1 | import { __decorate } from 'tslib';
|
2 | import { applyMagic } from 'js-magic';
|
3 | import axios from 'axios';
|
4 | import { CatchAll } from '@magna_shogun/catch-decorator';
|
5 |
|
6 | function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
7 | try {
|
8 | var info = gen[key](arg);
|
9 | var value = info.value;
|
10 | } catch (error) {
|
11 | reject(error);
|
12 | return;
|
13 | }
|
14 |
|
15 | if (info.done) {
|
16 | resolve(value);
|
17 | } else {
|
18 | Promise.resolve(value).then(_next, _throw);
|
19 | }
|
20 | }
|
21 |
|
22 | function _asyncToGenerator(fn) {
|
23 | return function () {
|
24 | var self = this,
|
25 | args = arguments;
|
26 | return new Promise(function (resolve, reject) {
|
27 | var gen = fn.apply(self, args);
|
28 |
|
29 | function _next(value) {
|
30 | asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
31 | }
|
32 |
|
33 | function _throw(err) {
|
34 | asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
35 | }
|
36 |
|
37 | _next(undefined);
|
38 | });
|
39 | };
|
40 | }
|
41 |
|
42 | function _extends() {
|
43 | _extends = Object.assign || function (target) {
|
44 | for (var i = 1; i < arguments.length; i++) {
|
45 | var source = arguments[i];
|
46 |
|
47 | for (var key in source) {
|
48 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
49 | target[key] = source[key];
|
50 | }
|
51 | }
|
52 | }
|
53 |
|
54 | return target;
|
55 | };
|
56 |
|
57 | return _extends.apply(this, arguments);
|
58 | }
|
59 |
|
60 | function _objectWithoutPropertiesLoose(source, excluded) {
|
61 | if (source == null) return {};
|
62 | var target = {};
|
63 | var sourceKeys = Object.keys(source);
|
64 | var key, i;
|
65 |
|
66 | for (i = 0; i < sourceKeys.length; i++) {
|
67 | key = sourceKeys[i];
|
68 | if (excluded.indexOf(key) >= 0) continue;
|
69 | target[key] = source[key];
|
70 | }
|
71 |
|
72 | return target;
|
73 | }
|
74 |
|
75 | function createCommonjsModule(fn, module) {
|
76 | return module = { exports: {} }, fn(module, module.exports), module.exports;
|
77 | }
|
78 |
|
79 | var runtime_1 = createCommonjsModule(function (module) {
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | var runtime = (function (exports) {
|
88 |
|
89 | var Op = Object.prototype;
|
90 | var hasOwn = Op.hasOwnProperty;
|
91 | var undefined$1;
|
92 | var $Symbol = typeof Symbol === "function" ? Symbol : {};
|
93 | var iteratorSymbol = $Symbol.iterator || "@@iterator";
|
94 | var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
|
95 | var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
96 |
|
97 | function define(obj, key, value) {
|
98 | Object.defineProperty(obj, key, {
|
99 | value: value,
|
100 | enumerable: true,
|
101 | configurable: true,
|
102 | writable: true
|
103 | });
|
104 | return obj[key];
|
105 | }
|
106 | try {
|
107 |
|
108 | define({}, "");
|
109 | } catch (err) {
|
110 | define = function(obj, key, value) {
|
111 | return obj[key] = value;
|
112 | };
|
113 | }
|
114 |
|
115 | function wrap(innerFn, outerFn, self, tryLocsList) {
|
116 |
|
117 | var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
|
118 | var generator = Object.create(protoGenerator.prototype);
|
119 | var context = new Context(tryLocsList || []);
|
120 |
|
121 |
|
122 |
|
123 | generator._invoke = makeInvokeMethod(innerFn, self, context);
|
124 |
|
125 | return generator;
|
126 | }
|
127 | exports.wrap = wrap;
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 | function tryCatch(fn, obj, arg) {
|
140 | try {
|
141 | return { type: "normal", arg: fn.call(obj, arg) };
|
142 | } catch (err) {
|
143 | return { type: "throw", arg: err };
|
144 | }
|
145 | }
|
146 |
|
147 | var GenStateSuspendedStart = "suspendedStart";
|
148 | var GenStateSuspendedYield = "suspendedYield";
|
149 | var GenStateExecuting = "executing";
|
150 | var GenStateCompleted = "completed";
|
151 |
|
152 |
|
153 |
|
154 | var ContinueSentinel = {};
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 | function Generator() {}
|
161 | function GeneratorFunction() {}
|
162 | function GeneratorFunctionPrototype() {}
|
163 |
|
164 |
|
165 |
|
166 | var IteratorPrototype = {};
|
167 | IteratorPrototype[iteratorSymbol] = function () {
|
168 | return this;
|
169 | };
|
170 |
|
171 | var getProto = Object.getPrototypeOf;
|
172 | var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
173 | if (NativeIteratorPrototype &&
|
174 | NativeIteratorPrototype !== Op &&
|
175 | hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
|
176 |
|
177 |
|
178 | IteratorPrototype = NativeIteratorPrototype;
|
179 | }
|
180 |
|
181 | var Gp = GeneratorFunctionPrototype.prototype =
|
182 | Generator.prototype = Object.create(IteratorPrototype);
|
183 | GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
|
184 | GeneratorFunctionPrototype.constructor = GeneratorFunction;
|
185 | GeneratorFunction.displayName = define(
|
186 | GeneratorFunctionPrototype,
|
187 | toStringTagSymbol,
|
188 | "GeneratorFunction"
|
189 | );
|
190 |
|
191 |
|
192 |
|
193 | function defineIteratorMethods(prototype) {
|
194 | ["next", "throw", "return"].forEach(function(method) {
|
195 | define(prototype, method, function(arg) {
|
196 | return this._invoke(method, arg);
|
197 | });
|
198 | });
|
199 | }
|
200 |
|
201 | exports.isGeneratorFunction = function(genFun) {
|
202 | var ctor = typeof genFun === "function" && genFun.constructor;
|
203 | return ctor
|
204 | ? ctor === GeneratorFunction ||
|
205 |
|
206 |
|
207 | (ctor.displayName || ctor.name) === "GeneratorFunction"
|
208 | : false;
|
209 | };
|
210 |
|
211 | exports.mark = function(genFun) {
|
212 | if (Object.setPrototypeOf) {
|
213 | Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
|
214 | } else {
|
215 | genFun.__proto__ = GeneratorFunctionPrototype;
|
216 | define(genFun, toStringTagSymbol, "GeneratorFunction");
|
217 | }
|
218 | genFun.prototype = Object.create(Gp);
|
219 | return genFun;
|
220 | };
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 | exports.awrap = function(arg) {
|
227 | return { __await: arg };
|
228 | };
|
229 |
|
230 | function AsyncIterator(generator, PromiseImpl) {
|
231 | function invoke(method, arg, resolve, reject) {
|
232 | var record = tryCatch(generator[method], generator, arg);
|
233 | if (record.type === "throw") {
|
234 | reject(record.arg);
|
235 | } else {
|
236 | var result = record.arg;
|
237 | var value = result.value;
|
238 | if (value &&
|
239 | typeof value === "object" &&
|
240 | hasOwn.call(value, "__await")) {
|
241 | return PromiseImpl.resolve(value.__await).then(function(value) {
|
242 | invoke("next", value, resolve, reject);
|
243 | }, function(err) {
|
244 | invoke("throw", err, resolve, reject);
|
245 | });
|
246 | }
|
247 |
|
248 | return PromiseImpl.resolve(value).then(function(unwrapped) {
|
249 |
|
250 |
|
251 |
|
252 | result.value = unwrapped;
|
253 | resolve(result);
|
254 | }, function(error) {
|
255 |
|
256 |
|
257 | return invoke("throw", error, resolve, reject);
|
258 | });
|
259 | }
|
260 | }
|
261 |
|
262 | var previousPromise;
|
263 |
|
264 | function enqueue(method, arg) {
|
265 | function callInvokeWithMethodAndArg() {
|
266 | return new PromiseImpl(function(resolve, reject) {
|
267 | invoke(method, arg, resolve, reject);
|
268 | });
|
269 | }
|
270 |
|
271 | return previousPromise =
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 | previousPromise ? previousPromise.then(
|
285 | callInvokeWithMethodAndArg,
|
286 |
|
287 |
|
288 | callInvokeWithMethodAndArg
|
289 | ) : callInvokeWithMethodAndArg();
|
290 | }
|
291 |
|
292 |
|
293 |
|
294 | this._invoke = enqueue;
|
295 | }
|
296 |
|
297 | defineIteratorMethods(AsyncIterator.prototype);
|
298 | AsyncIterator.prototype[asyncIteratorSymbol] = function () {
|
299 | return this;
|
300 | };
|
301 | exports.AsyncIterator = AsyncIterator;
|
302 |
|
303 |
|
304 |
|
305 |
|
306 | exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
307 | if (PromiseImpl === void 0) PromiseImpl = Promise;
|
308 |
|
309 | var iter = new AsyncIterator(
|
310 | wrap(innerFn, outerFn, self, tryLocsList),
|
311 | PromiseImpl
|
312 | );
|
313 |
|
314 | return exports.isGeneratorFunction(outerFn)
|
315 | ? iter
|
316 | : iter.next().then(function(result) {
|
317 | return result.done ? result.value : iter.next();
|
318 | });
|
319 | };
|
320 |
|
321 | function makeInvokeMethod(innerFn, self, context) {
|
322 | var state = GenStateSuspendedStart;
|
323 |
|
324 | return function invoke(method, arg) {
|
325 | if (state === GenStateExecuting) {
|
326 | throw new Error("Generator is already running");
|
327 | }
|
328 |
|
329 | if (state === GenStateCompleted) {
|
330 | if (method === "throw") {
|
331 | throw arg;
|
332 | }
|
333 |
|
334 |
|
335 |
|
336 | return doneResult();
|
337 | }
|
338 |
|
339 | context.method = method;
|
340 | context.arg = arg;
|
341 |
|
342 | while (true) {
|
343 | var delegate = context.delegate;
|
344 | if (delegate) {
|
345 | var delegateResult = maybeInvokeDelegate(delegate, context);
|
346 | if (delegateResult) {
|
347 | if (delegateResult === ContinueSentinel) continue;
|
348 | return delegateResult;
|
349 | }
|
350 | }
|
351 |
|
352 | if (context.method === "next") {
|
353 |
|
354 |
|
355 | context.sent = context._sent = context.arg;
|
356 |
|
357 | } else if (context.method === "throw") {
|
358 | if (state === GenStateSuspendedStart) {
|
359 | state = GenStateCompleted;
|
360 | throw context.arg;
|
361 | }
|
362 |
|
363 | context.dispatchException(context.arg);
|
364 |
|
365 | } else if (context.method === "return") {
|
366 | context.abrupt("return", context.arg);
|
367 | }
|
368 |
|
369 | state = GenStateExecuting;
|
370 |
|
371 | var record = tryCatch(innerFn, self, context);
|
372 | if (record.type === "normal") {
|
373 |
|
374 |
|
375 | state = context.done
|
376 | ? GenStateCompleted
|
377 | : GenStateSuspendedYield;
|
378 |
|
379 | if (record.arg === ContinueSentinel) {
|
380 | continue;
|
381 | }
|
382 |
|
383 | return {
|
384 | value: record.arg,
|
385 | done: context.done
|
386 | };
|
387 |
|
388 | } else if (record.type === "throw") {
|
389 | state = GenStateCompleted;
|
390 |
|
391 |
|
392 | context.method = "throw";
|
393 | context.arg = record.arg;
|
394 | }
|
395 | }
|
396 | };
|
397 | }
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 | function maybeInvokeDelegate(delegate, context) {
|
404 | var method = delegate.iterator[context.method];
|
405 | if (method === undefined$1) {
|
406 |
|
407 |
|
408 | context.delegate = null;
|
409 |
|
410 | if (context.method === "throw") {
|
411 |
|
412 | if (delegate.iterator["return"]) {
|
413 |
|
414 |
|
415 | context.method = "return";
|
416 | context.arg = undefined$1;
|
417 | maybeInvokeDelegate(delegate, context);
|
418 |
|
419 | if (context.method === "throw") {
|
420 |
|
421 |
|
422 | return ContinueSentinel;
|
423 | }
|
424 | }
|
425 |
|
426 | context.method = "throw";
|
427 | context.arg = new TypeError(
|
428 | "The iterator does not provide a 'throw' method");
|
429 | }
|
430 |
|
431 | return ContinueSentinel;
|
432 | }
|
433 |
|
434 | var record = tryCatch(method, delegate.iterator, context.arg);
|
435 |
|
436 | if (record.type === "throw") {
|
437 | context.method = "throw";
|
438 | context.arg = record.arg;
|
439 | context.delegate = null;
|
440 | return ContinueSentinel;
|
441 | }
|
442 |
|
443 | var info = record.arg;
|
444 |
|
445 | if (! info) {
|
446 | context.method = "throw";
|
447 | context.arg = new TypeError("iterator result is not an object");
|
448 | context.delegate = null;
|
449 | return ContinueSentinel;
|
450 | }
|
451 |
|
452 | if (info.done) {
|
453 |
|
454 |
|
455 | context[delegate.resultName] = info.value;
|
456 |
|
457 |
|
458 | context.next = delegate.nextLoc;
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 | if (context.method !== "return") {
|
467 | context.method = "next";
|
468 | context.arg = undefined$1;
|
469 | }
|
470 |
|
471 | } else {
|
472 |
|
473 | return info;
|
474 | }
|
475 |
|
476 |
|
477 |
|
478 | context.delegate = null;
|
479 | return ContinueSentinel;
|
480 | }
|
481 |
|
482 |
|
483 |
|
484 | defineIteratorMethods(Gp);
|
485 |
|
486 | define(Gp, toStringTagSymbol, "Generator");
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 | Gp[iteratorSymbol] = function() {
|
494 | return this;
|
495 | };
|
496 |
|
497 | Gp.toString = function() {
|
498 | return "[object Generator]";
|
499 | };
|
500 |
|
501 | function pushTryEntry(locs) {
|
502 | var entry = { tryLoc: locs[0] };
|
503 |
|
504 | if (1 in locs) {
|
505 | entry.catchLoc = locs[1];
|
506 | }
|
507 |
|
508 | if (2 in locs) {
|
509 | entry.finallyLoc = locs[2];
|
510 | entry.afterLoc = locs[3];
|
511 | }
|
512 |
|
513 | this.tryEntries.push(entry);
|
514 | }
|
515 |
|
516 | function resetTryEntry(entry) {
|
517 | var record = entry.completion || {};
|
518 | record.type = "normal";
|
519 | delete record.arg;
|
520 | entry.completion = record;
|
521 | }
|
522 |
|
523 | function Context(tryLocsList) {
|
524 |
|
525 |
|
526 |
|
527 | this.tryEntries = [{ tryLoc: "root" }];
|
528 | tryLocsList.forEach(pushTryEntry, this);
|
529 | this.reset(true);
|
530 | }
|
531 |
|
532 | exports.keys = function(object) {
|
533 | var keys = [];
|
534 | for (var key in object) {
|
535 | keys.push(key);
|
536 | }
|
537 | keys.reverse();
|
538 |
|
539 |
|
540 |
|
541 | return function next() {
|
542 | while (keys.length) {
|
543 | var key = keys.pop();
|
544 | if (key in object) {
|
545 | next.value = key;
|
546 | next.done = false;
|
547 | return next;
|
548 | }
|
549 | }
|
550 |
|
551 |
|
552 |
|
553 |
|
554 | next.done = true;
|
555 | return next;
|
556 | };
|
557 | };
|
558 |
|
559 | function values(iterable) {
|
560 | if (iterable) {
|
561 | var iteratorMethod = iterable[iteratorSymbol];
|
562 | if (iteratorMethod) {
|
563 | return iteratorMethod.call(iterable);
|
564 | }
|
565 |
|
566 | if (typeof iterable.next === "function") {
|
567 | return iterable;
|
568 | }
|
569 |
|
570 | if (!isNaN(iterable.length)) {
|
571 | var i = -1, next = function next() {
|
572 | while (++i < iterable.length) {
|
573 | if (hasOwn.call(iterable, i)) {
|
574 | next.value = iterable[i];
|
575 | next.done = false;
|
576 | return next;
|
577 | }
|
578 | }
|
579 |
|
580 | next.value = undefined$1;
|
581 | next.done = true;
|
582 |
|
583 | return next;
|
584 | };
|
585 |
|
586 | return next.next = next;
|
587 | }
|
588 | }
|
589 |
|
590 |
|
591 | return { next: doneResult };
|
592 | }
|
593 | exports.values = values;
|
594 |
|
595 | function doneResult() {
|
596 | return { value: undefined$1, done: true };
|
597 | }
|
598 |
|
599 | Context.prototype = {
|
600 | constructor: Context,
|
601 |
|
602 | reset: function(skipTempReset) {
|
603 | this.prev = 0;
|
604 | this.next = 0;
|
605 |
|
606 |
|
607 | this.sent = this._sent = undefined$1;
|
608 | this.done = false;
|
609 | this.delegate = null;
|
610 |
|
611 | this.method = "next";
|
612 | this.arg = undefined$1;
|
613 |
|
614 | this.tryEntries.forEach(resetTryEntry);
|
615 |
|
616 | if (!skipTempReset) {
|
617 | for (var name in this) {
|
618 |
|
619 | if (name.charAt(0) === "t" &&
|
620 | hasOwn.call(this, name) &&
|
621 | !isNaN(+name.slice(1))) {
|
622 | this[name] = undefined$1;
|
623 | }
|
624 | }
|
625 | }
|
626 | },
|
627 |
|
628 | stop: function() {
|
629 | this.done = true;
|
630 |
|
631 | var rootEntry = this.tryEntries[0];
|
632 | var rootRecord = rootEntry.completion;
|
633 | if (rootRecord.type === "throw") {
|
634 | throw rootRecord.arg;
|
635 | }
|
636 |
|
637 | return this.rval;
|
638 | },
|
639 |
|
640 | dispatchException: function(exception) {
|
641 | if (this.done) {
|
642 | throw exception;
|
643 | }
|
644 |
|
645 | var context = this;
|
646 | function handle(loc, caught) {
|
647 | record.type = "throw";
|
648 | record.arg = exception;
|
649 | context.next = loc;
|
650 |
|
651 | if (caught) {
|
652 |
|
653 |
|
654 | context.method = "next";
|
655 | context.arg = undefined$1;
|
656 | }
|
657 |
|
658 | return !! caught;
|
659 | }
|
660 |
|
661 | for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
662 | var entry = this.tryEntries[i];
|
663 | var record = entry.completion;
|
664 |
|
665 | if (entry.tryLoc === "root") {
|
666 |
|
667 |
|
668 |
|
669 | return handle("end");
|
670 | }
|
671 |
|
672 | if (entry.tryLoc <= this.prev) {
|
673 | var hasCatch = hasOwn.call(entry, "catchLoc");
|
674 | var hasFinally = hasOwn.call(entry, "finallyLoc");
|
675 |
|
676 | if (hasCatch && hasFinally) {
|
677 | if (this.prev < entry.catchLoc) {
|
678 | return handle(entry.catchLoc, true);
|
679 | } else if (this.prev < entry.finallyLoc) {
|
680 | return handle(entry.finallyLoc);
|
681 | }
|
682 |
|
683 | } else if (hasCatch) {
|
684 | if (this.prev < entry.catchLoc) {
|
685 | return handle(entry.catchLoc, true);
|
686 | }
|
687 |
|
688 | } else if (hasFinally) {
|
689 | if (this.prev < entry.finallyLoc) {
|
690 | return handle(entry.finallyLoc);
|
691 | }
|
692 |
|
693 | } else {
|
694 | throw new Error("try statement without catch or finally");
|
695 | }
|
696 | }
|
697 | }
|
698 | },
|
699 |
|
700 | abrupt: function(type, arg) {
|
701 | for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
702 | var entry = this.tryEntries[i];
|
703 | if (entry.tryLoc <= this.prev &&
|
704 | hasOwn.call(entry, "finallyLoc") &&
|
705 | this.prev < entry.finallyLoc) {
|
706 | var finallyEntry = entry;
|
707 | break;
|
708 | }
|
709 | }
|
710 |
|
711 | if (finallyEntry &&
|
712 | (type === "break" ||
|
713 | type === "continue") &&
|
714 | finallyEntry.tryLoc <= arg &&
|
715 | arg <= finallyEntry.finallyLoc) {
|
716 |
|
717 |
|
718 | finallyEntry = null;
|
719 | }
|
720 |
|
721 | var record = finallyEntry ? finallyEntry.completion : {};
|
722 | record.type = type;
|
723 | record.arg = arg;
|
724 |
|
725 | if (finallyEntry) {
|
726 | this.method = "next";
|
727 | this.next = finallyEntry.finallyLoc;
|
728 | return ContinueSentinel;
|
729 | }
|
730 |
|
731 | return this.complete(record);
|
732 | },
|
733 |
|
734 | complete: function(record, afterLoc) {
|
735 | if (record.type === "throw") {
|
736 | throw record.arg;
|
737 | }
|
738 |
|
739 | if (record.type === "break" ||
|
740 | record.type === "continue") {
|
741 | this.next = record.arg;
|
742 | } else if (record.type === "return") {
|
743 | this.rval = this.arg = record.arg;
|
744 | this.method = "return";
|
745 | this.next = "end";
|
746 | } else if (record.type === "normal" && afterLoc) {
|
747 | this.next = afterLoc;
|
748 | }
|
749 |
|
750 | return ContinueSentinel;
|
751 | },
|
752 |
|
753 | finish: function(finallyLoc) {
|
754 | for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
755 | var entry = this.tryEntries[i];
|
756 | if (entry.finallyLoc === finallyLoc) {
|
757 | this.complete(entry.completion, entry.afterLoc);
|
758 | resetTryEntry(entry);
|
759 | return ContinueSentinel;
|
760 | }
|
761 | }
|
762 | },
|
763 |
|
764 | "catch": function(tryLoc) {
|
765 | for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
766 | var entry = this.tryEntries[i];
|
767 | if (entry.tryLoc === tryLoc) {
|
768 | var record = entry.completion;
|
769 | if (record.type === "throw") {
|
770 | var thrown = record.arg;
|
771 | resetTryEntry(entry);
|
772 | }
|
773 | return thrown;
|
774 | }
|
775 | }
|
776 |
|
777 |
|
778 |
|
779 | throw new Error("illegal catch attempt");
|
780 | },
|
781 |
|
782 | delegateYield: function(iterable, resultName, nextLoc) {
|
783 | this.delegate = {
|
784 | iterator: values(iterable),
|
785 | resultName: resultName,
|
786 | nextLoc: nextLoc
|
787 | };
|
788 |
|
789 | if (this.method === "next") {
|
790 |
|
791 |
|
792 | this.arg = undefined$1;
|
793 | }
|
794 |
|
795 | return ContinueSentinel;
|
796 | }
|
797 | };
|
798 |
|
799 |
|
800 |
|
801 |
|
802 |
|
803 | return exports;
|
804 |
|
805 | }(
|
806 |
|
807 |
|
808 |
|
809 |
|
810 | module.exports
|
811 | ));
|
812 |
|
813 | try {
|
814 | regeneratorRuntime = runtime;
|
815 | } catch (accidentalStrictMode) {
|
816 |
|
817 |
|
818 |
|
819 |
|
820 |
|
821 |
|
822 |
|
823 |
|
824 |
|
825 | Function("r", "regeneratorRuntime = r")(runtime);
|
826 | }
|
827 | });
|
828 |
|
829 | var HttpRequestErrorHandler = function () {
|
830 | function HttpRequestErrorHandler(logger, httpRequestErrorService, strategy) {
|
831 | |
832 |
|
833 |
|
834 |
|
835 |
|
836 | this.noThrowStrategies = ['reject', 'silent'];
|
837 | this.logger = logger;
|
838 | this.httpRequestErrorService = httpRequestErrorService;
|
839 | this.strategy = strategy;
|
840 | }
|
841 | |
842 |
|
843 |
|
844 |
|
845 |
|
846 |
|
847 |
|
848 |
|
849 |
|
850 | var _proto = HttpRequestErrorHandler.prototype;
|
851 |
|
852 | _proto.process = function process(error) {
|
853 | if (this.logger && this.logger.warn) {
|
854 | this.logger.warn('API ERROR', error);
|
855 | }
|
856 |
|
857 | var errorContext = error;
|
858 |
|
859 | if (typeof error === 'string') {
|
860 | errorContext = new Error(error);
|
861 | }
|
862 |
|
863 | if (this.httpRequestErrorService) {
|
864 | if (typeof this.httpRequestErrorService.process !== 'undefined') {
|
865 | this.httpRequestErrorService.process(errorContext);
|
866 | } else if (typeof this.httpRequestErrorService === 'function') {
|
867 | this.httpRequestErrorService(errorContext);
|
868 | }
|
869 | }
|
870 |
|
871 | if (!this.noThrowStrategies.includes(this.strategy)) {
|
872 | throw errorContext;
|
873 | }
|
874 | };
|
875 |
|
876 | return HttpRequestErrorHandler;
|
877 | }();
|
878 |
|
879 |
|
880 |
|
881 |
|
882 |
|
883 |
|
884 |
|
885 | var HttpRequestHandler = function () {
|
886 | |
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 | function HttpRequestHandler(_ref) {
|
899 | var _ref$baseURL = _ref.baseURL,
|
900 | baseURL = _ref$baseURL === void 0 ? '' : _ref$baseURL,
|
901 | _ref$timeout = _ref.timeout,
|
902 | timeout = _ref$timeout === void 0 ? null : _ref$timeout,
|
903 | _ref$strategy = _ref.strategy,
|
904 | strategy = _ref$strategy === void 0 ? null : _ref$strategy,
|
905 | _ref$flattenResponse = _ref.flattenResponse,
|
906 | flattenResponse = _ref$flattenResponse === void 0 ? null : _ref$flattenResponse,
|
907 | _ref$logger = _ref.logger,
|
908 | logger = _ref$logger === void 0 ? null : _ref$logger,
|
909 | _ref$httpRequestError = _ref.httpRequestErrorService,
|
910 | httpRequestErrorService = _ref$httpRequestError === void 0 ? null : _ref$httpRequestError,
|
911 | config = _objectWithoutPropertiesLoose(_ref, ["baseURL", "timeout", "strategy", "flattenResponse", "logger", "httpRequestErrorService"]);
|
912 |
|
913 | |
914 |
|
915 |
|
916 |
|
917 |
|
918 | this.timeout = 30000;
|
919 | |
920 |
|
921 |
|
922 |
|
923 |
|
924 |
|
925 | this.strategy = 'silent';
|
926 | |
927 |
|
928 |
|
929 |
|
930 |
|
931 |
|
932 | this.flattenResponse = true;
|
933 | this.timeout = timeout !== null ? timeout : this.timeout;
|
934 | this.strategy = strategy !== null ? strategy : this.strategy;
|
935 | this.flattenResponse = flattenResponse !== null ? flattenResponse : this.flattenResponse;
|
936 | this.logger = logger || global.console || window.console || null;
|
937 | this.httpRequestErrorService = httpRequestErrorService;
|
938 | this.requestInstance = axios.create(_extends({}, config, {
|
939 | baseURL: baseURL,
|
940 | timeout: this.timeout
|
941 | }));
|
942 | }
|
943 | |
944 |
|
945 |
|
946 |
|
947 |
|
948 |
|
949 |
|
950 |
|
951 | var _proto = HttpRequestHandler.prototype;
|
952 |
|
953 | _proto.getInstance = function getInstance() {
|
954 | return this.requestInstance;
|
955 | }
|
956 | |
957 |
|
958 |
|
959 |
|
960 |
|
961 |
|
962 |
|
963 | ;
|
964 |
|
965 | _proto.interceptRequest = function interceptRequest(callback) {
|
966 | this.getInstance().interceptors.request.use(callback);
|
967 | }
|
968 | |
969 |
|
970 |
|
971 |
|
972 |
|
973 |
|
974 |
|
975 |
|
976 |
|
977 |
|
978 | ;
|
979 |
|
980 | _proto.post = function post(url, data, config) {
|
981 | if (data === void 0) {
|
982 | data = null;
|
983 | }
|
984 |
|
985 | if (config === void 0) {
|
986 | config = null;
|
987 | }
|
988 |
|
989 | return this.handleRequest({
|
990 | type: 'post',
|
991 | url: url,
|
992 | data: data,
|
993 | config: config
|
994 | });
|
995 | }
|
996 | |
997 |
|
998 |
|
999 |
|
1000 |
|
1001 |
|
1002 |
|
1003 |
|
1004 |
|
1005 |
|
1006 | ;
|
1007 |
|
1008 | _proto.get = function get(url, data, config) {
|
1009 | if (data === void 0) {
|
1010 | data = null;
|
1011 | }
|
1012 |
|
1013 | if (config === void 0) {
|
1014 | config = null;
|
1015 | }
|
1016 |
|
1017 | return this.handleRequest({
|
1018 | type: 'get',
|
1019 | url: url,
|
1020 | data: data,
|
1021 | config: config
|
1022 | });
|
1023 | }
|
1024 | |
1025 |
|
1026 |
|
1027 |
|
1028 |
|
1029 |
|
1030 |
|
1031 |
|
1032 |
|
1033 |
|
1034 | ;
|
1035 |
|
1036 | _proto.put = function put(url, data, config) {
|
1037 | if (data === void 0) {
|
1038 | data = null;
|
1039 | }
|
1040 |
|
1041 | if (config === void 0) {
|
1042 | config = null;
|
1043 | }
|
1044 |
|
1045 | return this.handleRequest({
|
1046 | type: 'put',
|
1047 | url: url,
|
1048 | data: data,
|
1049 | config: config
|
1050 | });
|
1051 | }
|
1052 | |
1053 |
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 |
|
1060 |
|
1061 |
|
1062 | ;
|
1063 |
|
1064 | _proto["delete"] = function _delete(url, data, config) {
|
1065 | if (data === void 0) {
|
1066 | data = null;
|
1067 | }
|
1068 |
|
1069 | if (config === void 0) {
|
1070 | config = null;
|
1071 | }
|
1072 |
|
1073 | return this.handleRequest({
|
1074 | type: 'delete',
|
1075 | url: url,
|
1076 | data: data,
|
1077 | config: config
|
1078 | });
|
1079 | }
|
1080 | |
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 |
|
1086 |
|
1087 |
|
1088 |
|
1089 |
|
1090 | ;
|
1091 |
|
1092 | _proto.patch = function patch(url, data, config) {
|
1093 | if (data === void 0) {
|
1094 | data = null;
|
1095 | }
|
1096 |
|
1097 | if (config === void 0) {
|
1098 | config = null;
|
1099 | }
|
1100 |
|
1101 | return this.handleRequest({
|
1102 | type: 'patch',
|
1103 | url: url,
|
1104 | data: data,
|
1105 | config: config
|
1106 | });
|
1107 | }
|
1108 | |
1109 |
|
1110 |
|
1111 |
|
1112 |
|
1113 |
|
1114 |
|
1115 |
|
1116 |
|
1117 |
|
1118 | ;
|
1119 |
|
1120 | _proto.head = function head(url, data, config) {
|
1121 | if (data === void 0) {
|
1122 | data = null;
|
1123 | }
|
1124 |
|
1125 | if (config === void 0) {
|
1126 | config = null;
|
1127 | }
|
1128 |
|
1129 | return this.handleRequest({
|
1130 | type: 'head',
|
1131 | url: url,
|
1132 | data: data,
|
1133 | config: config
|
1134 | });
|
1135 | }
|
1136 | |
1137 |
|
1138 |
|
1139 |
|
1140 |
|
1141 |
|
1142 |
|
1143 | ;
|
1144 |
|
1145 | _proto.processRequestError = function processRequestError(err) {
|
1146 | return new HttpRequestErrorHandler(this.logger, this.httpRequestErrorService, this.strategy).process(err);
|
1147 | }
|
1148 | |
1149 |
|
1150 |
|
1151 |
|
1152 |
|
1153 |
|
1154 |
|
1155 |
|
1156 |
|
1157 |
|
1158 |
|
1159 |
|
1160 | ;
|
1161 |
|
1162 | _proto.handleRequest =
|
1163 |
|
1164 | function () {
|
1165 | var _handleRequest = _asyncToGenerator( runtime_1.mark(function _callee(_ref2) {
|
1166 | var _extends2;
|
1167 |
|
1168 | var type, url, _ref2$data, data, _ref2$config, config, response, requestConfig, key;
|
1169 |
|
1170 | return runtime_1.wrap(function _callee$(_context) {
|
1171 | while (1) {
|
1172 | switch (_context.prev = _context.next) {
|
1173 | case 0:
|
1174 | type = _ref2.type, url = _ref2.url, _ref2$data = _ref2.data, data = _ref2$data === void 0 ? null : _ref2$data, _ref2$config = _ref2.config, config = _ref2$config === void 0 ? null : _ref2$config;
|
1175 | response = null;
|
1176 | requestConfig = config || {};
|
1177 | key = type === 'get' || type === 'head' ? 'params' : 'data';
|
1178 | requestConfig = _extends({}, requestConfig, (_extends2 = {
|
1179 | url: url,
|
1180 | method: type
|
1181 | }, _extends2[key] = data || {}, _extends2));
|
1182 | _context.t0 = this.strategy;
|
1183 | _context.next = _context.t0 === 'silent' ? 8 : _context.t0 === 'reject' ? 22 : _context.t0 === 'throwError' ? 33 : 33;
|
1184 | break;
|
1185 |
|
1186 | case 8:
|
1187 | _context.prev = 8;
|
1188 | _context.next = 11;
|
1189 | return this.requestInstance.request(requestConfig);
|
1190 |
|
1191 | case 11:
|
1192 | response = _context.sent;
|
1193 | _context.next = 21;
|
1194 | break;
|
1195 |
|
1196 | case 14:
|
1197 | _context.prev = 14;
|
1198 | _context.t1 = _context["catch"](8);
|
1199 | this.processRequestError(_context.t1);
|
1200 | _context.next = 19;
|
1201 | return new Promise(function () {
|
1202 | return null;
|
1203 | });
|
1204 |
|
1205 | case 19:
|
1206 | response = _context.sent;
|
1207 | return _context.abrupt("return", response);
|
1208 |
|
1209 | case 21:
|
1210 | return _context.abrupt("break", 36);
|
1211 |
|
1212 | case 22:
|
1213 | _context.prev = 22;
|
1214 | _context.next = 25;
|
1215 | return this.requestInstance.request(requestConfig);
|
1216 |
|
1217 | case 25:
|
1218 | response = _context.sent;
|
1219 | _context.next = 32;
|
1220 | break;
|
1221 |
|
1222 | case 28:
|
1223 | _context.prev = 28;
|
1224 | _context.t2 = _context["catch"](22);
|
1225 | this.processRequestError(_context.t2);
|
1226 | return _context.abrupt("return", Promise.reject(_context.t2));
|
1227 |
|
1228 | case 32:
|
1229 | return _context.abrupt("break", 36);
|
1230 |
|
1231 | case 33:
|
1232 | _context.next = 35;
|
1233 | return this.requestInstance.request(requestConfig);
|
1234 |
|
1235 | case 35:
|
1236 | response = _context.sent;
|
1237 |
|
1238 | case 36:
|
1239 | return _context.abrupt("return", this.processResponseData(response));
|
1240 |
|
1241 | case 37:
|
1242 | case "end":
|
1243 | return _context.stop();
|
1244 | }
|
1245 | }
|
1246 | }, _callee, this, [[8, 14], [22, 28]]);
|
1247 | }));
|
1248 |
|
1249 | function handleRequest(_x) {
|
1250 | return _handleRequest.apply(this, arguments);
|
1251 | }
|
1252 |
|
1253 | return handleRequest;
|
1254 | }()
|
1255 | ;
|
1256 |
|
1257 | _proto.processResponseData = function processResponseData(response) {
|
1258 | if (response.data) {
|
1259 | if (!this.flattenResponse) {
|
1260 | return response;
|
1261 | }
|
1262 |
|
1263 |
|
1264 |
|
1265 |
|
1266 | if (typeof response.data === 'object' && response.data.data && Object.keys(response.data).length === 1) {
|
1267 | return response.data.data;
|
1268 | }
|
1269 |
|
1270 | return response.data;
|
1271 | }
|
1272 |
|
1273 | return null;
|
1274 | };
|
1275 |
|
1276 | return HttpRequestHandler;
|
1277 | }();
|
1278 |
|
1279 | HttpRequestHandler = __decorate([CatchAll(function (err, ctx) {
|
1280 | return ctx.processRequestError(err);
|
1281 | })], HttpRequestHandler);
|
1282 |
|
1283 |
|
1284 |
|
1285 |
|
1286 |
|
1287 | var ApiHandler = function () {
|
1288 | |
1289 |
|
1290 |
|
1291 |
|
1292 |
|
1293 |
|
1294 |
|
1295 |
|
1296 |
|
1297 |
|
1298 |
|
1299 |
|
1300 | function ApiHandler(_ref) {
|
1301 | var apiUrl = _ref.apiUrl,
|
1302 | apiEndpoints = _ref.apiEndpoints,
|
1303 | _ref$timeout = _ref.timeout,
|
1304 | timeout = _ref$timeout === void 0 ? null : _ref$timeout,
|
1305 | _ref$strategy = _ref.strategy,
|
1306 | strategy = _ref$strategy === void 0 ? null : _ref$strategy,
|
1307 | _ref$flattenResponse = _ref.flattenResponse,
|
1308 | flattenResponse = _ref$flattenResponse === void 0 ? null : _ref$flattenResponse,
|
1309 | _ref$logger = _ref.logger,
|
1310 | logger = _ref$logger === void 0 ? null : _ref$logger,
|
1311 | _ref$httpRequestError = _ref.httpRequestErrorService,
|
1312 | httpRequestErrorService = _ref$httpRequestError === void 0 ? null : _ref$httpRequestError,
|
1313 | config = _objectWithoutPropertiesLoose(_ref, ["apiUrl", "apiEndpoints", "timeout", "strategy", "flattenResponse", "logger", "httpRequestErrorService"]);
|
1314 |
|
1315 | |
1316 |
|
1317 |
|
1318 |
|
1319 |
|
1320 | this.apiUrl = '';
|
1321 | this.apiUrl = apiUrl;
|
1322 | this.apiEndpoints = apiEndpoints;
|
1323 | this.logger = logger;
|
1324 | this.httpRequestHandler = new HttpRequestHandler(_extends({}, config, {
|
1325 | baseURL: this.apiUrl,
|
1326 | timeout: timeout,
|
1327 | strategy: strategy,
|
1328 | flattenResponse: flattenResponse,
|
1329 | logger: logger,
|
1330 | httpRequestErrorService: httpRequestErrorService
|
1331 | }));
|
1332 | }
|
1333 | |
1334 |
|
1335 |
|
1336 |
|
1337 |
|
1338 |
|
1339 |
|
1340 |
|
1341 | var _proto = ApiHandler.prototype;
|
1342 |
|
1343 | _proto.getInstance = function getInstance() {
|
1344 | return this.httpRequestHandler.getInstance();
|
1345 | }
|
1346 | |
1347 |
|
1348 |
|
1349 |
|
1350 |
|
1351 |
|
1352 |
|
1353 | ;
|
1354 |
|
1355 | _proto.__get = function __get(prop) {
|
1356 | if (prop in this) {
|
1357 | return this[prop];
|
1358 | }
|
1359 |
|
1360 |
|
1361 | if (!this.apiEndpoints[prop]) {
|
1362 | return this.handleNonImplemented.bind(this, prop);
|
1363 | }
|
1364 |
|
1365 | return this.handleRequest.bind(this, prop);
|
1366 | }
|
1367 | |
1368 |
|
1369 |
|
1370 |
|
1371 |
|
1372 |
|
1373 |
|
1374 | ;
|
1375 |
|
1376 | _proto.handleRequest =
|
1377 |
|
1378 | function () {
|
1379 | var _handleRequest = _asyncToGenerator( runtime_1.mark(function _callee() {
|
1380 | var prop,
|
1381 | api,
|
1382 | queryParams,
|
1383 | uriParams,
|
1384 | requestConfig,
|
1385 | uri,
|
1386 | requestData,
|
1387 | responseData,
|
1388 | _args = arguments;
|
1389 | return runtime_1.wrap(function _callee$(_context) {
|
1390 | while (1) {
|
1391 | switch (_context.prev = _context.next) {
|
1392 | case 0:
|
1393 | prop = _args.length <= 0 ? undefined : _args[0];
|
1394 | api = this.apiEndpoints[prop];
|
1395 | queryParams = (_args.length <= 1 ? undefined : _args[1]) || {};
|
1396 | uriParams = (_args.length <= 2 ? undefined : _args[2]) || {};
|
1397 | requestConfig = (_args.length <= 3 ? undefined : _args[3]) || {};
|
1398 | uri = api.url.replace(/:[a-z]+/ig, function (str) {
|
1399 | return uriParams[str.substr(1)] ? uriParams[str.substr(1)] : str;
|
1400 | });
|
1401 | requestData = _extends({}, queryParams);
|
1402 | responseData = null;
|
1403 | _context.next = 10;
|
1404 | return this.httpRequestHandler[api.method](uri, requestData, requestConfig);
|
1405 |
|
1406 | case 10:
|
1407 | responseData = _context.sent;
|
1408 | return _context.abrupt("return", responseData);
|
1409 |
|
1410 | case 12:
|
1411 | case "end":
|
1412 | return _context.stop();
|
1413 | }
|
1414 | }
|
1415 | }, _callee, this);
|
1416 | }));
|
1417 |
|
1418 | function handleRequest() {
|
1419 | return _handleRequest.apply(this, arguments);
|
1420 | }
|
1421 |
|
1422 | return handleRequest;
|
1423 | }()
|
1424 | |
1425 |
|
1426 |
|
1427 |
|
1428 |
|
1429 |
|
1430 | ;
|
1431 |
|
1432 | _proto.handleNonImplemented = function handleNonImplemented(prop) {
|
1433 | if (this.logger && this.logger.log) {
|
1434 | this.logger.log(prop + " endpoint not implemented.");
|
1435 | }
|
1436 |
|
1437 | return Promise.resolve(null);
|
1438 | };
|
1439 |
|
1440 | return ApiHandler;
|
1441 | }();
|
1442 |
|
1443 | ApiHandler = __decorate([applyMagic], ApiHandler);
|
1444 | var createApiFetcher = function createApiFetcher(options) {
|
1445 | return new ApiHandler(options);
|
1446 | };
|
1447 |
|
1448 | export { ApiHandler, HttpRequestErrorHandler, HttpRequestHandler, createApiFetcher };
|
1449 |
|