Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@forward-software/react-auth

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@forward-software/react-auth - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

dist/types/deferred.d.ts

1170

dist/react-auth.cjs.development.js

@@ -11,166 +11,57 @@ 'use strict';

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function () {
var self = this,
args = arguments;
return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
function _regeneratorRuntime() {
_regeneratorRuntime = function () {
return exports;
};
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
var runtime_1 = createCommonjsModule(function (module) {
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var runtime = (function (exports) {
var Op = Object.prototype;
var hasOwn = Op.hasOwnProperty;
var undefined$1; // More compressible than void 0.
var $Symbol = typeof Symbol === "function" ? Symbol : {};
var iteratorSymbol = $Symbol.iterator || "@@iterator";
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
var exports = {},
Op = Object.prototype,
hasOwn = Op.hasOwnProperty,
defineProperty = Object.defineProperty || function (obj, key, desc) {
obj[key] = desc.value;
},
$Symbol = "function" == typeof Symbol ? Symbol : {},
iteratorSymbol = $Symbol.iterator || "@@iterator",
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
function define(obj, key, value) {
Object.defineProperty(obj, key, {
return Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
return obj[key];
enumerable: !0,
configurable: !0,
writable: !0
}), obj[key];
}
try {
// IE 8 has a broken Object.defineProperty that only works on DOM objects.
define({}, "");
} catch (err) {
define = function(obj, key, value) {
define = function (obj, key, value) {
return obj[key] = value;
};
}
function wrap(innerFn, outerFn, self, tryLocsList) {
// If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
var generator = Object.create(protoGenerator.prototype);
var context = new Context(tryLocsList || []);
// The ._invoke method unifies the implementations of the .next,
// .throw, and .return methods.
generator._invoke = makeInvokeMethod(innerFn, self, context);
return generator;
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
generator = Object.create(protoGenerator.prototype),
context = new Context(tryLocsList || []);
return defineProperty(generator, "_invoke", {
value: makeInvokeMethod(innerFn, self, context)
}), generator;
}
exports.wrap = wrap;
// Try/catch helper to minimize deoptimizations. Returns a completion
// record like context.tryEntries[i].completion. This interface could
// have been (and was previously) designed to take a closure to be
// invoked without arguments, but in all the cases we care about we
// already have an existing method we want to call, so there's no need
// to create a new function object. We can even get away with assuming
// the method takes exactly one argument, since that happens to be true
// in every case, so we don't have to touch the arguments object. The
// only additional allocation required is the completion record, which
// has a stable shape and so hopefully should be cheap to allocate.
function tryCatch(fn, obj, arg) {
try {
return { type: "normal", arg: fn.call(obj, arg) };
return {
type: "normal",
arg: fn.call(obj, arg)
};
} catch (err) {
return { type: "throw", arg: err };
return {
type: "throw",
arg: err
};
}
}
var GenStateSuspendedStart = "suspendedStart";
var GenStateSuspendedYield = "suspendedYield";
var GenStateExecuting = "executing";
var GenStateCompleted = "completed";
// Returning this object from the innerFn has the same effect as
// breaking out of the dispatch switch statement.
exports.wrap = wrap;
var ContinueSentinel = {};
// Dummy constructor functions that we use as the .constructor and
// .constructor.prototype properties for functions that return Generator
// objects. For full spec compliance, you may wish to configure your
// minifier not to mangle the names of these two functions.
function Generator() {}
function GeneratorFunction() {}
function GeneratorFunctionPrototype() {}
// This is a polyfill for %IteratorPrototype% for environments that
// don't natively support it.
var IteratorPrototype = {};

@@ -180,29 +71,9 @@ define(IteratorPrototype, iteratorSymbol, function () {

});
var getProto = Object.getPrototypeOf;
var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
if (NativeIteratorPrototype &&
NativeIteratorPrototype !== Op &&
hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
// This environment has a native %IteratorPrototype%; use it instead
// of the polyfill.
IteratorPrototype = NativeIteratorPrototype;
}
var Gp = GeneratorFunctionPrototype.prototype =
Generator.prototype = Object.create(IteratorPrototype);
GeneratorFunction.prototype = GeneratorFunctionPrototype;
define(Gp, "constructor", GeneratorFunctionPrototype);
define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
GeneratorFunction.displayName = define(
GeneratorFunctionPrototype,
toStringTagSymbol,
"GeneratorFunction"
);
// Helper for defining the .next, .throw, and .return methods of the
// Iterator interface in terms of a single ._invoke method.
var getProto = Object.getPrototypeOf,
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
function defineIteratorMethods(prototype) {
["next", "throw", "return"].forEach(function(method) {
define(prototype, method, function(arg) {
["next", "throw", "return"].forEach(function (method) {
define(prototype, method, function (arg) {
return this._invoke(method, arg);

@@ -212,145 +83,41 @@ });

}
exports.isGeneratorFunction = function(genFun) {
var ctor = typeof genFun === "function" && genFun.constructor;
return ctor
? ctor === GeneratorFunction ||
// For the native GeneratorFunction constructor, the best we can
// do is to check its .name property.
(ctor.displayName || ctor.name) === "GeneratorFunction"
: false;
};
exports.mark = function(genFun) {
if (Object.setPrototypeOf) {
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
} else {
genFun.__proto__ = GeneratorFunctionPrototype;
define(genFun, toStringTagSymbol, "GeneratorFunction");
}
genFun.prototype = Object.create(Gp);
return genFun;
};
// Within the body of any async function, `await x` is transformed to
// `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
// `hasOwn.call(value, "__await")` to determine if the yielded value is
// meant to be awaited.
exports.awrap = function(arg) {
return { __await: arg };
};
function AsyncIterator(generator, PromiseImpl) {
function invoke(method, arg, resolve, reject) {
var record = tryCatch(generator[method], generator, arg);
if (record.type === "throw") {
reject(record.arg);
} else {
var result = record.arg;
var value = result.value;
if (value &&
typeof value === "object" &&
hasOwn.call(value, "__await")) {
return PromiseImpl.resolve(value.__await).then(function(value) {
invoke("next", value, resolve, reject);
}, function(err) {
invoke("throw", err, resolve, reject);
});
}
return PromiseImpl.resolve(value).then(function(unwrapped) {
// When a yielded Promise is resolved, its final value becomes
// the .value of the Promise<{value,done}> result for the
// current iteration.
result.value = unwrapped;
resolve(result);
}, function(error) {
// If a rejected Promise was yielded, throw the rejection back
// into the async generator function so it can be handled there.
if ("throw" !== record.type) {
var result = record.arg,
value = result.value;
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
invoke("next", value, resolve, reject);
}, function (err) {
invoke("throw", err, resolve, reject);
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
result.value = unwrapped, resolve(result);
}, function (error) {
return invoke("throw", error, resolve, reject);
});
}
reject(record.arg);
}
var previousPromise;
function enqueue(method, arg) {
function callInvokeWithMethodAndArg() {
return new PromiseImpl(function(resolve, reject) {
invoke(method, arg, resolve, reject);
});
defineProperty(this, "_invoke", {
value: function (method, arg) {
function callInvokeWithMethodAndArg() {
return new PromiseImpl(function (resolve, reject) {
invoke(method, arg, resolve, reject);
});
}
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
}
return previousPromise =
// If enqueue has been called before, then we want to wait until
// all previous Promises have been resolved before calling invoke,
// so that results are always delivered in the correct order. If
// enqueue has not been called before, then it is important to
// call invoke immediately, without waiting on a callback to fire,
// so that the async generator function has the opportunity to do
// any necessary setup in a predictable way. This predictability
// is why the Promise constructor synchronously invokes its
// executor callback, and why async functions synchronously
// execute code before the first await. Since we implement simple
// async functions in terms of async generators, it is especially
// important to get this right, even though it requires care.
previousPromise ? previousPromise.then(
callInvokeWithMethodAndArg,
// Avoid propagating failures to Promises returned by later
// invocations of the iterator.
callInvokeWithMethodAndArg
) : callInvokeWithMethodAndArg();
}
// Define the unified helper method that is used to implement .next,
// .throw, and .return (see defineIteratorMethods).
this._invoke = enqueue;
});
}
defineIteratorMethods(AsyncIterator.prototype);
define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
return this;
});
exports.AsyncIterator = AsyncIterator;
// Note that simple async functions are implemented on top of
// AsyncIterator objects; they just return a Promise for the value of
// the final result produced by the iterator.
exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
if (PromiseImpl === void 0) PromiseImpl = Promise;
var iter = new AsyncIterator(
wrap(innerFn, outerFn, self, tryLocsList),
PromiseImpl
);
return exports.isGeneratorFunction(outerFn)
? iter // If outerFn is a generator, return the full iterator.
: iter.next().then(function(result) {
return result.done ? result.value : iter.next();
});
};
function makeInvokeMethod(innerFn, self, context) {
var state = GenStateSuspendedStart;
return function invoke(method, arg) {
if (state === GenStateExecuting) {
throw new Error("Generator is already running");
}
if (state === GenStateCompleted) {
if (method === "throw") {
throw arg;
}
// Be forgiving, per 25.3.3.3.3 of the spec:
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
var state = "suspendedStart";
return function (method, arg) {
if ("executing" === state) throw new Error("Generator is already running");
if ("completed" === state) {
if ("throw" === method) throw arg;
return doneResult();
}
context.method = method;
context.arg = arg;
while (true) {
for (context.method = method, context.arg = arg;;) {
var delegate = context.delegate;

@@ -364,34 +131,10 @@ if (delegate) {

}
if (context.method === "next") {
// Setting context._sent for legacy support of Babel's
// function.sent implementation.
context.sent = context._sent = context.arg;
} else if (context.method === "throw") {
if (state === GenStateSuspendedStart) {
state = GenStateCompleted;
throw context.arg;
}
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
if ("suspendedStart" === state) throw state = "completed", context.arg;
context.dispatchException(context.arg);
} else if (context.method === "return") {
context.abrupt("return", context.arg);
}
state = GenStateExecuting;
} else "return" === context.method && context.abrupt("return", context.arg);
state = "executing";
var record = tryCatch(innerFn, self, context);
if (record.type === "normal") {
// If an exception is thrown from innerFn, we leave state ===
// GenStateExecuting and loop back for another invocation.
state = context.done
? GenStateCompleted
: GenStateSuspendedYield;
if (record.arg === ContinueSentinel) {
continue;
}
if ("normal" === record.type) {
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
return {

@@ -401,310 +144,130 @@ value: record.arg,

};
} else if (record.type === "throw") {
state = GenStateCompleted;
// Dispatch the exception by looping back around to the
// context.dispatchException(context.arg) call above.
context.method = "throw";
context.arg = record.arg;
}
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
}
};
}
// Call delegate.iterator[context.method](context.arg) and handle the
// result, either by returning a { value, done } result from the
// delegate iterator, or by modifying context.method and context.arg,
// setting context.delegate to null, and returning the ContinueSentinel.
function maybeInvokeDelegate(delegate, context) {
var method = delegate.iterator[context.method];
if (method === undefined$1) {
// A .throw or .return when the delegate iterator has no .throw
// method always terminates the yield* loop.
context.delegate = null;
if (context.method === "throw") {
// Note: ["return"] must be used for ES3 parsing compatibility.
if (delegate.iterator["return"]) {
// If the delegate iterator has a return method, give it a
// chance to clean up.
context.method = "return";
context.arg = undefined$1;
maybeInvokeDelegate(delegate, context);
if (context.method === "throw") {
// If maybeInvokeDelegate(context) changed context.method from
// "return" to "throw", let that override the TypeError below.
return ContinueSentinel;
}
}
context.method = "throw";
context.arg = new TypeError(
"The iterator does not provide a 'throw' method");
if (undefined === method) {
if (context.delegate = null, "throw" === context.method) {
if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
}
return ContinueSentinel;
}
var record = tryCatch(method, delegate.iterator, context.arg);
if (record.type === "throw") {
context.method = "throw";
context.arg = record.arg;
context.delegate = null;
return ContinueSentinel;
}
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
var info = record.arg;
if (! info) {
context.method = "throw";
context.arg = new TypeError("iterator result is not an object");
context.delegate = null;
return ContinueSentinel;
}
if (info.done) {
// Assign the result of the finished delegate to the temporary
// variable specified by delegate.resultName (see delegateYield).
context[delegate.resultName] = info.value;
// Resume execution at the desired location (see delegateYield).
context.next = delegate.nextLoc;
// If context.method was "throw" but the delegate handled the
// exception, let the outer generator proceed normally. If
// context.method was "next", forget context.arg since it has been
// "consumed" by the delegate iterator. If context.method was
// "return", allow the original .return call to continue in the
// outer generator.
if (context.method !== "return") {
context.method = "next";
context.arg = undefined$1;
}
} else {
// Re-yield the result returned by the delegate method.
return info;
}
// The delegate iterator is finished, so forget it and continue with
// the outer generator.
context.delegate = null;
return ContinueSentinel;
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);
}
// Define Generator.prototype.{next,throw,return} in terms of the
// unified ._invoke helper method.
defineIteratorMethods(Gp);
define(Gp, toStringTagSymbol, "Generator");
// A Generator should always return itself as the iterator object when the
// @@iterator function is called on it. Some browsers' implementations of the
// iterator prototype chain incorrectly implement this, causing the Generator
// object to not be returned from this call. This ensures that doesn't happen.
// See https://github.com/facebook/regenerator/issues/274 for more details.
define(Gp, iteratorSymbol, function() {
return this;
});
define(Gp, "toString", function() {
return "[object Generator]";
});
function pushTryEntry(locs) {
var entry = { tryLoc: locs[0] };
if (1 in locs) {
entry.catchLoc = locs[1];
}
if (2 in locs) {
entry.finallyLoc = locs[2];
entry.afterLoc = locs[3];
}
this.tryEntries.push(entry);
var entry = {
tryLoc: locs[0]
};
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
}
function resetTryEntry(entry) {
var record = entry.completion || {};
record.type = "normal";
delete record.arg;
entry.completion = record;
record.type = "normal", delete record.arg, entry.completion = record;
}
function Context(tryLocsList) {
// The root entry object (effectively a try statement without a catch
// or a finally block) gives us a place to store values thrown from
// locations where there is no enclosing try statement.
this.tryEntries = [{ tryLoc: "root" }];
tryLocsList.forEach(pushTryEntry, this);
this.reset(true);
this.tryEntries = [{
tryLoc: "root"
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
}
exports.keys = function(object) {
var keys = [];
for (var key in object) {
keys.push(key);
}
keys.reverse();
// Rather than returning an object with a next method, we keep
// things simple and return the next function itself.
return function next() {
while (keys.length) {
var key = keys.pop();
if (key in object) {
next.value = key;
next.done = false;
return next;
}
}
// To avoid creating an additional object, we just hang the .value
// and .done properties off the next function object itself. This
// also ensures that the minifier will not anonymize the function.
next.done = true;
return next;
};
};
function values(iterable) {
if (iterable) {
var iteratorMethod = iterable[iteratorSymbol];
if (iteratorMethod) {
return iteratorMethod.call(iterable);
}
if (typeof iterable.next === "function") {
return iterable;
}
if (iteratorMethod) return iteratorMethod.call(iterable);
if ("function" == typeof iterable.next) return iterable;
if (!isNaN(iterable.length)) {
var i = -1, next = function next() {
while (++i < iterable.length) {
if (hasOwn.call(iterable, i)) {
next.value = iterable[i];
next.done = false;
return next;
}
}
next.value = undefined$1;
next.done = true;
return next;
};
var i = -1,
next = function next() {
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
return next.value = undefined, next.done = !0, next;
};
return next.next = next;
}
}
// Return an iterator with no values.
return { next: doneResult };
return {
next: doneResult
};
}
exports.values = values;
function doneResult() {
return { value: undefined$1, done: true };
return {
value: undefined,
done: !0
};
}
Context.prototype = {
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
value: GeneratorFunctionPrototype,
configurable: !0
}), defineProperty(GeneratorFunctionPrototype, "constructor", {
value: GeneratorFunction,
configurable: !0
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
var ctor = "function" == typeof genFun && genFun.constructor;
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
}, exports.mark = function (genFun) {
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
}, exports.awrap = function (arg) {
return {
__await: arg
};
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
return this;
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
void 0 === PromiseImpl && (PromiseImpl = Promise);
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
return result.done ? result.value : iter.next();
});
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
return this;
}), define(Gp, "toString", function () {
return "[object Generator]";
}), exports.keys = function (val) {
var object = Object(val),
keys = [];
for (var key in object) keys.push(key);
return keys.reverse(), function next() {
for (; keys.length;) {
var key = keys.pop();
if (key in object) return next.value = key, next.done = !1, next;
}
return next.done = !0, next;
};
}, exports.values = values, Context.prototype = {
constructor: Context,
reset: function(skipTempReset) {
this.prev = 0;
this.next = 0;
// Resetting context._sent for legacy support of Babel's
// function.sent implementation.
this.sent = this._sent = undefined$1;
this.done = false;
this.delegate = null;
this.method = "next";
this.arg = undefined$1;
this.tryEntries.forEach(resetTryEntry);
if (!skipTempReset) {
for (var name in this) {
// Not sure about the optimal order of these conditions:
if (name.charAt(0) === "t" &&
hasOwn.call(this, name) &&
!isNaN(+name.slice(1))) {
this[name] = undefined$1;
}
}
}
reset: function (skipTempReset) {
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);
},
stop: function() {
this.done = true;
var rootEntry = this.tryEntries[0];
var rootRecord = rootEntry.completion;
if (rootRecord.type === "throw") {
throw rootRecord.arg;
}
stop: function () {
this.done = !0;
var rootRecord = this.tryEntries[0].completion;
if ("throw" === rootRecord.type) throw rootRecord.arg;
return this.rval;
},
dispatchException: function(exception) {
if (this.done) {
throw exception;
}
dispatchException: function (exception) {
if (this.done) throw exception;
var context = this;
function handle(loc, caught) {
record.type = "throw";
record.arg = exception;
context.next = loc;
if (caught) {
// If the dispatched exception was caught by a catch block,
// then let that catch block handle the exception normally.
context.method = "next";
context.arg = undefined$1;
}
return !! caught;
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
}
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
var record = entry.completion;
if (entry.tryLoc === "root") {
// Exception thrown outside of any try block that could handle
// it, so set the completion value of the entire function to
// throw the exception.
return handle("end");
}
var entry = this.tryEntries[i],
record = entry.completion;
if ("root" === entry.tryLoc) return handle("end");
if (entry.tryLoc <= this.prev) {
var hasCatch = hasOwn.call(entry, "catchLoc");
var hasFinally = hasOwn.call(entry, "finallyLoc");
var hasCatch = hasOwn.call(entry, "catchLoc"),
hasFinally = hasOwn.call(entry, "finallyLoc");
if (hasCatch && hasFinally) {
if (this.prev < entry.catchLoc) {
return handle(entry.catchLoc, true);
} else if (this.prev < entry.finallyLoc) {
return handle(entry.finallyLoc);
}
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
} else if (hasCatch) {
if (this.prev < entry.catchLoc) {
return handle(entry.catchLoc, true);
}
} else if (hasFinally) {
if (this.prev < entry.finallyLoc) {
return handle(entry.finallyLoc);
}
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
} else {
throw new Error("try statement without catch or finally");
if (!hasFinally) throw new Error("try statement without catch or finally");
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
}

@@ -714,9 +277,6 @@ }

},
abrupt: function(type, arg) {
abrupt: function (type, arg) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.tryLoc <= this.prev &&
hasOwn.call(entry, "finallyLoc") &&
this.prev < entry.finallyLoc) {
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
var finallyEntry = entry;

@@ -726,57 +286,17 @@ break;

}
if (finallyEntry &&
(type === "break" ||
type === "continue") &&
finallyEntry.tryLoc <= arg &&
arg <= finallyEntry.finallyLoc) {
// Ignore the finally entry if control is not jumping to a
// location outside the try/catch block.
finallyEntry = null;
}
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
var record = finallyEntry ? finallyEntry.completion : {};
record.type = type;
record.arg = arg;
if (finallyEntry) {
this.method = "next";
this.next = finallyEntry.finallyLoc;
return ContinueSentinel;
}
return this.complete(record);
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
},
complete: function(record, afterLoc) {
if (record.type === "throw") {
throw record.arg;
}
if (record.type === "break" ||
record.type === "continue") {
this.next = record.arg;
} else if (record.type === "return") {
this.rval = this.arg = record.arg;
this.method = "return";
this.next = "end";
} else if (record.type === "normal" && afterLoc) {
this.next = afterLoc;
}
return ContinueSentinel;
complete: function (record, afterLoc) {
if ("throw" === record.type) throw record.arg;
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;
},
finish: function(finallyLoc) {
finish: function (finallyLoc) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.finallyLoc === finallyLoc) {
this.complete(entry.completion, entry.afterLoc);
resetTryEntry(entry);
return ContinueSentinel;
}
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
}
},
"catch": function(tryLoc) {
catch: function (tryLoc) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {

@@ -786,3 +306,3 @@ var entry = this.tryEntries[i];

var record = entry.completion;
if (record.type === "throw") {
if ("throw" === record.type) {
var thrown = record.arg;

@@ -794,59 +314,89 @@ resetTryEntry(entry);

}
// The context.catch method must only be called with a location
// argument that corresponds to a known catch block.
throw new Error("illegal catch attempt");
},
delegateYield: function(iterable, resultName, nextLoc) {
this.delegate = {
delegateYield: function (iterable, resultName, nextLoc) {
return this.delegate = {
iterator: values(iterable),
resultName: resultName,
nextLoc: nextLoc
};
if (this.method === "next") {
// Deliberately forget the last sent value so that we don't
// accidentally pass it on to the delegate.
this.arg = undefined$1;
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
}
}, exports;
}
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function () {
var self = this,
args = arguments;
return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
return ContinueSentinel;
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
// Regardless of whether this script is executing as a CommonJS module
// or not, return the runtime object so that we can declare the variable
// regeneratorRuntime in the outer scope, which allows this module to be
// injected easily by `bin/regenerator --include-runtime script.js`.
return exports;
}(
// If this script is executing as a CommonJS module, use module.exports
// as the regeneratorRuntime namespace. Otherwise create a new empty
// object. Either way, the resulting object will be used to initialize
// the regeneratorRuntime variable at the top of this file.
module.exports
));
try {
regeneratorRuntime = runtime;
} catch (accidentalStrictMode) {
// This module should not be running in strict mode, so the above
// assignment should always work unless something is misconfigured. Just
// in case runtime.js accidentally runs in strict mode, in modern engines
// we can explicitly access globalThis. In older engines we can escape
// strict mode using a global Function call. This could conceivably fail
// if a Content Security Policy forbids using Function, but in that case
// the proper solution is to fix the accidental strict mode problem. If
// you've misconfigured your bundler to force strict mode and applied a
// CSP to forbid Function, and you're not willing to fix either of those
// problems, please detail your unique predicament in a GitHub issue.
if (typeof globalThis === "object") {
globalThis.regeneratorRuntime = runtime;
} else {
Function("r", "regeneratorRuntime = r")(runtime);
var Deferred = /*#__PURE__*/function () {
function Deferred() {
var _this = this;
this.promise = new Promise(function (resolve, reject) {
_this.reject = reject;
_this.resolve = resolve;
});
}
}
});
var _proto = Deferred.prototype;
_proto.getPromise = function getPromise() {
return this.promise;
};
return Deferred;
}();

@@ -878,3 +428,2 @@ // TODO: Improve -> `listeners` are unbounded -- don't use this in practice!

var _this = this;
this._state = {

@@ -885,24 +434,22 @@ isAuthenticated: false,

};
// refresh queue - used to avoid concurrency issue during Token refresh
this.refreshQ = [];
this.eventEmitter = createEventEmitter();
this.subscribers = new Set(); // Should be declared like this to avoid binding issues when used by useSyncExternalStore
this.subscribers = new Set();
// Should be declared like this to avoid binding issues when used by useSyncExternalStore
this.subscribe = function (subscription) {
_this.subscribers.add(subscription);
return function () {
return _this.subscribers["delete"](subscription);
};
}; // Should be declared like this to avoid binding issues when used by useSyncExternalStore
};
// Should be declared like this to avoid binding issues when used by useSyncExternalStore
this.getSnapshot = function () {
return _this._state;
};
} //
}
//
// Getters
//
var _proto = BaseAuthClient.prototype;
//

@@ -914,6 +461,5 @@ // Public methods

function () {
var _init = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
var _init = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
var _this$onPostInit;
return runtime_1.wrap(function _callee$(_context) {
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) {

@@ -925,3 +471,2 @@ switch (_context.prev = _context.next) {

return this.onInit();
case 3:

@@ -934,3 +479,2 @@ this.setState({

break;
case 7:

@@ -943,10 +487,7 @@ _context.prev = 7;

this.emit('initFailed', _context.t0);
case 11:
_context.next = 13;
return (_this$onPostInit = this.onPostInit) == null ? void 0 : _this$onPostInit.call(this);
case 13:
return _context.abrupt("return", this.isInitialized);
case 14:

@@ -959,16 +500,12 @@ case "end":

}));
function init() {
return _init.apply(this, arguments);
}
return init;
}();
_proto.login = /*#__PURE__*/function () {
var _login = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(credentials) {
var _login = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(credentials) {
var _this$onPreLogin, _this$onPostLogin;
var isSuccess, tokens;
return runtime_1.wrap(function _callee2$(_context2) {
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) {

@@ -980,3 +517,2 @@ switch (_context2.prev = _context2.next) {

return (_this$onPreLogin = this.onPreLogin) == null ? void 0 : _this$onPreLogin.call(this);
case 3:

@@ -987,3 +523,2 @@ isSuccess = false;

return this.onLogin(credentials);
case 7:

@@ -999,3 +534,2 @@ tokens = _context2.sent;

break;
case 13:

@@ -1010,10 +544,7 @@ _context2.prev = 13;

isSuccess = false;
case 18:
_context2.next = 20;
return (_this$onPostLogin = this.onPostLogin) == null ? void 0 : _this$onPostLogin.call(this, isSuccess);
case 20:
return _context2.abrupt("return", this.isAuthenticated);
case 21:

@@ -1026,58 +557,18 @@ case "end":

}));
function login(_x) {
return _login.apply(this, arguments);
}
return login;
}();
_proto.refresh = /*#__PURE__*/function () {
var _refresh = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(minValidity) {
var _this$onPreRefresh, _this$onPostRefresh;
var isSuccess, tokens;
return runtime_1.wrap(function _callee3$(_context3) {
var _refresh = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(minValidity) {
var deferred;
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
this.emit('refreshStarted', undefined);
_context3.next = 3;
return (_this$onPreRefresh = this.onPreRefresh) == null ? void 0 : _this$onPreRefresh.call(this);
deferred = new Deferred();
this.runRefresh(deferred, minValidity);
return _context3.abrupt("return", deferred.getPromise());
case 3:
isSuccess = false;
_context3.prev = 4;
_context3.next = 7;
return this.onRefresh(minValidity);
case 7:
tokens = _context3.sent;
this.setState({
isAuthenticated: true,
tokens: tokens
});
this.emit('refreshSuccess', undefined);
isSuccess = true;
_context3.next = 18;
break;
case 13:
_context3.prev = 13;
_context3.t0 = _context3["catch"](4);
this.setState({
isAuthenticated: false,
tokens: {}
});
this.emit('refreshFailed', _context3.t0);
isSuccess = false;
case 18:
_context3.next = 20;
return (_this$onPostRefresh = this.onPostRefresh) == null ? void 0 : _this$onPostRefresh.call(this, isSuccess);
case 20:
return _context3.abrupt("return", this.isAuthenticated);
case 21:
case "end":

@@ -1087,18 +578,14 @@ return _context3.stop();

}
}, _callee3, this, [[4, 13]]);
}, _callee3, this);
}));
function refresh(_x2) {
return _refresh.apply(this, arguments);
}
return refresh;
}();
_proto.logout = /*#__PURE__*/function () {
var _logout = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
var _logout = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
var _this$onPreLogout, _this$onPostLogout;
var isSuccess;
return runtime_1.wrap(function _callee4$(_context4) {
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
while (1) {

@@ -1110,3 +597,2 @@ switch (_context4.prev = _context4.next) {

return (_this$onPreLogout = this.onPreLogout) == null ? void 0 : _this$onPreLogout.call(this);
case 3:

@@ -1117,3 +603,2 @@ isSuccess = false;

return this.onLogout();
case 7:

@@ -1128,3 +613,2 @@ this.setState({

break;
case 12:

@@ -1135,7 +619,5 @@ _context4.prev = 12;

isSuccess = false;
case 16:
_context4.next = 18;
return (_this$onPostLogout = this.onPostLogout) == null ? void 0 : _this$onPostLogout.call(this, isSuccess);
case 18:

@@ -1148,33 +630,90 @@ case "end":

}));
function logout() {
return _logout.apply(this, arguments);
}
return logout;
}();
_proto.on = function on(eventName, listener) {
this.eventEmitter.on(eventName, listener);
};
_proto.off = function off(eventName, listener) {
this.eventEmitter.off(eventName, listener);
} //
}
//
// Protected methods
//
;
_proto.setState = function setState(stateUpdate) {
this._state = _extends({}, this._state, stateUpdate);
this.notifySubscribers();
} //
}
//
// Private methods
//
;
_proto.runRefresh =
/*#__PURE__*/
function () {
var _runRefresh = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(deferred, minValidity) {
var _this$onPreRefresh, _this$onPostRefresh;
var isAuthenticated, tokens, p;
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
// Add deferred Promise to refresh queue
this.refreshQ.push(deferred);
// If refresh queue already has promises enqueued do not attempt a new refresh - one is already in progress
if (!(this.refreshQ.length !== 1)) {
_context5.next = 3;
break;
}
return _context5.abrupt("return");
case 3:
this.emit('refreshStarted', undefined);
_context5.next = 6;
return (_this$onPreRefresh = this.onPreRefresh) == null ? void 0 : _this$onPreRefresh.call(this);
case 6:
isAuthenticated = false;
tokens = {};
_context5.prev = 8;
_context5.next = 11;
return this.onRefresh(minValidity);
case 11:
tokens = _context5.sent;
isAuthenticated = true;
this.emit('refreshSuccess', undefined);
_context5.next = 20;
break;
case 16:
_context5.prev = 16;
_context5.t0 = _context5["catch"](8);
isAuthenticated = false;
this.emit('refreshFailed', _context5.t0);
case 20:
this.setState({
isAuthenticated: isAuthenticated,
tokens: tokens
});
_context5.next = 23;
return (_this$onPostRefresh = this.onPostRefresh) == null ? void 0 : _this$onPostRefresh.call(this, isAuthenticated);
case 23:
for (p = this.refreshQ.pop(); p != null; p = this.refreshQ.pop()) {
p.resolve(isAuthenticated);
}
case 24:
case "end":
return _context5.stop();
}
}
}, _callee5, this, [[8, 16]]);
}));
function runRefresh(_x3, _x4) {
return _runRefresh.apply(this, arguments);
}
return runRefresh;
}();
_proto.emit = function emit(eventName, error) {
this.eventEmitter.emit(eventName, error);
};
_proto.notifySubscribers = function notifySubscribers() {

@@ -1187,3 +726,2 @@ this.subscribers.forEach(function (s) {

};
_createClass(BaseAuthClient, [{

@@ -1205,3 +743,2 @@ key: "isInitialized",

}]);
return BaseAuthClient;

@@ -1212,17 +749,14 @@ }();

// Create a React context containing a BaseAuthClient instance.
var authContext = React.createContext(null); // Create the React Context Provider for the BaseAuthClient instance.
var authContext = React.createContext(null);
// Create the React Context Provider for the BaseAuthClient instance.
var AuthProvider = function AuthProvider(_ref) {
var children = _ref.children,
ErrorComponent = _ref.ErrorComponent,
LoadingComponent = _ref.LoadingComponent;
ErrorComponent = _ref.ErrorComponent,
LoadingComponent = _ref.LoadingComponent;
var _useState = React.useState(false),
isInitFailed = _useState[0],
setInitFailed = _useState[1];
isInitFailed = _useState[0],
setInitFailed = _useState[1];
var _useSyncExternalStore = shim.useSyncExternalStore(authClient.subscribe, authClient.getSnapshot),
isAuthenticated = _useSyncExternalStore.isAuthenticated,
isInitialized = _useSyncExternalStore.isInitialized;
isAuthenticated = _useSyncExternalStore.isAuthenticated,
isInitialized = _useSyncExternalStore.isInitialized;
React.useEffect(function () {

@@ -1232,8 +766,6 @@ function initAuthClient() {

} // Init AuthClient
function _initAuthClient() {
_initAuthClient = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
_initAuthClient = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
var initSuccess;
return runtime_1.wrap(function _callee$(_context) {
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) {

@@ -1244,7 +776,5 @@ switch (_context.prev = _context.next) {

return authClient.init();
case 2:
initSuccess = _context.sent;
setInitFailed(!initSuccess);
case 4:

@@ -1259,14 +789,10 @@ case "end":

}
initAuthClient();
}, []);
if (!!ErrorComponent && isInitFailed) {
return ErrorComponent;
}
if (!!LoadingComponent && !isInitialized) {
return LoadingComponent;
}
return React__default.createElement(authContext.Provider, {

@@ -1279,15 +805,11 @@ value: {

}, children);
}; // Retrieve the AuthClient from the current context
};
// Retrieve the AuthClient from the current context
var useAuthClient = function useAuthClient() {
var ctx = React.useContext(authContext);
if (!ctx) {
throw new Error('useAuthClient hook should be used inside AuthProvider');
}
return ctx.authClient;
};
return {

@@ -1294,0 +816,0 @@ AuthProvider: AuthProvider,

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=require("react"),r=(t=e)&&"object"==typeof t&&"default"in t?t.default:t,n=require("use-sync-external-store/shim");function i(t,e,r,n,i,o,a){try{var s=t[o](a),c=s.value}catch(t){return void r(t)}s.done?e(c):Promise.resolve(c).then(n,i)}function o(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function s(t){i(a,n,o,s,c,"next",t)}function c(t){i(a,n,o,s,c,"throw",t)}s(void 0)}))}}function a(){return(a=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}var s,c=(function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",o=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function c(t,e,r,n){var i=Object.create((e&&e.prototype instanceof f?e:f).prototype),o=new E(n||[]);return i._invoke=function(t,e,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return{value:void 0,done:!0}}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var s=b(a,r);if(s){if(s===h)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=u(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===h)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}(t,r,o),i}function u(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var h={};function f(){}function l(){}function p(){}var v={};s(v,i,(function(){return this}));var d=Object.getPrototypeOf,y=d&&d(d(k([])));y&&y!==e&&r.call(y,i)&&(v=y);var g=p.prototype=f.prototype=Object.create(v);function m(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function w(t,e){var n;this._invoke=function(i,o){function a(){return new e((function(n,a){!function n(i,o,a,s){var c=u(t[i],t,o);if("throw"!==c.type){var h=c.arg,f=h.value;return f&&"object"==typeof f&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){n("next",t,a,s)}),(function(t){n("throw",t,a,s)})):e.resolve(f).then((function(t){h.value=t,a(h)}),(function(t){return n("throw",t,a,s)}))}s(c.arg)}(i,o,n,a)}))}return n=n?n.then(a,a):a()}}function b(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,b(t,e),"throw"===e.method))return h;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return h}var n=u(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,h;var i=n.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,h):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,h)}function x(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function E(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function k(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:S}}function S(){return{value:void 0,done:!0}}return l.prototype=p,s(g,"constructor",p),s(p,"constructor",l),l.displayName=s(p,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,s(t,a,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},m(w.prototype),s(w.prototype,o,(function(){return this})),t.AsyncIterator=w,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var a=new w(c(e,r,n,i),o);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},m(g),s(g,a,"Generator"),s(g,i,(function(){return this})),s(g,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=k,E.prototype={constructor:E,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(L),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var s=r.call(o,"catchLoc"),c=r.call(o,"finallyLoc");if(s&&c){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,h):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;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),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;L(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:k(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(s={exports:{}}),s.exports);exports.BaseAuthClient=function(){function t(){var t,e=this;this._state={isAuthenticated:!1,isInitialized:!1,tokens:{}},this.eventEmitter=(t={},{on:function(e,r){t[e]=(t[e]||[]).concat(r)},off:function(e,r){t[e]=(t[e]||[]).filter((function(t){return t!==r}))},emit:function(e,r){(t[e]||[]).forEach((function(t){try{t(r)}catch(t){}}))}}),this.subscribers=new Set,this.subscribe=function(t){return e.subscribers.add(t),function(){return e.subscribers.delete(t)}},this.getSnapshot=function(){return e._state}}var e,r,n=t.prototype;return n.init=function(){var t=o(c.mark((function t(){var e;return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.onInit();case 3:this.setState({isInitialized:!0}),this.emit("initSuccess",void 0),t.next=11;break;case 7:t.prev=7,t.t0=t.catch(0),this.setState({isInitialized:!1}),this.emit("initFailed",t.t0);case 11:return t.next=13,null==(e=this.onPostInit)?void 0:e.call(this);case 13:return t.abrupt("return",this.isInitialized);case 14:case"end":return t.stop()}}),t,this,[[0,7]])})));return function(){return t.apply(this,arguments)}}(),n.login=function(){var t=o(c.mark((function t(e){var r,n,i;return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.emit("loginStarted",void 0),t.next=3,null==(r=this.onPreLogin)?void 0:r.call(this);case 3:return i=!1,t.prev=4,t.next=7,this.onLogin(e);case 7:this.setState({isAuthenticated:!0,tokens:t.sent}),this.emit("loginSuccess",void 0),i=!0,t.next=18;break;case 13:t.prev=13,t.t0=t.catch(4),this.setState({isAuthenticated:!1,tokens:{}}),this.emit("loginFailed",t.t0),i=!1;case 18:return t.next=20,null==(n=this.onPostLogin)?void 0:n.call(this,i);case 20:return t.abrupt("return",this.isAuthenticated);case 21:case"end":return t.stop()}}),t,this,[[4,13]])})));return function(e){return t.apply(this,arguments)}}(),n.refresh=function(){var t=o(c.mark((function t(e){var r,n,i;return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.emit("refreshStarted",void 0),t.next=3,null==(r=this.onPreRefresh)?void 0:r.call(this);case 3:return i=!1,t.prev=4,t.next=7,this.onRefresh(e);case 7:this.setState({isAuthenticated:!0,tokens:t.sent}),this.emit("refreshSuccess",void 0),i=!0,t.next=18;break;case 13:t.prev=13,t.t0=t.catch(4),this.setState({isAuthenticated:!1,tokens:{}}),this.emit("refreshFailed",t.t0),i=!1;case 18:return t.next=20,null==(n=this.onPostRefresh)?void 0:n.call(this,i);case 20:return t.abrupt("return",this.isAuthenticated);case 21:case"end":return t.stop()}}),t,this,[[4,13]])})));return function(e){return t.apply(this,arguments)}}(),n.logout=function(){var t=o(c.mark((function t(){var e,r,n;return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.emit("logoutStarted",void 0),t.next=3,null==(e=this.onPreLogout)?void 0:e.call(this);case 3:return n=!1,t.prev=4,t.next=7,this.onLogout();case 7:this.setState({isAuthenticated:!1,tokens:{}}),this.emit("logoutSuccess",void 0),n=!0,t.next=16;break;case 12:t.prev=12,t.t0=t.catch(4),this.emit("logoutFailed",t.t0),n=!1;case 16:return t.next=18,null==(r=this.onPostLogout)?void 0:r.call(this,n);case 18:case"end":return t.stop()}}),t,this,[[4,12]])})));return function(){return t.apply(this,arguments)}}(),n.on=function(t,e){this.eventEmitter.on(t,e)},n.off=function(t,e){this.eventEmitter.off(t,e)},n.setState=function(t){this._state=a({},this._state,t),this.notifySubscribers()},n.emit=function(t,e){this.eventEmitter.emit(t,e)},n.notifySubscribers=function(){this.subscribers.forEach((function(t){try{t()}catch(t){}}))},e=t,(r=[{key:"isInitialized",get:function(){return this._state.isInitialized}},{key:"isAuthenticated",get:function(){return this._state.isAuthenticated}},{key:"tokens",get:function(){return this._state.tokens}}])&&function(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}(e.prototype,r),Object.defineProperty(e,"prototype",{writable:!1}),t}(),exports.createAuth=function(t){var i=e.createContext(null);return{AuthProvider:function(a){var s=a.children,u=a.ErrorComponent,h=a.LoadingComponent,f=e.useState(!1),l=f[0],p=f[1],v=n.useSyncExternalStore(t.subscribe,t.getSnapshot),d=v.isAuthenticated,y=v.isInitialized;return e.useEffect((function(){function e(){return(e=o(c.mark((function e(){return c.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.init();case 2:p(!e.sent);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}!function(){e.apply(this,arguments)}()}),[]),u&&l?u:h&&!y?h:r.createElement(i.Provider,{value:{authClient:t,isAuthenticated:d,isInitialized:y}},s)},useAuthClient:function(){var t=e.useContext(i);if(!t)throw new Error("useAuthClient hook should be used inside AuthProvider");return t.authClient}}};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=require("react"),r=(t=e)&&"object"==typeof t&&"default"in t?t.default:t,n=require("use-sync-external-store/shim");function i(){i=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,n=Object.defineProperty||function(t,e,r){t[e]=r.value},o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",s=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function h(t,e,r,i){var o=Object.create((e&&e.prototype instanceof p?e:p).prototype),a=new P(i||[]);return n(o,"_invoke",{value:L(t,r,a)}),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=h;var l={};function p(){}function v(){}function d(){}var y={};c(y,a,(function(){return this}));var g=Object.getPrototypeOf,m=g&&g(g(_([])));m&&m!==e&&r.call(m,a)&&(y=m);var w=d.prototype=p.prototype=Object.create(y);function b(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function x(t,e){var i;n(this,"_invoke",{value:function(n,o){function a(){return new e((function(i,a){!function n(i,o,a,s){var u=f(t[i],t,o);if("throw"!==u.type){var c=u.arg,h=c.value;return h&&"object"==typeof h&&r.call(h,"__await")?e.resolve(h.__await).then((function(t){n("next",t,a,s)}),(function(t){n("throw",t,a,s)})):e.resolve(h).then((function(t){c.value=t,a(c)}),(function(t){return n("throw",t,a,s)}))}s(u.arg)}(n,o,i,a)}))}return i=i?i.then(a,a):a()}})}function L(t,e,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return{value:void 0,done:!0}}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var s=E(a,r);if(s){if(s===l)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=f(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===l)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function E(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,E(t,e),"throw"===e.method))return l;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=f(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,l;var i=n.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,l):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function S(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function _(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:j}}function j(){return{value:void 0,done:!0}}return v.prototype=d,n(w,"constructor",{value:d,configurable:!0}),n(d,"constructor",{value:v,configurable:!0}),v.displayName=c(d,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===v||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,c(t,u,"GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},b(x.prototype),c(x.prototype,s,(function(){return this})),t.AsyncIterator=x,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var a=new x(h(e,r,n,i),o);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},b(w),c(w,u,"Generator"),c(w,a,(function(){return this})),c(w,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=_,P.prototype={constructor:P,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(S),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var s=r.call(o,"catchLoc"),u=r.call(o,"finallyLoc");if(s&&u){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,l):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;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),l},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),S(r),l}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;S(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:_(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},t}function o(t,e,r,n,i,o,a){try{var s=t[o](a),u=s.value}catch(t){return void r(t)}s.done?e(u):Promise.resolve(u).then(n,i)}function a(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var a=t.apply(e,r);function s(t){o(a,n,i,s,u,"next",t)}function u(t){o(a,n,i,s,u,"throw",t)}s(void 0)}))}}function s(){return(s=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}var u=function(){function t(){var t=this;this.promise=new Promise((function(e,r){t.reject=r,t.resolve=e}))}return t.prototype.getPromise=function(){return this.promise},t}();exports.BaseAuthClient=function(){function t(){var t,e=this;this._state={isAuthenticated:!1,isInitialized:!1,tokens:{}},this.refreshQ=[],this.eventEmitter=(t={},{on:function(e,r){t[e]=(t[e]||[]).concat(r)},off:function(e,r){t[e]=(t[e]||[]).filter((function(t){return t!==r}))},emit:function(e,r){(t[e]||[]).forEach((function(t){try{t(r)}catch(t){}}))}}),this.subscribers=new Set,this.subscribe=function(t){return e.subscribers.add(t),function(){return e.subscribers.delete(t)}},this.getSnapshot=function(){return e._state}}var e,r,n=t.prototype;return n.init=function(){var t=a(i().mark((function t(){var e;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.onInit();case 3:this.setState({isInitialized:!0}),this.emit("initSuccess",void 0),t.next=11;break;case 7:t.prev=7,t.t0=t.catch(0),this.setState({isInitialized:!1}),this.emit("initFailed",t.t0);case 11:return t.next=13,null==(e=this.onPostInit)?void 0:e.call(this);case 13:return t.abrupt("return",this.isInitialized);case 14:case"end":return t.stop()}}),t,this,[[0,7]])})));return function(){return t.apply(this,arguments)}}(),n.login=function(){var t=a(i().mark((function t(e){var r,n,o;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.emit("loginStarted",void 0),t.next=3,null==(r=this.onPreLogin)?void 0:r.call(this);case 3:return o=!1,t.prev=4,t.next=7,this.onLogin(e);case 7:this.setState({isAuthenticated:!0,tokens:t.sent}),this.emit("loginSuccess",void 0),o=!0,t.next=18;break;case 13:t.prev=13,t.t0=t.catch(4),this.setState({isAuthenticated:!1,tokens:{}}),this.emit("loginFailed",t.t0),o=!1;case 18:return t.next=20,null==(n=this.onPostLogin)?void 0:n.call(this,o);case 20:return t.abrupt("return",this.isAuthenticated);case 21:case"end":return t.stop()}}),t,this,[[4,13]])})));return function(e){return t.apply(this,arguments)}}(),n.refresh=function(){var t=a(i().mark((function t(e){var r;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=new u,this.runRefresh(r,e),t.abrupt("return",r.getPromise());case 3:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.logout=function(){var t=a(i().mark((function t(){var e,r,n;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.emit("logoutStarted",void 0),t.next=3,null==(e=this.onPreLogout)?void 0:e.call(this);case 3:return n=!1,t.prev=4,t.next=7,this.onLogout();case 7:this.setState({isAuthenticated:!1,tokens:{}}),this.emit("logoutSuccess",void 0),n=!0,t.next=16;break;case 12:t.prev=12,t.t0=t.catch(4),this.emit("logoutFailed",t.t0),n=!1;case 16:return t.next=18,null==(r=this.onPostLogout)?void 0:r.call(this,n);case 18:case"end":return t.stop()}}),t,this,[[4,12]])})));return function(){return t.apply(this,arguments)}}(),n.on=function(t,e){this.eventEmitter.on(t,e)},n.off=function(t,e){this.eventEmitter.off(t,e)},n.setState=function(t){this._state=s({},this._state,t),this.notifySubscribers()},n.runRefresh=function(){var t=a(i().mark((function t(e,r){var n,o,a,s,u;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.refreshQ.push(e),1===this.refreshQ.length){t.next=3;break}return t.abrupt("return");case 3:return this.emit("refreshStarted",void 0),t.next=6,null==(n=this.onPreRefresh)?void 0:n.call(this);case 6:return a=!1,s={},t.prev=8,t.next=11,this.onRefresh(r);case 11:s=t.sent,a=!0,this.emit("refreshSuccess",void 0),t.next=20;break;case 16:t.prev=16,t.t0=t.catch(8),a=!1,this.emit("refreshFailed",t.t0);case 20:return this.setState({isAuthenticated:a,tokens:s}),t.next=23,null==(o=this.onPostRefresh)?void 0:o.call(this,a);case 23:for(u=this.refreshQ.pop();null!=u;u=this.refreshQ.pop())u.resolve(a);case 24:case"end":return t.stop()}}),t,this,[[8,16]])})));return function(e,r){return t.apply(this,arguments)}}(),n.emit=function(t,e){this.eventEmitter.emit(t,e)},n.notifySubscribers=function(){this.subscribers.forEach((function(t){try{t()}catch(t){}}))},e=t,(r=[{key:"isInitialized",get:function(){return this._state.isInitialized}},{key:"isAuthenticated",get:function(){return this._state.isAuthenticated}},{key:"tokens",get:function(){return this._state.tokens}}])&&function(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}(e.prototype,r),Object.defineProperty(e,"prototype",{writable:!1}),t}(),exports.createAuth=function(t){var o=e.createContext(null);return{AuthProvider:function(s){var u=s.children,c=s.ErrorComponent,h=s.LoadingComponent,f=e.useState(!1),l=f[0],p=f[1],v=n.useSyncExternalStore(t.subscribe,t.getSnapshot),d=v.isAuthenticated,y=v.isInitialized;return e.useEffect((function(){function e(){return(e=a(i().mark((function e(){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.init();case 2:p(!e.sent);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}!function(){e.apply(this,arguments)}()}),[]),c&&l?c:h&&!y?h:r.createElement(o.Provider,{value:{authClient:t,isAuthenticated:d,isInitialized:y}},u)},useAuthClient:function(){var t=e.useContext(o);if(!t)throw new Error("useAuthClient hook should be used inside AuthProvider");return t.authClient}}};
//# sourceMappingURL=react-auth.cjs.production.min.js.map
import React, { createContext, useState, useEffect, useContext } from 'react';
import { useSyncExternalStore } from 'use-sync-external-store/shim';
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function () {
var self = this,
args = arguments;
return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
function _regeneratorRuntime() {
_regeneratorRuntime = function () {
return exports;
};
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
var runtime_1 = createCommonjsModule(function (module) {
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var runtime = (function (exports) {
var Op = Object.prototype;
var hasOwn = Op.hasOwnProperty;
var undefined$1; // More compressible than void 0.
var $Symbol = typeof Symbol === "function" ? Symbol : {};
var iteratorSymbol = $Symbol.iterator || "@@iterator";
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
var exports = {},
Op = Object.prototype,
hasOwn = Op.hasOwnProperty,
defineProperty = Object.defineProperty || function (obj, key, desc) {
obj[key] = desc.value;
},
$Symbol = "function" == typeof Symbol ? Symbol : {},
iteratorSymbol = $Symbol.iterator || "@@iterator",
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
function define(obj, key, value) {
Object.defineProperty(obj, key, {
return Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
return obj[key];
enumerable: !0,
configurable: !0,
writable: !0
}), obj[key];
}
try {
// IE 8 has a broken Object.defineProperty that only works on DOM objects.
define({}, "");
} catch (err) {
define = function(obj, key, value) {
define = function (obj, key, value) {
return obj[key] = value;
};
}
function wrap(innerFn, outerFn, self, tryLocsList) {
// If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
var generator = Object.create(protoGenerator.prototype);
var context = new Context(tryLocsList || []);
// The ._invoke method unifies the implementations of the .next,
// .throw, and .return methods.
generator._invoke = makeInvokeMethod(innerFn, self, context);
return generator;
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
generator = Object.create(protoGenerator.prototype),
context = new Context(tryLocsList || []);
return defineProperty(generator, "_invoke", {
value: makeInvokeMethod(innerFn, self, context)
}), generator;
}
exports.wrap = wrap;
// Try/catch helper to minimize deoptimizations. Returns a completion
// record like context.tryEntries[i].completion. This interface could
// have been (and was previously) designed to take a closure to be
// invoked without arguments, but in all the cases we care about we
// already have an existing method we want to call, so there's no need
// to create a new function object. We can even get away with assuming
// the method takes exactly one argument, since that happens to be true
// in every case, so we don't have to touch the arguments object. The
// only additional allocation required is the completion record, which
// has a stable shape and so hopefully should be cheap to allocate.
function tryCatch(fn, obj, arg) {
try {
return { type: "normal", arg: fn.call(obj, arg) };
return {
type: "normal",
arg: fn.call(obj, arg)
};
} catch (err) {
return { type: "throw", arg: err };
return {
type: "throw",
arg: err
};
}
}
var GenStateSuspendedStart = "suspendedStart";
var GenStateSuspendedYield = "suspendedYield";
var GenStateExecuting = "executing";
var GenStateCompleted = "completed";
// Returning this object from the innerFn has the same effect as
// breaking out of the dispatch switch statement.
exports.wrap = wrap;
var ContinueSentinel = {};
// Dummy constructor functions that we use as the .constructor and
// .constructor.prototype properties for functions that return Generator
// objects. For full spec compliance, you may wish to configure your
// minifier not to mangle the names of these two functions.
function Generator() {}
function GeneratorFunction() {}
function GeneratorFunctionPrototype() {}
// This is a polyfill for %IteratorPrototype% for environments that
// don't natively support it.
var IteratorPrototype = {};

@@ -172,29 +63,9 @@ define(IteratorPrototype, iteratorSymbol, function () {

});
var getProto = Object.getPrototypeOf;
var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
if (NativeIteratorPrototype &&
NativeIteratorPrototype !== Op &&
hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
// This environment has a native %IteratorPrototype%; use it instead
// of the polyfill.
IteratorPrototype = NativeIteratorPrototype;
}
var Gp = GeneratorFunctionPrototype.prototype =
Generator.prototype = Object.create(IteratorPrototype);
GeneratorFunction.prototype = GeneratorFunctionPrototype;
define(Gp, "constructor", GeneratorFunctionPrototype);
define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
GeneratorFunction.displayName = define(
GeneratorFunctionPrototype,
toStringTagSymbol,
"GeneratorFunction"
);
// Helper for defining the .next, .throw, and .return methods of the
// Iterator interface in terms of a single ._invoke method.
var getProto = Object.getPrototypeOf,
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
function defineIteratorMethods(prototype) {
["next", "throw", "return"].forEach(function(method) {
define(prototype, method, function(arg) {
["next", "throw", "return"].forEach(function (method) {
define(prototype, method, function (arg) {
return this._invoke(method, arg);

@@ -204,145 +75,41 @@ });

}
exports.isGeneratorFunction = function(genFun) {
var ctor = typeof genFun === "function" && genFun.constructor;
return ctor
? ctor === GeneratorFunction ||
// For the native GeneratorFunction constructor, the best we can
// do is to check its .name property.
(ctor.displayName || ctor.name) === "GeneratorFunction"
: false;
};
exports.mark = function(genFun) {
if (Object.setPrototypeOf) {
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
} else {
genFun.__proto__ = GeneratorFunctionPrototype;
define(genFun, toStringTagSymbol, "GeneratorFunction");
}
genFun.prototype = Object.create(Gp);
return genFun;
};
// Within the body of any async function, `await x` is transformed to
// `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
// `hasOwn.call(value, "__await")` to determine if the yielded value is
// meant to be awaited.
exports.awrap = function(arg) {
return { __await: arg };
};
function AsyncIterator(generator, PromiseImpl) {
function invoke(method, arg, resolve, reject) {
var record = tryCatch(generator[method], generator, arg);
if (record.type === "throw") {
reject(record.arg);
} else {
var result = record.arg;
var value = result.value;
if (value &&
typeof value === "object" &&
hasOwn.call(value, "__await")) {
return PromiseImpl.resolve(value.__await).then(function(value) {
invoke("next", value, resolve, reject);
}, function(err) {
invoke("throw", err, resolve, reject);
});
}
return PromiseImpl.resolve(value).then(function(unwrapped) {
// When a yielded Promise is resolved, its final value becomes
// the .value of the Promise<{value,done}> result for the
// current iteration.
result.value = unwrapped;
resolve(result);
}, function(error) {
// If a rejected Promise was yielded, throw the rejection back
// into the async generator function so it can be handled there.
if ("throw" !== record.type) {
var result = record.arg,
value = result.value;
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
invoke("next", value, resolve, reject);
}, function (err) {
invoke("throw", err, resolve, reject);
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
result.value = unwrapped, resolve(result);
}, function (error) {
return invoke("throw", error, resolve, reject);
});
}
reject(record.arg);
}
var previousPromise;
function enqueue(method, arg) {
function callInvokeWithMethodAndArg() {
return new PromiseImpl(function(resolve, reject) {
invoke(method, arg, resolve, reject);
});
defineProperty(this, "_invoke", {
value: function (method, arg) {
function callInvokeWithMethodAndArg() {
return new PromiseImpl(function (resolve, reject) {
invoke(method, arg, resolve, reject);
});
}
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
}
return previousPromise =
// If enqueue has been called before, then we want to wait until
// all previous Promises have been resolved before calling invoke,
// so that results are always delivered in the correct order. If
// enqueue has not been called before, then it is important to
// call invoke immediately, without waiting on a callback to fire,
// so that the async generator function has the opportunity to do
// any necessary setup in a predictable way. This predictability
// is why the Promise constructor synchronously invokes its
// executor callback, and why async functions synchronously
// execute code before the first await. Since we implement simple
// async functions in terms of async generators, it is especially
// important to get this right, even though it requires care.
previousPromise ? previousPromise.then(
callInvokeWithMethodAndArg,
// Avoid propagating failures to Promises returned by later
// invocations of the iterator.
callInvokeWithMethodAndArg
) : callInvokeWithMethodAndArg();
}
// Define the unified helper method that is used to implement .next,
// .throw, and .return (see defineIteratorMethods).
this._invoke = enqueue;
});
}
defineIteratorMethods(AsyncIterator.prototype);
define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
return this;
});
exports.AsyncIterator = AsyncIterator;
// Note that simple async functions are implemented on top of
// AsyncIterator objects; they just return a Promise for the value of
// the final result produced by the iterator.
exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
if (PromiseImpl === void 0) PromiseImpl = Promise;
var iter = new AsyncIterator(
wrap(innerFn, outerFn, self, tryLocsList),
PromiseImpl
);
return exports.isGeneratorFunction(outerFn)
? iter // If outerFn is a generator, return the full iterator.
: iter.next().then(function(result) {
return result.done ? result.value : iter.next();
});
};
function makeInvokeMethod(innerFn, self, context) {
var state = GenStateSuspendedStart;
return function invoke(method, arg) {
if (state === GenStateExecuting) {
throw new Error("Generator is already running");
}
if (state === GenStateCompleted) {
if (method === "throw") {
throw arg;
}
// Be forgiving, per 25.3.3.3.3 of the spec:
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
var state = "suspendedStart";
return function (method, arg) {
if ("executing" === state) throw new Error("Generator is already running");
if ("completed" === state) {
if ("throw" === method) throw arg;
return doneResult();
}
context.method = method;
context.arg = arg;
while (true) {
for (context.method = method, context.arg = arg;;) {
var delegate = context.delegate;

@@ -356,34 +123,10 @@ if (delegate) {

}
if (context.method === "next") {
// Setting context._sent for legacy support of Babel's
// function.sent implementation.
context.sent = context._sent = context.arg;
} else if (context.method === "throw") {
if (state === GenStateSuspendedStart) {
state = GenStateCompleted;
throw context.arg;
}
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
if ("suspendedStart" === state) throw state = "completed", context.arg;
context.dispatchException(context.arg);
} else if (context.method === "return") {
context.abrupt("return", context.arg);
}
state = GenStateExecuting;
} else "return" === context.method && context.abrupt("return", context.arg);
state = "executing";
var record = tryCatch(innerFn, self, context);
if (record.type === "normal") {
// If an exception is thrown from innerFn, we leave state ===
// GenStateExecuting and loop back for another invocation.
state = context.done
? GenStateCompleted
: GenStateSuspendedYield;
if (record.arg === ContinueSentinel) {
continue;
}
if ("normal" === record.type) {
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
return {

@@ -393,310 +136,130 @@ value: record.arg,

};
} else if (record.type === "throw") {
state = GenStateCompleted;
// Dispatch the exception by looping back around to the
// context.dispatchException(context.arg) call above.
context.method = "throw";
context.arg = record.arg;
}
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
}
};
}
// Call delegate.iterator[context.method](context.arg) and handle the
// result, either by returning a { value, done } result from the
// delegate iterator, or by modifying context.method and context.arg,
// setting context.delegate to null, and returning the ContinueSentinel.
function maybeInvokeDelegate(delegate, context) {
var method = delegate.iterator[context.method];
if (method === undefined$1) {
// A .throw or .return when the delegate iterator has no .throw
// method always terminates the yield* loop.
context.delegate = null;
if (context.method === "throw") {
// Note: ["return"] must be used for ES3 parsing compatibility.
if (delegate.iterator["return"]) {
// If the delegate iterator has a return method, give it a
// chance to clean up.
context.method = "return";
context.arg = undefined$1;
maybeInvokeDelegate(delegate, context);
if (context.method === "throw") {
// If maybeInvokeDelegate(context) changed context.method from
// "return" to "throw", let that override the TypeError below.
return ContinueSentinel;
}
}
context.method = "throw";
context.arg = new TypeError(
"The iterator does not provide a 'throw' method");
if (undefined === method) {
if (context.delegate = null, "throw" === context.method) {
if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
}
return ContinueSentinel;
}
var record = tryCatch(method, delegate.iterator, context.arg);
if (record.type === "throw") {
context.method = "throw";
context.arg = record.arg;
context.delegate = null;
return ContinueSentinel;
}
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
var info = record.arg;
if (! info) {
context.method = "throw";
context.arg = new TypeError("iterator result is not an object");
context.delegate = null;
return ContinueSentinel;
}
if (info.done) {
// Assign the result of the finished delegate to the temporary
// variable specified by delegate.resultName (see delegateYield).
context[delegate.resultName] = info.value;
// Resume execution at the desired location (see delegateYield).
context.next = delegate.nextLoc;
// If context.method was "throw" but the delegate handled the
// exception, let the outer generator proceed normally. If
// context.method was "next", forget context.arg since it has been
// "consumed" by the delegate iterator. If context.method was
// "return", allow the original .return call to continue in the
// outer generator.
if (context.method !== "return") {
context.method = "next";
context.arg = undefined$1;
}
} else {
// Re-yield the result returned by the delegate method.
return info;
}
// The delegate iterator is finished, so forget it and continue with
// the outer generator.
context.delegate = null;
return ContinueSentinel;
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);
}
// Define Generator.prototype.{next,throw,return} in terms of the
// unified ._invoke helper method.
defineIteratorMethods(Gp);
define(Gp, toStringTagSymbol, "Generator");
// A Generator should always return itself as the iterator object when the
// @@iterator function is called on it. Some browsers' implementations of the
// iterator prototype chain incorrectly implement this, causing the Generator
// object to not be returned from this call. This ensures that doesn't happen.
// See https://github.com/facebook/regenerator/issues/274 for more details.
define(Gp, iteratorSymbol, function() {
return this;
});
define(Gp, "toString", function() {
return "[object Generator]";
});
function pushTryEntry(locs) {
var entry = { tryLoc: locs[0] };
if (1 in locs) {
entry.catchLoc = locs[1];
}
if (2 in locs) {
entry.finallyLoc = locs[2];
entry.afterLoc = locs[3];
}
this.tryEntries.push(entry);
var entry = {
tryLoc: locs[0]
};
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
}
function resetTryEntry(entry) {
var record = entry.completion || {};
record.type = "normal";
delete record.arg;
entry.completion = record;
record.type = "normal", delete record.arg, entry.completion = record;
}
function Context(tryLocsList) {
// The root entry object (effectively a try statement without a catch
// or a finally block) gives us a place to store values thrown from
// locations where there is no enclosing try statement.
this.tryEntries = [{ tryLoc: "root" }];
tryLocsList.forEach(pushTryEntry, this);
this.reset(true);
this.tryEntries = [{
tryLoc: "root"
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
}
exports.keys = function(object) {
var keys = [];
for (var key in object) {
keys.push(key);
}
keys.reverse();
// Rather than returning an object with a next method, we keep
// things simple and return the next function itself.
return function next() {
while (keys.length) {
var key = keys.pop();
if (key in object) {
next.value = key;
next.done = false;
return next;
}
}
// To avoid creating an additional object, we just hang the .value
// and .done properties off the next function object itself. This
// also ensures that the minifier will not anonymize the function.
next.done = true;
return next;
};
};
function values(iterable) {
if (iterable) {
var iteratorMethod = iterable[iteratorSymbol];
if (iteratorMethod) {
return iteratorMethod.call(iterable);
}
if (typeof iterable.next === "function") {
return iterable;
}
if (iteratorMethod) return iteratorMethod.call(iterable);
if ("function" == typeof iterable.next) return iterable;
if (!isNaN(iterable.length)) {
var i = -1, next = function next() {
while (++i < iterable.length) {
if (hasOwn.call(iterable, i)) {
next.value = iterable[i];
next.done = false;
return next;
}
}
next.value = undefined$1;
next.done = true;
return next;
};
var i = -1,
next = function next() {
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
return next.value = undefined, next.done = !0, next;
};
return next.next = next;
}
}
// Return an iterator with no values.
return { next: doneResult };
return {
next: doneResult
};
}
exports.values = values;
function doneResult() {
return { value: undefined$1, done: true };
return {
value: undefined,
done: !0
};
}
Context.prototype = {
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
value: GeneratorFunctionPrototype,
configurable: !0
}), defineProperty(GeneratorFunctionPrototype, "constructor", {
value: GeneratorFunction,
configurable: !0
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
var ctor = "function" == typeof genFun && genFun.constructor;
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
}, exports.mark = function (genFun) {
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
}, exports.awrap = function (arg) {
return {
__await: arg
};
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
return this;
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
void 0 === PromiseImpl && (PromiseImpl = Promise);
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
return result.done ? result.value : iter.next();
});
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
return this;
}), define(Gp, "toString", function () {
return "[object Generator]";
}), exports.keys = function (val) {
var object = Object(val),
keys = [];
for (var key in object) keys.push(key);
return keys.reverse(), function next() {
for (; keys.length;) {
var key = keys.pop();
if (key in object) return next.value = key, next.done = !1, next;
}
return next.done = !0, next;
};
}, exports.values = values, Context.prototype = {
constructor: Context,
reset: function(skipTempReset) {
this.prev = 0;
this.next = 0;
// Resetting context._sent for legacy support of Babel's
// function.sent implementation.
this.sent = this._sent = undefined$1;
this.done = false;
this.delegate = null;
this.method = "next";
this.arg = undefined$1;
this.tryEntries.forEach(resetTryEntry);
if (!skipTempReset) {
for (var name in this) {
// Not sure about the optimal order of these conditions:
if (name.charAt(0) === "t" &&
hasOwn.call(this, name) &&
!isNaN(+name.slice(1))) {
this[name] = undefined$1;
}
}
}
reset: function (skipTempReset) {
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);
},
stop: function() {
this.done = true;
var rootEntry = this.tryEntries[0];
var rootRecord = rootEntry.completion;
if (rootRecord.type === "throw") {
throw rootRecord.arg;
}
stop: function () {
this.done = !0;
var rootRecord = this.tryEntries[0].completion;
if ("throw" === rootRecord.type) throw rootRecord.arg;
return this.rval;
},
dispatchException: function(exception) {
if (this.done) {
throw exception;
}
dispatchException: function (exception) {
if (this.done) throw exception;
var context = this;
function handle(loc, caught) {
record.type = "throw";
record.arg = exception;
context.next = loc;
if (caught) {
// If the dispatched exception was caught by a catch block,
// then let that catch block handle the exception normally.
context.method = "next";
context.arg = undefined$1;
}
return !! caught;
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
}
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
var record = entry.completion;
if (entry.tryLoc === "root") {
// Exception thrown outside of any try block that could handle
// it, so set the completion value of the entire function to
// throw the exception.
return handle("end");
}
var entry = this.tryEntries[i],
record = entry.completion;
if ("root" === entry.tryLoc) return handle("end");
if (entry.tryLoc <= this.prev) {
var hasCatch = hasOwn.call(entry, "catchLoc");
var hasFinally = hasOwn.call(entry, "finallyLoc");
var hasCatch = hasOwn.call(entry, "catchLoc"),
hasFinally = hasOwn.call(entry, "finallyLoc");
if (hasCatch && hasFinally) {
if (this.prev < entry.catchLoc) {
return handle(entry.catchLoc, true);
} else if (this.prev < entry.finallyLoc) {
return handle(entry.finallyLoc);
}
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
} else if (hasCatch) {
if (this.prev < entry.catchLoc) {
return handle(entry.catchLoc, true);
}
} else if (hasFinally) {
if (this.prev < entry.finallyLoc) {
return handle(entry.finallyLoc);
}
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
} else {
throw new Error("try statement without catch or finally");
if (!hasFinally) throw new Error("try statement without catch or finally");
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
}

@@ -706,9 +269,6 @@ }

},
abrupt: function(type, arg) {
abrupt: function (type, arg) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.tryLoc <= this.prev &&
hasOwn.call(entry, "finallyLoc") &&
this.prev < entry.finallyLoc) {
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
var finallyEntry = entry;

@@ -718,57 +278,17 @@ break;

}
if (finallyEntry &&
(type === "break" ||
type === "continue") &&
finallyEntry.tryLoc <= arg &&
arg <= finallyEntry.finallyLoc) {
// Ignore the finally entry if control is not jumping to a
// location outside the try/catch block.
finallyEntry = null;
}
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
var record = finallyEntry ? finallyEntry.completion : {};
record.type = type;
record.arg = arg;
if (finallyEntry) {
this.method = "next";
this.next = finallyEntry.finallyLoc;
return ContinueSentinel;
}
return this.complete(record);
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
},
complete: function(record, afterLoc) {
if (record.type === "throw") {
throw record.arg;
}
if (record.type === "break" ||
record.type === "continue") {
this.next = record.arg;
} else if (record.type === "return") {
this.rval = this.arg = record.arg;
this.method = "return";
this.next = "end";
} else if (record.type === "normal" && afterLoc) {
this.next = afterLoc;
}
return ContinueSentinel;
complete: function (record, afterLoc) {
if ("throw" === record.type) throw record.arg;
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;
},
finish: function(finallyLoc) {
finish: function (finallyLoc) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.finallyLoc === finallyLoc) {
this.complete(entry.completion, entry.afterLoc);
resetTryEntry(entry);
return ContinueSentinel;
}
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
}
},
"catch": function(tryLoc) {
catch: function (tryLoc) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {

@@ -778,3 +298,3 @@ var entry = this.tryEntries[i];

var record = entry.completion;
if (record.type === "throw") {
if ("throw" === record.type) {
var thrown = record.arg;

@@ -786,59 +306,89 @@ resetTryEntry(entry);

}
// The context.catch method must only be called with a location
// argument that corresponds to a known catch block.
throw new Error("illegal catch attempt");
},
delegateYield: function(iterable, resultName, nextLoc) {
this.delegate = {
delegateYield: function (iterable, resultName, nextLoc) {
return this.delegate = {
iterator: values(iterable),
resultName: resultName,
nextLoc: nextLoc
};
if (this.method === "next") {
// Deliberately forget the last sent value so that we don't
// accidentally pass it on to the delegate.
this.arg = undefined$1;
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
}
}, exports;
}
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function () {
var self = this,
args = arguments;
return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
return ContinueSentinel;
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
// Regardless of whether this script is executing as a CommonJS module
// or not, return the runtime object so that we can declare the variable
// regeneratorRuntime in the outer scope, which allows this module to be
// injected easily by `bin/regenerator --include-runtime script.js`.
return exports;
}(
// If this script is executing as a CommonJS module, use module.exports
// as the regeneratorRuntime namespace. Otherwise create a new empty
// object. Either way, the resulting object will be used to initialize
// the regeneratorRuntime variable at the top of this file.
module.exports
));
try {
regeneratorRuntime = runtime;
} catch (accidentalStrictMode) {
// This module should not be running in strict mode, so the above
// assignment should always work unless something is misconfigured. Just
// in case runtime.js accidentally runs in strict mode, in modern engines
// we can explicitly access globalThis. In older engines we can escape
// strict mode using a global Function call. This could conceivably fail
// if a Content Security Policy forbids using Function, but in that case
// the proper solution is to fix the accidental strict mode problem. If
// you've misconfigured your bundler to force strict mode and applied a
// CSP to forbid Function, and you're not willing to fix either of those
// problems, please detail your unique predicament in a GitHub issue.
if (typeof globalThis === "object") {
globalThis.regeneratorRuntime = runtime;
} else {
Function("r", "regeneratorRuntime = r")(runtime);
var Deferred = /*#__PURE__*/function () {
function Deferred() {
var _this = this;
this.promise = new Promise(function (resolve, reject) {
_this.reject = reject;
_this.resolve = resolve;
});
}
}
});
var _proto = Deferred.prototype;
_proto.getPromise = function getPromise() {
return this.promise;
};
return Deferred;
}();

@@ -870,3 +420,2 @@ // TODO: Improve -> `listeners` are unbounded -- don't use this in practice!

var _this = this;
this._state = {

@@ -877,24 +426,22 @@ isAuthenticated: false,

};
// refresh queue - used to avoid concurrency issue during Token refresh
this.refreshQ = [];
this.eventEmitter = createEventEmitter();
this.subscribers = new Set(); // Should be declared like this to avoid binding issues when used by useSyncExternalStore
this.subscribers = new Set();
// Should be declared like this to avoid binding issues when used by useSyncExternalStore
this.subscribe = function (subscription) {
_this.subscribers.add(subscription);
return function () {
return _this.subscribers["delete"](subscription);
};
}; // Should be declared like this to avoid binding issues when used by useSyncExternalStore
};
// Should be declared like this to avoid binding issues when used by useSyncExternalStore
this.getSnapshot = function () {
return _this._state;
};
} //
}
//
// Getters
//
var _proto = BaseAuthClient.prototype;
//

@@ -906,6 +453,5 @@ // Public methods

function () {
var _init = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
var _init = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
var _this$onPostInit;
return runtime_1.wrap(function _callee$(_context) {
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) {

@@ -917,3 +463,2 @@ switch (_context.prev = _context.next) {

return this.onInit();
case 3:

@@ -926,3 +471,2 @@ this.setState({

break;
case 7:

@@ -935,10 +479,7 @@ _context.prev = 7;

this.emit('initFailed', _context.t0);
case 11:
_context.next = 13;
return (_this$onPostInit = this.onPostInit) == null ? void 0 : _this$onPostInit.call(this);
case 13:
return _context.abrupt("return", this.isInitialized);
case 14:

@@ -951,16 +492,12 @@ case "end":

}));
function init() {
return _init.apply(this, arguments);
}
return init;
}();
_proto.login = /*#__PURE__*/function () {
var _login = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(credentials) {
var _login = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(credentials) {
var _this$onPreLogin, _this$onPostLogin;
var isSuccess, tokens;
return runtime_1.wrap(function _callee2$(_context2) {
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) {

@@ -972,3 +509,2 @@ switch (_context2.prev = _context2.next) {

return (_this$onPreLogin = this.onPreLogin) == null ? void 0 : _this$onPreLogin.call(this);
case 3:

@@ -979,3 +515,2 @@ isSuccess = false;

return this.onLogin(credentials);
case 7:

@@ -991,3 +526,2 @@ tokens = _context2.sent;

break;
case 13:

@@ -1002,10 +536,7 @@ _context2.prev = 13;

isSuccess = false;
case 18:
_context2.next = 20;
return (_this$onPostLogin = this.onPostLogin) == null ? void 0 : _this$onPostLogin.call(this, isSuccess);
case 20:
return _context2.abrupt("return", this.isAuthenticated);
case 21:

@@ -1018,58 +549,18 @@ case "end":

}));
function login(_x) {
return _login.apply(this, arguments);
}
return login;
}();
_proto.refresh = /*#__PURE__*/function () {
var _refresh = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(minValidity) {
var _this$onPreRefresh, _this$onPostRefresh;
var isSuccess, tokens;
return runtime_1.wrap(function _callee3$(_context3) {
var _refresh = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(minValidity) {
var deferred;
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
this.emit('refreshStarted', undefined);
_context3.next = 3;
return (_this$onPreRefresh = this.onPreRefresh) == null ? void 0 : _this$onPreRefresh.call(this);
deferred = new Deferred();
this.runRefresh(deferred, minValidity);
return _context3.abrupt("return", deferred.getPromise());
case 3:
isSuccess = false;
_context3.prev = 4;
_context3.next = 7;
return this.onRefresh(minValidity);
case 7:
tokens = _context3.sent;
this.setState({
isAuthenticated: true,
tokens: tokens
});
this.emit('refreshSuccess', undefined);
isSuccess = true;
_context3.next = 18;
break;
case 13:
_context3.prev = 13;
_context3.t0 = _context3["catch"](4);
this.setState({
isAuthenticated: false,
tokens: {}
});
this.emit('refreshFailed', _context3.t0);
isSuccess = false;
case 18:
_context3.next = 20;
return (_this$onPostRefresh = this.onPostRefresh) == null ? void 0 : _this$onPostRefresh.call(this, isSuccess);
case 20:
return _context3.abrupt("return", this.isAuthenticated);
case 21:
case "end":

@@ -1079,18 +570,14 @@ return _context3.stop();

}
}, _callee3, this, [[4, 13]]);
}, _callee3, this);
}));
function refresh(_x2) {
return _refresh.apply(this, arguments);
}
return refresh;
}();
_proto.logout = /*#__PURE__*/function () {
var _logout = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
var _logout = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
var _this$onPreLogout, _this$onPostLogout;
var isSuccess;
return runtime_1.wrap(function _callee4$(_context4) {
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
while (1) {

@@ -1102,3 +589,2 @@ switch (_context4.prev = _context4.next) {

return (_this$onPreLogout = this.onPreLogout) == null ? void 0 : _this$onPreLogout.call(this);
case 3:

@@ -1109,3 +595,2 @@ isSuccess = false;

return this.onLogout();
case 7:

@@ -1120,3 +605,2 @@ this.setState({

break;
case 12:

@@ -1127,7 +611,5 @@ _context4.prev = 12;

isSuccess = false;
case 16:
_context4.next = 18;
return (_this$onPostLogout = this.onPostLogout) == null ? void 0 : _this$onPostLogout.call(this, isSuccess);
case 18:

@@ -1140,33 +622,90 @@ case "end":

}));
function logout() {
return _logout.apply(this, arguments);
}
return logout;
}();
_proto.on = function on(eventName, listener) {
this.eventEmitter.on(eventName, listener);
};
_proto.off = function off(eventName, listener) {
this.eventEmitter.off(eventName, listener);
} //
}
//
// Protected methods
//
;
_proto.setState = function setState(stateUpdate) {
this._state = _extends({}, this._state, stateUpdate);
this.notifySubscribers();
} //
}
//
// Private methods
//
;
_proto.runRefresh =
/*#__PURE__*/
function () {
var _runRefresh = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(deferred, minValidity) {
var _this$onPreRefresh, _this$onPostRefresh;
var isAuthenticated, tokens, p;
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
// Add deferred Promise to refresh queue
this.refreshQ.push(deferred);
// If refresh queue already has promises enqueued do not attempt a new refresh - one is already in progress
if (!(this.refreshQ.length !== 1)) {
_context5.next = 3;
break;
}
return _context5.abrupt("return");
case 3:
this.emit('refreshStarted', undefined);
_context5.next = 6;
return (_this$onPreRefresh = this.onPreRefresh) == null ? void 0 : _this$onPreRefresh.call(this);
case 6:
isAuthenticated = false;
tokens = {};
_context5.prev = 8;
_context5.next = 11;
return this.onRefresh(minValidity);
case 11:
tokens = _context5.sent;
isAuthenticated = true;
this.emit('refreshSuccess', undefined);
_context5.next = 20;
break;
case 16:
_context5.prev = 16;
_context5.t0 = _context5["catch"](8);
isAuthenticated = false;
this.emit('refreshFailed', _context5.t0);
case 20:
this.setState({
isAuthenticated: isAuthenticated,
tokens: tokens
});
_context5.next = 23;
return (_this$onPostRefresh = this.onPostRefresh) == null ? void 0 : _this$onPostRefresh.call(this, isAuthenticated);
case 23:
for (p = this.refreshQ.pop(); p != null; p = this.refreshQ.pop()) {
p.resolve(isAuthenticated);
}
case 24:
case "end":
return _context5.stop();
}
}
}, _callee5, this, [[8, 16]]);
}));
function runRefresh(_x3, _x4) {
return _runRefresh.apply(this, arguments);
}
return runRefresh;
}();
_proto.emit = function emit(eventName, error) {
this.eventEmitter.emit(eventName, error);
};
_proto.notifySubscribers = function notifySubscribers() {

@@ -1179,3 +718,2 @@ this.subscribers.forEach(function (s) {

};
_createClass(BaseAuthClient, [{

@@ -1197,3 +735,2 @@ key: "isInitialized",

}]);
return BaseAuthClient;

@@ -1204,17 +741,14 @@ }();

// Create a React context containing a BaseAuthClient instance.
var authContext = createContext(null); // Create the React Context Provider for the BaseAuthClient instance.
var authContext = createContext(null);
// Create the React Context Provider for the BaseAuthClient instance.
var AuthProvider = function AuthProvider(_ref) {
var children = _ref.children,
ErrorComponent = _ref.ErrorComponent,
LoadingComponent = _ref.LoadingComponent;
ErrorComponent = _ref.ErrorComponent,
LoadingComponent = _ref.LoadingComponent;
var _useState = useState(false),
isInitFailed = _useState[0],
setInitFailed = _useState[1];
isInitFailed = _useState[0],
setInitFailed = _useState[1];
var _useSyncExternalStore = useSyncExternalStore(authClient.subscribe, authClient.getSnapshot),
isAuthenticated = _useSyncExternalStore.isAuthenticated,
isInitialized = _useSyncExternalStore.isInitialized;
isAuthenticated = _useSyncExternalStore.isAuthenticated,
isInitialized = _useSyncExternalStore.isInitialized;
useEffect(function () {

@@ -1224,8 +758,6 @@ function initAuthClient() {

} // Init AuthClient
function _initAuthClient() {
_initAuthClient = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
_initAuthClient = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
var initSuccess;
return runtime_1.wrap(function _callee$(_context) {
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) {

@@ -1236,7 +768,5 @@ switch (_context.prev = _context.next) {

return authClient.init();
case 2:
initSuccess = _context.sent;
setInitFailed(!initSuccess);
case 4:

@@ -1251,14 +781,10 @@ case "end":

}
initAuthClient();
}, []);
if (!!ErrorComponent && isInitFailed) {
return ErrorComponent;
}
if (!!LoadingComponent && !isInitialized) {
return LoadingComponent;
}
return React.createElement(authContext.Provider, {

@@ -1271,15 +797,11 @@ value: {

}, children);
}; // Retrieve the AuthClient from the current context
};
// Retrieve the AuthClient from the current context
var useAuthClient = function useAuthClient() {
var ctx = useContext(authContext);
if (!ctx) {
throw new Error('useAuthClient hook should be used inside AuthProvider');
}
return ctx.authClient;
};
return {

@@ -1286,0 +808,0 @@ AuthProvider: AuthProvider,

@@ -26,2 +26,3 @@ import { EventKey, EventReceiver } from './eventEmitter';

private _state;
private refreshQ;
private eventEmitter;

@@ -41,2 +42,3 @@ private subscribers;

protected setState(stateUpdate: Partial<AuthClientState<T>>): void;
private runRefresh;
private emit;

@@ -43,0 +45,0 @@ private notifySubscribers;

{
"name": "@forward-software/react-auth",
"version": "1.0.2",
"version": "1.1.0",
"author": "ForWarD Software (https://github.com/Forward-Software)",

@@ -46,19 +46,16 @@ "license": "MIT",

"devDependencies": {
"@size-limit/preset-small-lib": "^7.0.8",
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/react": "^12.1.2",
"@testing-library/react-hooks": "^7.0.2",
"@types/react": "^17.0.39",
"@types/react-dom": "^17.0.11",
"@size-limit/preset-small-lib": "^8.1.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"@types/use-sync-external-store": "^0.0.3",
"husky": "^7.0.4",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"size-limit": "^7.0.8",
"tsdx": "^0.14.1",
"tslib": "^2.3.1",
"typescript": "^4.5.5"
"husky": "^8.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"size-limit": "^8.1.0",
"tsdx": "^0.14.1"
},
"dependencies": {
"use-sync-external-store": "^1.0.0"
"use-sync-external-store": "^1.2.0"
},

@@ -65,0 +62,0 @@ "peerDependencies": {

@@ -0,1 +1,2 @@

import { Deferred } from './deferred';
import { createEventEmitter, EventKey, EventReceiver } from './eventEmitter';

@@ -54,2 +55,5 @@

// refresh queue - used to avoid concurrency issue during Token refresh
private refreshQ: Array<Deferred<boolean>> = [];
private eventEmitter = createEventEmitter<AuthEventsMap<E>>();

@@ -136,33 +140,7 @@

public async refresh(minValidity?: number): Promise<boolean> {
this.emit('refreshStarted', undefined);
const deferred = new Deferred<boolean>();
await this.onPreRefresh?.();
this.runRefresh(deferred, minValidity);
let isSuccess: boolean = false;
try {
const tokens = await this.onRefresh(minValidity);
this.setState({
isAuthenticated: true,
tokens,
});
this.emit('refreshSuccess', undefined);
isSuccess = true;
} catch (err) {
this.setState({
isAuthenticated: false,
tokens: {},
});
this.emit('refreshFailed', err as E);
isSuccess = false;
}
await this.onPostRefresh?.(isSuccess);
return this.isAuthenticated;
return deferred.getPromise();
}

@@ -240,2 +218,44 @@

private async runRefresh(
deferred: Deferred<boolean>,
minValidity?: number
): Promise<void> {
// Add deferred Promise to refresh queue
this.refreshQ.push(deferred);
// If refresh queue already has promises enqueued do not attempt a new refresh - one is already in progress
if (this.refreshQ.length !== 1) {
return;
}
this.emit('refreshStarted', undefined);
await this.onPreRefresh?.();
let isAuthenticated: boolean = false;
let tokens: Partial<T> = {};
try {
tokens = await this.onRefresh(minValidity);
isAuthenticated = true;
this.emit('refreshSuccess', undefined);
} catch (err) {
isAuthenticated = false;
this.emit('refreshFailed', err as E);
}
this.setState({
isAuthenticated,
tokens,
});
await this.onPostRefresh?.(isAuthenticated);
for (let p = this.refreshQ.pop(); p != null; p = this.refreshQ.pop()) {
p.resolve(isAuthenticated);
}
}
private emit<K extends EventKey<AuthEventsMap<E>>>(

@@ -242,0 +262,0 @@ eventName: K,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc