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