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