UNPKG

@putdotio/pas-js

Version:

Client-side JS client for Putio Analytics System

1,454 lines (1,332 loc) 54.2 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } var queryString = _interopDefault(require('query-string')); var rxjs = require('rxjs'); var Cookies = _interopDefault(require('js-cookie')); /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ var __assign = function() { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __spreadArrays() { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; } var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; function unwrapExports (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } function createCommonjsModule(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } var root = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); var __window = typeof window !== 'undefined' && window; var __self = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope && self; var __global = typeof commonjsGlobal !== 'undefined' && commonjsGlobal; var _root = __window || __global || __self; exports.root = _root; (function () { if (!_root) { throw new Error('RxJS could not find any global context (window, self, global)'); } })(); }); unwrapExports(root); var root_1 = root.root; var isFunction_1 = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); function isFunction(x) { return typeof x === 'function'; } exports.isFunction = isFunction; }); unwrapExports(isFunction_1); var isFunction_2 = isFunction_1.isFunction; var config = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); var _enable_super_gross_mode_that_will_cause_bad_things = false; exports.config = { Promise: undefined, set useDeprecatedSynchronousErrorHandling(value) { if (value) { var error = new Error(); console.warn('DEPRECATED! RxJS was set to use deprecated synchronous error handling behavior by code at: \n' + error.stack); } else if (_enable_super_gross_mode_that_will_cause_bad_things) { console.log('RxJS: Back to a better error behavior. Thank you. <3'); } _enable_super_gross_mode_that_will_cause_bad_things = value; }, get useDeprecatedSynchronousErrorHandling() { return _enable_super_gross_mode_that_will_cause_bad_things; }, }; }); unwrapExports(config); var config_1 = config.config; var hostReportError_1 = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); function hostReportError(err) { setTimeout(function () { throw err; }, 0); } exports.hostReportError = hostReportError; }); unwrapExports(hostReportError_1); var hostReportError_2 = hostReportError_1.hostReportError; var Observer = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); exports.empty = { closed: true, next: function (value) { }, error: function (err) { if (config.config.useDeprecatedSynchronousErrorHandling) { throw err; } else { hostReportError_1.hostReportError(err); } }, complete: function () { } }; }); unwrapExports(Observer); var Observer_1 = Observer.empty; var isArray = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); exports.isArray = (function () { return Array.isArray || (function (x) { return x && typeof x.length === 'number'; }); })(); }); unwrapExports(isArray); var isArray_1 = isArray.isArray; var isObject_1 = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); function isObject(x) { return x !== null && typeof x === 'object'; } exports.isObject = isObject; }); unwrapExports(isObject_1); var isObject_2 = isObject_1.isObject; var UnsubscriptionError = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); var UnsubscriptionErrorImpl = (function () { function UnsubscriptionErrorImpl(errors) { Error.call(this); this.message = errors ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ') : ''; this.name = 'UnsubscriptionError'; this.errors = errors; return this; } UnsubscriptionErrorImpl.prototype = Object.create(Error.prototype); return UnsubscriptionErrorImpl; })(); exports.UnsubscriptionError = UnsubscriptionErrorImpl; }); unwrapExports(UnsubscriptionError); var UnsubscriptionError_1 = UnsubscriptionError.UnsubscriptionError; var Subscription_1 = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); var Subscription = (function () { function Subscription(unsubscribe) { this.closed = false; this._parentOrParents = null; this._subscriptions = null; if (unsubscribe) { this._unsubscribe = unsubscribe; } } Subscription.prototype.unsubscribe = function () { var errors; if (this.closed) { return; } var _a = this, _parentOrParents = _a._parentOrParents, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions; this.closed = true; this._parentOrParents = null; this._subscriptions = null; if (_parentOrParents instanceof Subscription) { _parentOrParents.remove(this); } else if (_parentOrParents !== null) { for (var index = 0; index < _parentOrParents.length; ++index) { var parent_1 = _parentOrParents[index]; parent_1.remove(this); } } if (isFunction_1.isFunction(_unsubscribe)) { try { _unsubscribe.call(this); } catch (e) { errors = e instanceof UnsubscriptionError.UnsubscriptionError ? flattenUnsubscriptionErrors(e.errors) : [e]; } } if (isArray.isArray(_subscriptions)) { var index = -1; var len = _subscriptions.length; while (++index < len) { var sub = _subscriptions[index]; if (isObject_1.isObject(sub)) { try { sub.unsubscribe(); } catch (e) { errors = errors || []; if (e instanceof UnsubscriptionError.UnsubscriptionError) { errors = errors.concat(flattenUnsubscriptionErrors(e.errors)); } else { errors.push(e); } } } } } if (errors) { throw new UnsubscriptionError.UnsubscriptionError(errors); } }; Subscription.prototype.add = function (teardown) { var subscription = teardown; if (!teardown) { return Subscription.EMPTY; } switch (typeof teardown) { case 'function': subscription = new Subscription(teardown); case 'object': if (subscription === this || subscription.closed || typeof subscription.unsubscribe !== 'function') { return subscription; } else if (this.closed) { subscription.unsubscribe(); return subscription; } else if (!(subscription instanceof Subscription)) { var tmp = subscription; subscription = new Subscription(); subscription._subscriptions = [tmp]; } break; default: { throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.'); } } var _parentOrParents = subscription._parentOrParents; if (_parentOrParents === null) { subscription._parentOrParents = this; } else if (_parentOrParents instanceof Subscription) { if (_parentOrParents === this) { return subscription; } subscription._parentOrParents = [_parentOrParents, this]; } else if (_parentOrParents.indexOf(this) === -1) { _parentOrParents.push(this); } else { return subscription; } var subscriptions = this._subscriptions; if (subscriptions === null) { this._subscriptions = [subscription]; } else { subscriptions.push(subscription); } return subscription; }; Subscription.prototype.remove = function (subscription) { var subscriptions = this._subscriptions; if (subscriptions) { var subscriptionIndex = subscriptions.indexOf(subscription); if (subscriptionIndex !== -1) { subscriptions.splice(subscriptionIndex, 1); } } }; Subscription.EMPTY = (function (empty) { empty.closed = true; return empty; }(new Subscription())); return Subscription; }()); exports.Subscription = Subscription; function flattenUnsubscriptionErrors(errors) { return errors.reduce(function (errs, err) { return errs.concat((err instanceof UnsubscriptionError.UnsubscriptionError) ? err.errors : err); }, []); } }); unwrapExports(Subscription_1); var Subscription_2 = Subscription_1.Subscription; var rxSubscriber = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); exports.rxSubscriber = (function () { return typeof Symbol === 'function' ? Symbol('rxSubscriber') : '@@rxSubscriber_' + Math.random(); })(); exports.$$rxSubscriber = exports.rxSubscriber; }); unwrapExports(rxSubscriber); var rxSubscriber_1 = rxSubscriber.rxSubscriber; var rxSubscriber_2 = rxSubscriber.$$rxSubscriber; var Subscriber_1 = createCommonjsModule(function (module, exports) { var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var Subscriber = (function (_super) { __extends(Subscriber, _super); function Subscriber(destinationOrNext, error, complete) { var _this = _super.call(this) || this; _this.syncErrorValue = null; _this.syncErrorThrown = false; _this.syncErrorThrowable = false; _this.isStopped = false; switch (arguments.length) { case 0: _this.destination = Observer.empty; break; case 1: if (!destinationOrNext) { _this.destination = Observer.empty; break; } if (typeof destinationOrNext === 'object') { if (destinationOrNext instanceof Subscriber) { _this.syncErrorThrowable = destinationOrNext.syncErrorThrowable; _this.destination = destinationOrNext; destinationOrNext.add(_this); } else { _this.syncErrorThrowable = true; _this.destination = new SafeSubscriber(_this, destinationOrNext); } break; } default: _this.syncErrorThrowable = true; _this.destination = new SafeSubscriber(_this, destinationOrNext, error, complete); break; } return _this; } Subscriber.prototype[rxSubscriber.rxSubscriber] = function () { return this; }; Subscriber.create = function (next, error, complete) { var subscriber = new Subscriber(next, error, complete); subscriber.syncErrorThrowable = false; return subscriber; }; Subscriber.prototype.next = function (value) { if (!this.isStopped) { this._next(value); } }; Subscriber.prototype.error = function (err) { if (!this.isStopped) { this.isStopped = true; this._error(err); } }; Subscriber.prototype.complete = function () { if (!this.isStopped) { this.isStopped = true; this._complete(); } }; Subscriber.prototype.unsubscribe = function () { if (this.closed) { return; } this.isStopped = true; _super.prototype.unsubscribe.call(this); }; Subscriber.prototype._next = function (value) { this.destination.next(value); }; Subscriber.prototype._error = function (err) { this.destination.error(err); this.unsubscribe(); }; Subscriber.prototype._complete = function () { this.destination.complete(); this.unsubscribe(); }; Subscriber.prototype._unsubscribeAndRecycle = function () { var _parentOrParents = this._parentOrParents; this._parentOrParents = null; this.unsubscribe(); this.closed = false; this.isStopped = false; this._parentOrParents = _parentOrParents; return this; }; return Subscriber; }(Subscription_1.Subscription)); exports.Subscriber = Subscriber; var SafeSubscriber = (function (_super) { __extends(SafeSubscriber, _super); function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) { var _this = _super.call(this) || this; _this._parentSubscriber = _parentSubscriber; var next; var context = _this; if (isFunction_1.isFunction(observerOrNext)) { next = observerOrNext; } else if (observerOrNext) { next = observerOrNext.next; error = observerOrNext.error; complete = observerOrNext.complete; if (observerOrNext !== Observer.empty) { context = Object.create(observerOrNext); if (isFunction_1.isFunction(context.unsubscribe)) { _this.add(context.unsubscribe.bind(context)); } context.unsubscribe = _this.unsubscribe.bind(_this); } } _this._context = context; _this._next = next; _this._error = error; _this._complete = complete; return _this; } SafeSubscriber.prototype.next = function (value) { if (!this.isStopped && this._next) { var _parentSubscriber = this._parentSubscriber; if (!config.config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) { this.__tryOrUnsub(this._next, value); } else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) { this.unsubscribe(); } } }; SafeSubscriber.prototype.error = function (err) { if (!this.isStopped) { var _parentSubscriber = this._parentSubscriber; var useDeprecatedSynchronousErrorHandling = config.config.useDeprecatedSynchronousErrorHandling; if (this._error) { if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) { this.__tryOrUnsub(this._error, err); this.unsubscribe(); } else { this.__tryOrSetError(_parentSubscriber, this._error, err); this.unsubscribe(); } } else if (!_parentSubscriber.syncErrorThrowable) { this.unsubscribe(); if (useDeprecatedSynchronousErrorHandling) { throw err; } hostReportError_1.hostReportError(err); } else { if (useDeprecatedSynchronousErrorHandling) { _parentSubscriber.syncErrorValue = err; _parentSubscriber.syncErrorThrown = true; } else { hostReportError_1.hostReportError(err); } this.unsubscribe(); } } }; SafeSubscriber.prototype.complete = function () { var _this = this; if (!this.isStopped) { var _parentSubscriber = this._parentSubscriber; if (this._complete) { var wrappedComplete = function () { return _this._complete.call(_this._context); }; if (!config.config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) { this.__tryOrUnsub(wrappedComplete); this.unsubscribe(); } else { this.__tryOrSetError(_parentSubscriber, wrappedComplete); this.unsubscribe(); } } else { this.unsubscribe(); } } }; SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) { try { fn.call(this._context, value); } catch (err) { this.unsubscribe(); if (config.config.useDeprecatedSynchronousErrorHandling) { throw err; } else { hostReportError_1.hostReportError(err); } } }; SafeSubscriber.prototype.__tryOrSetError = function (parent, fn, value) { if (!config.config.useDeprecatedSynchronousErrorHandling) { throw new Error('bad call'); } try { fn.call(this._context, value); } catch (err) { if (config.config.useDeprecatedSynchronousErrorHandling) { parent.syncErrorValue = err; parent.syncErrorThrown = true; return true; } else { hostReportError_1.hostReportError(err); return true; } } return false; }; SafeSubscriber.prototype._unsubscribe = function () { var _parentSubscriber = this._parentSubscriber; this._context = null; this._parentSubscriber = null; _parentSubscriber.unsubscribe(); }; return SafeSubscriber; }(Subscriber)); exports.SafeSubscriber = SafeSubscriber; }); unwrapExports(Subscriber_1); var Subscriber_2 = Subscriber_1.Subscriber; var Subscriber_3 = Subscriber_1.SafeSubscriber; var canReportError_1 = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); function canReportError(observer) { while (observer) { var _a = observer, closed_1 = _a.closed, destination = _a.destination, isStopped = _a.isStopped; if (closed_1 || isStopped) { return false; } else if (destination && destination instanceof Subscriber_1.Subscriber) { observer = destination; } else { observer = null; } } return true; } exports.canReportError = canReportError; }); unwrapExports(canReportError_1); var canReportError_2 = canReportError_1.canReportError; var toSubscriber_1 = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); function toSubscriber(nextOrObserver, error, complete) { if (nextOrObserver) { if (nextOrObserver instanceof Subscriber_1.Subscriber) { return nextOrObserver; } if (nextOrObserver[rxSubscriber.rxSubscriber]) { return nextOrObserver[rxSubscriber.rxSubscriber](); } } if (!nextOrObserver && !error && !complete) { return new Subscriber_1.Subscriber(Observer.empty); } return new Subscriber_1.Subscriber(nextOrObserver, error, complete); } exports.toSubscriber = toSubscriber; }); unwrapExports(toSubscriber_1); var toSubscriber_2 = toSubscriber_1.toSubscriber; var observable = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); exports.observable = (function () { return typeof Symbol === 'function' && Symbol.observable || '@@observable'; })(); }); unwrapExports(observable); var observable_1 = observable.observable; var noop_1 = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); function noop() { } exports.noop = noop; }); unwrapExports(noop_1); var noop_2 = noop_1.noop; var pipe_1 = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); function pipe() { var fns = []; for (var _i = 0; _i < arguments.length; _i++) { fns[_i] = arguments[_i]; } return pipeFromArray(fns); } exports.pipe = pipe; function pipeFromArray(fns) { if (!fns) { return noop_1.noop; } if (fns.length === 1) { return fns[0]; } return function piped(input) { return fns.reduce(function (prev, fn) { return fn(prev); }, input); }; } exports.pipeFromArray = pipeFromArray; }); unwrapExports(pipe_1); var pipe_2 = pipe_1.pipe; var pipe_3 = pipe_1.pipeFromArray; var Observable_1 = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); var Observable = (function () { function Observable(subscribe) { this._isScalar = false; if (subscribe) { this._subscribe = subscribe; } } Observable.prototype.lift = function (operator) { var observable = new Observable(); observable.source = this; observable.operator = operator; return observable; }; Observable.prototype.subscribe = function (observerOrNext, error, complete) { var operator = this.operator; var sink = toSubscriber_1.toSubscriber(observerOrNext, error, complete); if (operator) { sink.add(operator.call(sink, this.source)); } else { sink.add(this.source || (config.config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ? this._subscribe(sink) : this._trySubscribe(sink)); } if (config.config.useDeprecatedSynchronousErrorHandling) { if (sink.syncErrorThrowable) { sink.syncErrorThrowable = false; if (sink.syncErrorThrown) { throw sink.syncErrorValue; } } } return sink; }; Observable.prototype._trySubscribe = function (sink) { try { return this._subscribe(sink); } catch (err) { if (config.config.useDeprecatedSynchronousErrorHandling) { sink.syncErrorThrown = true; sink.syncErrorValue = err; } if (canReportError_1.canReportError(sink)) { sink.error(err); } else { console.warn(err); } } }; Observable.prototype.forEach = function (next, promiseCtor) { var _this = this; promiseCtor = getPromiseCtor(promiseCtor); return new promiseCtor(function (resolve, reject) { var subscription; subscription = _this.subscribe(function (value) { try { next(value); } catch (err) { reject(err); if (subscription) { subscription.unsubscribe(); } } }, reject, resolve); }); }; Observable.prototype._subscribe = function (subscriber) { var source = this.source; return source && source.subscribe(subscriber); }; Observable.prototype[observable.observable] = function () { return this; }; Observable.prototype.pipe = function () { var operations = []; for (var _i = 0; _i < arguments.length; _i++) { operations[_i] = arguments[_i]; } if (operations.length === 0) { return this; } return pipe_1.pipeFromArray(operations)(this); }; Observable.prototype.toPromise = function (promiseCtor) { var _this = this; promiseCtor = getPromiseCtor(promiseCtor); return new promiseCtor(function (resolve, reject) { var value; _this.subscribe(function (x) { return value = x; }, function (err) { return reject(err); }, function () { return resolve(value); }); }); }; Observable.create = function (subscribe) { return new Observable(subscribe); }; return Observable; }()); exports.Observable = Observable; function getPromiseCtor(promiseCtor) { if (!promiseCtor) { promiseCtor = config.config.Promise || Promise; } if (!promiseCtor) { throw new Error('no Promise impl found'); } return promiseCtor; } }); unwrapExports(Observable_1); var Observable_2 = Observable_1.Observable; var map_1 = createCommonjsModule(function (module, exports) { var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); function map(project, thisArg) { return function mapOperation(source) { if (typeof project !== 'function') { throw new TypeError('argument is not a function. Are you looking for `mapTo()`?'); } return source.lift(new MapOperator(project, thisArg)); }; } exports.map = map; var MapOperator = (function () { function MapOperator(project, thisArg) { this.project = project; this.thisArg = thisArg; } MapOperator.prototype.call = function (subscriber, source) { return source.subscribe(new MapSubscriber(subscriber, this.project, this.thisArg)); }; return MapOperator; }()); exports.MapOperator = MapOperator; var MapSubscriber = (function (_super) { __extends(MapSubscriber, _super); function MapSubscriber(destination, project, thisArg) { var _this = _super.call(this, destination) || this; _this.project = project; _this.count = 0; _this.thisArg = thisArg || _this; return _this; } MapSubscriber.prototype._next = function (value) { var result; try { result = this.project.call(this.thisArg, value, this.count++); } catch (err) { this.destination.error(err); return; } this.destination.next(result); }; return MapSubscriber; }(Subscriber_1.Subscriber)); }); unwrapExports(map_1); var map_2 = map_1.map; var map_3 = map_1.MapOperator; var AjaxObservable_1 = createCommonjsModule(function (module, exports) { var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); function getCORSRequest() { if (root.root.XMLHttpRequest) { return new root.root.XMLHttpRequest(); } else if (!!root.root.XDomainRequest) { return new root.root.XDomainRequest(); } else { throw new Error('CORS is not supported by your browser'); } } function getXMLHttpRequest() { if (root.root.XMLHttpRequest) { return new root.root.XMLHttpRequest(); } else { var progId = void 0; try { var progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0']; for (var i = 0; i < 3; i++) { try { progId = progIds[i]; if (new root.root.ActiveXObject(progId)) { break; } } catch (e) { } } return new root.root.ActiveXObject(progId); } catch (e) { throw new Error('XMLHttpRequest is not supported by your browser'); } } } function ajaxGet(url, headers) { if (headers === void 0) { headers = null; } return new AjaxObservable({ method: 'GET', url: url, headers: headers }); } exports.ajaxGet = ajaxGet; function ajaxPost(url, body, headers) { return new AjaxObservable({ method: 'POST', url: url, body: body, headers: headers }); } exports.ajaxPost = ajaxPost; function ajaxDelete(url, headers) { return new AjaxObservable({ method: 'DELETE', url: url, headers: headers }); } exports.ajaxDelete = ajaxDelete; function ajaxPut(url, body, headers) { return new AjaxObservable({ method: 'PUT', url: url, body: body, headers: headers }); } exports.ajaxPut = ajaxPut; function ajaxPatch(url, body, headers) { return new AjaxObservable({ method: 'PATCH', url: url, body: body, headers: headers }); } exports.ajaxPatch = ajaxPatch; var mapResponse = map_1.map(function (x, index) { return x.response; }); function ajaxGetJSON(url, headers) { return mapResponse(new AjaxObservable({ method: 'GET', url: url, responseType: 'json', headers: headers })); } exports.ajaxGetJSON = ajaxGetJSON; var AjaxObservable = (function (_super) { __extends(AjaxObservable, _super); function AjaxObservable(urlOrRequest) { var _this = _super.call(this) || this; var request = { async: true, createXHR: function () { return this.crossDomain ? getCORSRequest() : getXMLHttpRequest(); }, crossDomain: true, withCredentials: false, headers: {}, method: 'GET', responseType: 'json', timeout: 0 }; if (typeof urlOrRequest === 'string') { request.url = urlOrRequest; } else { for (var prop in urlOrRequest) { if (urlOrRequest.hasOwnProperty(prop)) { request[prop] = urlOrRequest[prop]; } } } _this.request = request; return _this; } AjaxObservable.prototype._subscribe = function (subscriber) { return new AjaxSubscriber(subscriber, this.request); }; AjaxObservable.create = (function () { var create = function (urlOrRequest) { return new AjaxObservable(urlOrRequest); }; create.get = ajaxGet; create.post = ajaxPost; create.delete = ajaxDelete; create.put = ajaxPut; create.patch = ajaxPatch; create.getJSON = ajaxGetJSON; return create; })(); return AjaxObservable; }(Observable_1.Observable)); exports.AjaxObservable = AjaxObservable; var AjaxSubscriber = (function (_super) { __extends(AjaxSubscriber, _super); function AjaxSubscriber(destination, request) { var _this = _super.call(this, destination) || this; _this.request = request; _this.done = false; var headers = request.headers = request.headers || {}; if (!request.crossDomain && !_this.getHeader(headers, 'X-Requested-With')) { headers['X-Requested-With'] = 'XMLHttpRequest'; } var contentTypeHeader = _this.getHeader(headers, 'Content-Type'); if (!contentTypeHeader && !(root.root.FormData && request.body instanceof root.root.FormData) && typeof request.body !== 'undefined') { headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'; } request.body = _this.serializeBody(request.body, _this.getHeader(request.headers, 'Content-Type')); _this.send(); return _this; } AjaxSubscriber.prototype.next = function (e) { this.done = true; var _a = this, xhr = _a.xhr, request = _a.request, destination = _a.destination; var result; try { result = new AjaxResponse(e, xhr, request); } catch (err) { return destination.error(err); } destination.next(result); }; AjaxSubscriber.prototype.send = function () { var _a = this, request = _a.request, _b = _a.request, user = _b.user, method = _b.method, url = _b.url, async = _b.async, password = _b.password, headers = _b.headers, body = _b.body; try { var xhr = this.xhr = request.createXHR(); this.setupEvents(xhr, request); if (user) { xhr.open(method, url, async, user, password); } else { xhr.open(method, url, async); } if (async) { xhr.timeout = request.timeout; xhr.responseType = request.responseType; } if ('withCredentials' in xhr) { xhr.withCredentials = !!request.withCredentials; } this.setHeaders(xhr, headers); if (body) { xhr.send(body); } else { xhr.send(); } } catch (err) { this.error(err); } }; AjaxSubscriber.prototype.serializeBody = function (body, contentType) { if (!body || typeof body === 'string') { return body; } else if (root.root.FormData && body instanceof root.root.FormData) { return body; } if (contentType) { var splitIndex = contentType.indexOf(';'); if (splitIndex !== -1) { contentType = contentType.substring(0, splitIndex); } } switch (contentType) { case 'application/x-www-form-urlencoded': return Object.keys(body).map(function (key) { return encodeURIComponent(key) + "=" + encodeURIComponent(body[key]); }).join('&'); case 'application/json': return JSON.stringify(body); default: return body; } }; AjaxSubscriber.prototype.setHeaders = function (xhr, headers) { for (var key in headers) { if (headers.hasOwnProperty(key)) { xhr.setRequestHeader(key, headers[key]); } } }; AjaxSubscriber.prototype.getHeader = function (headers, headerName) { for (var key in headers) { if (key.toLowerCase() === headerName.toLowerCase()) { return headers[key]; } } return undefined; }; AjaxSubscriber.prototype.setupEvents = function (xhr, request) { var progressSubscriber = request.progressSubscriber; function xhrTimeout(e) { var _a = xhrTimeout, subscriber = _a.subscriber, progressSubscriber = _a.progressSubscriber, request = _a.request; if (progressSubscriber) { progressSubscriber.error(e); } var error; try { error = new exports.AjaxTimeoutError(this, request); } catch (err) { error = err; } subscriber.error(error); } xhr.ontimeout = xhrTimeout; xhrTimeout.request = request; xhrTimeout.subscriber = this; xhrTimeout.progressSubscriber = progressSubscriber; if (xhr.upload && 'withCredentials' in xhr) { if (progressSubscriber) { var xhrProgress_1; xhrProgress_1 = function (e) { var progressSubscriber = xhrProgress_1.progressSubscriber; progressSubscriber.next(e); }; if (root.root.XDomainRequest) { xhr.onprogress = xhrProgress_1; } else { xhr.upload.onprogress = xhrProgress_1; } xhrProgress_1.progressSubscriber = progressSubscriber; } var xhrError_1; xhrError_1 = function (e) { var _a = xhrError_1, progressSubscriber = _a.progressSubscriber, subscriber = _a.subscriber, request = _a.request; if (progressSubscriber) { progressSubscriber.error(e); } var error; try { error = new exports.AjaxError('ajax error', this, request); } catch (err) { error = err; } subscriber.error(error); }; xhr.onerror = xhrError_1; xhrError_1.request = request; xhrError_1.subscriber = this; xhrError_1.progressSubscriber = progressSubscriber; } function xhrReadyStateChange(e) { return; } xhr.onreadystatechange = xhrReadyStateChange; xhrReadyStateChange.subscriber = this; xhrReadyStateChange.progressSubscriber = progressSubscriber; xhrReadyStateChange.request = request; function xhrLoad(e) { var _a = xhrLoad, subscriber = _a.subscriber, progressSubscriber = _a.progressSubscriber, request = _a.request; if (this.readyState === 4) { var status_1 = this.status === 1223 ? 204 : this.status; var response = (this.responseType === 'text' ? (this.response || this.responseText) : this.response); if (status_1 === 0) { status_1 = response ? 200 : 0; } if (status_1 < 400) { if (progressSubscriber) { progressSubscriber.complete(); } subscriber.next(e); subscriber.complete(); } else { if (progressSubscriber) { progressSubscriber.error(e); } var error = void 0; try { error = new exports.AjaxError('ajax error ' + status_1, this, request); } catch (err) { error = err; } subscriber.error(error); } } } xhr.onload = xhrLoad; xhrLoad.subscriber = this; xhrLoad.progressSubscriber = progressSubscriber; xhrLoad.request = request; }; AjaxSubscriber.prototype.unsubscribe = function () { var _a = this, done = _a.done, xhr = _a.xhr; if (!done && xhr && xhr.readyState !== 4 && typeof xhr.abort === 'function') { xhr.abort(); } _super.prototype.unsubscribe.call(this); }; return AjaxSubscriber; }(Subscriber_1.Subscriber)); exports.AjaxSubscriber = AjaxSubscriber; var AjaxResponse = (function () { function AjaxResponse(originalEvent, xhr, request) { this.originalEvent = originalEvent; this.xhr = xhr; this.request = request; this.status = xhr.status; this.responseType = xhr.responseType || request.responseType; this.response = parseXhrResponse(this.responseType, xhr); } return AjaxResponse; }()); exports.AjaxResponse = AjaxResponse; var AjaxErrorImpl = (function () { function AjaxErrorImpl(message, xhr, request) { Error.call(this); this.message = message; this.name = 'AjaxError'; this.xhr = xhr; this.request = request; this.status = xhr.status; this.responseType = xhr.responseType || request.responseType; this.response = parseXhrResponse(this.responseType, xhr); return this; } AjaxErrorImpl.prototype = Object.create(Error.prototype); return AjaxErrorImpl; })(); exports.AjaxError = AjaxErrorImpl; function parseJson(xhr) { if ('response' in xhr) { return xhr.responseType ? xhr.response : JSON.parse(xhr.response || xhr.responseText || 'null'); } else { return JSON.parse(xhr.responseText || 'null'); } } function parseXhrResponse(responseType, xhr) { switch (responseType) { case 'json': return parseJson(xhr); case 'xml': return xhr.responseXML; case 'text': default: return ('response' in xhr) ? xhr.response : xhr.responseText; } } function AjaxTimeoutErrorImpl(xhr, request) { exports.AjaxError.call(this, 'ajax timeout', xhr, request); this.name = 'AjaxTimeoutError'; return this; } exports.AjaxTimeoutError = AjaxTimeoutErrorImpl; }); unwrapExports(AjaxObservable_1); var AjaxObservable_2 = AjaxObservable_1.ajaxGet; var AjaxObservable_3 = AjaxObservable_1.ajaxPost; var AjaxObservable_4 = AjaxObservable_1.ajaxDelete; var AjaxObservable_5 = AjaxObservable_1.ajaxPut; var AjaxObservable_6 = AjaxObservable_1.ajaxPatch; var AjaxObservable_7 = AjaxObservable_1.ajaxGetJSON; var AjaxObservable_8 = AjaxObservable_1.AjaxObservable; var AjaxObservable_9 = AjaxObservable_1.AjaxSubscriber; var AjaxObservable_10 = AjaxObservable_1.AjaxResponse; var AjaxObservable_11 = AjaxObservable_1.AjaxError; var AjaxObservable_12 = AjaxObservable_1.AjaxTimeoutError; var ajax = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); exports.ajax = (function () { return AjaxObservable_1.AjaxObservable.create; })(); }); unwrapExports(ajax); var ajax_1 = ajax.ajax; var ajax$1 = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); exports.ajax = ajax.ajax; exports.AjaxResponse = AjaxObservable_1.AjaxResponse; exports.AjaxError = AjaxObservable_1.AjaxError; exports.AjaxTimeoutError = AjaxObservable_1.AjaxTimeoutError; }); unwrapExports(ajax$1); var ajax_2 = ajax$1.ajax; var ajax_3 = ajax$1.AjaxResponse; var ajax_4 = ajax$1.AjaxError; var ajax_5 = ajax$1.AjaxTimeoutError; var rngBrowser = createCommonjsModule(function (module) { // Unique ID creation requires a high quality random # generator. In the // browser this is a little complicated due to unknown quality of Math.random() // and inconsistent support for the `crypto` API. We do the best we can via // feature-detection // getRandomValues needs to be invoked in a context where "this" is a Crypto // implementation. Also, find the complete implementation of crypto on IE11. var getRandomValues = (typeof(crypto) != 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto)) || (typeof(msCrypto) != 'undefined' && typeof window.msCrypto.getRandomValues == 'function' && msCrypto.getRandomValues.bind(msCrypto)); if (getRandomValues) { // WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto var rnds8 = new Uint8Array(16); // eslint-disable-line no-undef module.exports = function whatwgRNG() { getRandomValues(rnds8); return rnds8; }; } else { // Math.random()-based (RNG) // // If all else fails, use Math.random(). It's fast, but is of unspecified // quality. var rnds = new Array(16); module.exports = function mathRNG() { for (var i = 0, r; i < 16; i++) { if ((i & 0x03) === 0) r = Math.random() * 0x100000000; rnds[i] = r >>> ((i & 0x03) << 3) & 0xff; } return rnds; }; } }); /** * Convert array of 16 byte values to UUID string format of the form: * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX */ var byteToHex = []; for (var i = 0; i < 256; ++i) { byteToHex[i] = (i + 0x100).toString(16).substr(1); } function bytesToUuid(buf, offset) { var i = offset || 0; var bth = byteToHex; // join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4 return ([bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]]]).join(''); } var bytesToUuid_1 = bytesToUuid; function v4(options, buf, offset) { var i = buf && offset || 0; if (typeof(options) == 'string') { buf = options === 'binary' ? new Array(16) : null; options = null; } options = options || {}; var rnds = options.random || (options.rng || rngBrowser)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved` rnds[6] = (rnds[6] & 0x0f) | 0x40; rnds[8] = (rnds[8] & 0x3f) | 0x80; // Copy bytes to buffer, if provided if (buf) { for (var ii = 0; ii < 16; ++ii) { buf[i + ii] = rnds[ii]; } } return buf || bytesToUuid_1(rnds); } var v4_1 = v4; var createAPI = function (baseURL, cache) { var CACHE_KEY = 'pas_js_retry_queue'; var retryQueue = new rxjs.BehaviorSubject((cache.get(CACHE_KEY) || [])); retryQueue.getValue().forEach(function (retryItem) { var next = retryQueue.getValue().filter(function (i) { return i.id !== retryItem.id; }); retryQueue.next(next); post(retryItem.path, retryItem.body); }); retryQueue.subscribe({ next: function (v) { return cache.set(CACHE_KEY, v); }, }); function post(path, body) { var request = ajax_2({ url: "" + baseURL + path, method: 'POST', body: body, headers: { 'Content-Type': 'application/json' }, timeout: 3000, }); request.subscribe({ error: function (e) { if (e instanceof ajax_4 && (e.status > 500 || e.status === 0)) { var retryItem = { id: v4_1(), path: path, body: body, }; retryQueue.next(__spreadArrays(retryQueue.getValue(), [retryItem])); } }, }); return request; } return { post: post, }; }; var createCache = function (options) { return ({ set: function (key, value) { Cookies.set(key, value, { expires: options.expires, domain: options.domain, sameSite: 'lax', }); return value; }, get: function (key) { return Cookies.getJSON(key); }, clear: function (key) { return Cookies.remove(key, { domain: options.domain }); },