nk20/static/rest_framework/js/coreapi-0.1.1.js

2043 lines
154 KiB
JavaScript
Raw Normal View History

2020-02-25 21:15:46 +00:00
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.coreapi = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var BasicAuthentication = function () {
function BasicAuthentication() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, BasicAuthentication);
var username = options.username;
var password = options.password;
var hash = window.btoa(username + ':' + password);
this.auth = 'Basic ' + hash;
}
_createClass(BasicAuthentication, [{
key: 'authenticate',
value: function authenticate(options) {
options.headers['Authorization'] = this.auth;
return options;
}
}]);
return BasicAuthentication;
}();
module.exports = {
BasicAuthentication: BasicAuthentication
};
},{}],2:[function(require,module,exports){
'use strict';
var basic = require('./basic');
var session = require('./session');
var token = require('./token');
module.exports = {
BasicAuthentication: basic.BasicAuthentication,
SessionAuthentication: session.SessionAuthentication,
TokenAuthentication: token.TokenAuthentication
};
},{"./basic":1,"./session":3,"./token":4}],3:[function(require,module,exports){
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var utils = require('../utils');
function trim(str) {
return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
function getCookie(cookieName, cookieString) {
cookieString = cookieString || window.document.cookie;
if (cookieString && cookieString !== '') {
var cookies = cookieString.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, cookieName.length + 1) === cookieName + '=') {
return decodeURIComponent(cookie.substring(cookieName.length + 1));
}
}
}
return null;
}
var SessionAuthentication = function () {
function SessionAuthentication() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, SessionAuthentication);
this.csrfToken = getCookie(options.csrfCookieName, options.cookieString);
this.csrfHeaderName = options.csrfHeaderName;
}
_createClass(SessionAuthentication, [{
key: 'authenticate',
value: function authenticate(options) {
options.credentials = 'same-origin';
if (this.csrfToken && !utils.csrfSafeMethod(options.method)) {
options.headers[this.csrfHeaderName] = this.csrfToken;
}
return options;
}
}]);
return SessionAuthentication;
}();
module.exports = {
SessionAuthentication: SessionAuthentication
};
},{"../utils":15}],4:[function(require,module,exports){
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var TokenAuthentication = function () {
function TokenAuthentication() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, TokenAuthentication);
this.token = options.token;
this.scheme = options.scheme || 'Bearer';
}
_createClass(TokenAuthentication, [{
key: 'authenticate',
value: function authenticate(options) {
options.headers['Authorization'] = this.scheme + ' ' + this.token;
return options;
}
}]);
return TokenAuthentication;
}();
module.exports = {
TokenAuthentication: TokenAuthentication
};
},{}],5:[function(require,module,exports){
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var document = require('./document');
var codecs = require('./codecs');
var errors = require('./errors');
var transports = require('./transports');
var utils = require('./utils');
function lookupLink(node, keys) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var key = _step.value;
if (node instanceof document.Document) {
node = node.content[key];
} else {
node = node[key];
}
if (node === undefined) {
throw new errors.LinkLookupError('Invalid link lookup: ' + JSON.stringify(keys));
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
if (!(node instanceof document.Link)) {
throw new errors.LinkLookupError('Invalid link lookup: ' + JSON.stringify(keys));
}
return node;
}
var Client = function () {
function Client() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Client);
var transportOptions = {
auth: options.auth || null,
headers: options.headers || {},
requestCallback: options.requestCallback,
responseCallback: options.responseCallback
};
this.decoders = options.decoders || [new codecs.CoreJSONCodec(), new codecs.JSONCodec(), new codecs.TextCodec()];
this.transports = options.transports || [new transports.HTTPTransport(transportOptions)];
}
_createClass(Client, [{
key: 'action',
value: function action(document, keys) {
var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var link = lookupLink(document, keys);
var transport = utils.determineTransport(this.transports, link.url);
return transport.action(link, this.decoders, params);
}
}, {
key: 'get',
value: function get(url) {
var link = new document.Link(url, 'get');
var transport = utils.determineTransport(this.transports, url);
return transport.action(link, this.decoders);
}
}]);
return Client;
}();
module.exports = {
Client: Client
};
},{"./codecs":7,"./document":10,"./errors":11,"./transports":14,"./utils":15}],6:[function(require,module,exports){
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var document = require('../document');
var URL = require('url-parse');
function unescapeKey(key) {
if (key.match(/__(type|meta)$/)) {
return key.substring(1);
}
return key;
}
function getString(obj, key) {
var value = obj[key];
if (typeof value === 'string') {
return value;
}
return '';
}
function getBoolean(obj, key) {
var value = obj[key];
if (typeof value === 'boolean') {
return value;
}
return false;
}
function getObject(obj, key) {
var value = obj[key];
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
return value;
}
return {};
}
function getArray(obj, key) {
var value = obj[key];
if (value instanceof Array) {
return value;
}
return [];
}
function getContent(data, baseUrl) {
var excluded = ['_type', '_meta'];
var content = {};
for (var property in data) {
if (data.hasOwnProperty(property) && !excluded.includes(property)) {
var key = unescapeKey(property);
var value = primitiveToNode(data[property], baseUrl);
content[key] = value;
}
}
return content;
}
function primitiveToNode(data, baseUrl) {
var isObject = data instanceof Object && !(data instanceof Array);
if (isObject && data._type === 'document') {
// Document
var meta = getObject(data, '_meta');
var relativeUrl = getString(meta, 'url');
var url = relativeUrl ? URL(relativeUrl, baseUrl).toString() : '';
var title = getString(meta, 'title');
var description = getString(meta, 'description');
var content = getContent(data, url);
return new document.Document(url, title, description, content);
} else if (isObject && data._type === 'link') {
// Link
var _relativeUrl = getString(data, 'url');
var _url = _relativeUrl ? URL(_relativeUrl, baseUrl).toString() : '';
var method = getString(data, 'action') || 'get';
var _title = getString(data, 'title');
var _description = getString(data, 'description');
var fieldsData = getArray(data, 'fields');
var fields = [];
for (var idx = 0, len = fieldsData.length; idx < len; idx++) {
var value = fieldsData[idx];
var name = getString(value, 'name');
var required = getBoolean(value, 'required');
var location = getString(value, 'location');
var fieldDescription = getString(value, 'fieldDescription');
var field = new document.Field(name, required, location, fieldDescription);
fields.push(field);
}
return new document.Link(_url, method, 'application/json', fields, _title, _description);
} else if (isObject) {
// Object
var _content = {};
for (var key in data) {
if (data.hasOwnProperty(key)) {
_content[key] = primitiveToNode(data[key], baseUrl);
}
}
return _content;
} else if (data instanceof Array) {
// Object
var _content2 = [];
for (var _idx = 0, _len = data.length; _idx < _len; _idx++) {
_content2.push(primitiveToNode(data[_idx], baseUrl));
}
return _content2;
}
// Primitive
return data;
}
var CoreJSONCodec = function () {
function CoreJSONCodec() {
_classCallCheck(this, CoreJSONCodec);
this.mediaType = 'application/coreapi+json';
}
_createClass(CoreJSONCodec, [{
key: 'decode',
value: function decode(text) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var data = text;
if (options.preloaded === undefined || !options.preloaded) {
data = JSON.parse(text);
}
return primitiveToNode(data, options.url);
}
}]);
return CoreJSONCodec;
}();
module.exports = {
CoreJSONCodec: CoreJSONCodec
};
},{"../document":10,"url-parse":19}],7:[function(require,module,exports){
'use strict';
var corejson = require('./corejson');
var json = require('./json');
var text = require('./text');
module.exports = {
CoreJSONCodec: corejson.CoreJSONCodec,
JSONCodec: json.JSONCodec,
TextCodec: text.TextCodec
};
},{"./corejson":6,"./json":8,"./text":9}],8:[function(require,module,exports){
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var JSONCodec = function () {
function JSONCodec() {
_classCallCheck(this, JSONCodec);
this.mediaType = 'application/json';
}
_createClass(JSONCodec, [{
key: 'decode',
value: function decode(text) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return JSON.parse(text);
}
}]);
return JSONCodec;
}();
module.exports = {
JSONCodec: JSONCodec
};
},{}],9:[function(require,module,exports){
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var TextCodec = function () {
function TextCodec() {
_classCallCheck(this, TextCodec);
this.mediaType = 'text/*';
}
_createClass(TextCodec, [{
key: 'decode',
value: function decode(text) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return text;
}
}]);
return TextCodec;
}();
module.exports = {
TextCodec: TextCodec
};
},{}],10:[function(require,module,exports){
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Document = function Document() {
var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
var title = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
var description = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
var content = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
_classCallCheck(this, Document);
this.url = url;
this.title = title;
this.description = description;
this.content = content;
};
var Link = function Link(url, method) {
var encoding = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'application/json';
var fields = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
var title = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '';
var description = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : '';
_classCallCheck(this, Link);
if (url === undefined) {
throw new Error('url argument is required');
}
if (method === undefined) {
throw new Error('method argument is required');
}
this.url = url;
this.method = method;
this.encoding = encoding;
this.fields = fields;
this.title = title;
this.description = description;
};
var Field = function Field(name) {
var required = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var location = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
var description = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
_classCallCheck(this, Field);
if (name === undefined) {
throw new Error('name argument is required');
}
this.name = name;
this.required = required;
this.location = location;
this.description = description;
};
module.exports = {
Document: Document,
Link: Link,
Field: Field
};
},{}],11:[function(require,module,exports){
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var ParameterError = function (_Error) {
_inherits(ParameterError, _Error);
function ParameterError(message) {
_classCallCheck(this, ParameterError);
var _this = _possibleConstructorReturn(this, (ParameterError.__proto__ || Object.getPrototypeOf(ParameterError)).call(this, message));
_this.message = message;
_this.name = 'ParameterError';
return _this;
}
return ParameterError;
}(Error);
var LinkLookupError = function (_Error2) {
_inherits(LinkLookupError, _Error2);
function LinkLookupError(message) {
_classCallCheck(this, LinkLookupError);
var _this2 = _possibleConstructorReturn(this, (LinkLookupError.__proto__ || Object.getPrototypeOf(LinkLookupError)).call(this, message));
_this2.message = message;
_this2.name = 'LinkLookupError';
return _this2;
}
return LinkLookupError;
}(Error);
var ErrorMessage = function (_Error3) {
_inherits(ErrorMessage, _Error3);
function ErrorMessage(message, content) {
_classCallCheck(this, ErrorMessage);
var _this3 = _possibleConstructorReturn(this, (ErrorMessage.__proto__ || Object.getPrototypeOf(ErrorMessage)).call(this, message));
_this3.message = message;
_this3.content = content;
_this3.name = 'ErrorMessage';
return _this3;
}
return ErrorMessage;
}(Error);
module.exports = {
ParameterError: ParameterError,
LinkLookupError: LinkLookupError,
ErrorMessage: ErrorMessage
};
},{}],12:[function(require,module,exports){
'use strict';
var auth = require('./auth');
var client = require('./client');
var codecs = require('./codecs');
var document = require('./document');
var errors = require('./errors');
var transports = require('./transports');
var utils = require('./utils');
var coreapi = {
Client: client.Client,
Document: document.Document,
Link: document.Link,
auth: auth,
codecs: codecs,
errors: errors,
transports: transports,
utils: utils
};
module.exports = coreapi;
},{"./auth":2,"./client":5,"./codecs":7,"./document":10,"./errors":11,"./transports":14,"./utils":15}],13:[function(require,module,exports){
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var fetch = require('isomorphic-fetch');
var errors = require('../errors');
var utils = require('../utils');
var URL = require('url-parse');
var urlTemplate = require('url-template');
var parseResponse = function parseResponse(response, decoders, responseCallback) {
return response.text().then(function (text) {
if (responseCallback) {
responseCallback(response, text);
}
var contentType = response.headers.get('Content-Type');
var decoder = utils.negotiateDecoder(decoders, contentType);
var options = { url: response.url };
return decoder.decode(text, options);
});
};
var HTTPTransport = function () {
function HTTPTransport() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, HTTPTransport);
this.schemes = ['http', 'https'];
this.auth = options.auth || null;
this.headers = options.headers || {};
this.fetch = options.fetch || fetch;
this.FormData = options.FormData || window.FormData;
this.requestCallback = options.requestCallback;
this.responseCallback = options.responseCallback;
}
_createClass(HTTPTransport, [{
key: 'buildRequest',
value: function buildRequest(link, decoders) {
var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var fields = link.fields;
var method = link.method.toUpperCase();
var queryParams = {};
var pathParams = {};
var formParams = {};
var fieldNames = [];
var hasBody = false;
for (var idx = 0, len = fields.length; idx < len; idx++) {
var field = fields[idx];
// Ensure any required fields are included
if (!params.hasOwnProperty(field.name)) {
if (field.required) {
throw new errors.ParameterError('Missing required field: "' + field.name + '"');
} else {
continue;
}
}
fieldNames.push(field.name);
if (field.location === 'query') {
queryParams[field.name] = params[field.name];
} else if (field.location === 'path') {
pathParams[field.name] = params[field.name];
} else if (field.location === 'form') {
formParams[field.name] = params[field.name];
hasBody = true;
} else if (field.location === 'body') {
formParams = params[field.name];
hasBody = true;
}
}
// Check for any parameters that did not have a matching field
for (var property in params) {
if (params.hasOwnProperty(property) && !fieldNames.includes(property)) {
throw new errors.ParameterError('Unknown parameter: "' + property + '"');
}
}
var requestOptions = { method: method, headers: {} };
Object.assign(requestOptions.headers, this.headers);
if (hasBody) {
if (link.encoding === 'application/json') {
requestOptions.body = JSON.stringify(formParams);
requestOptions.headers['Content-Type'] = 'application/json';
} else if (link.encoding === 'multipart/form-data') {
var form = new this.FormData();
for (var paramKey in formParams) {
form.append(paramKey, formParams[paramKey]);
}
requestOptions.body = form;
} else if (link.encoding === 'application/x-www-form-urlencoded') {
var formBody = [];
for (var _paramKey in formParams) {
var encodedKey = encodeURIComponent(_paramKey);
var encodedValue = encodeURIComponent(formParams[_paramKey]);
formBody.push(encodedKey + '=' + encodedValue);
}
formBody = formBody.join('&');
requestOptions.body = formBody;
requestOptions.headers['Content-Type'] = 'application/x-www-form-urlencoded';
}
}
if (this.auth) {
requestOptions = this.auth.authenticate(requestOptions);
}
var parsedUrl = urlTemplate.parse(link.url);
parsedUrl = parsedUrl.expand(pathParams);
parsedUrl = new URL(parsedUrl);
parsedUrl.set('query', queryParams);
return {
url: parsedUrl.toString(),
options: requestOptions
};
}
}, {
key: 'action',
value: function action(link, decoders) {
var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var responseCallback = this.responseCallback;
var request = this.buildRequest(link, decoders, params);
if (this.requestCallback) {
this.requestCallback(request);
}
return this.fetch(request.url, request.options).then(function (response) {
if (response.status === 204) {
return;
}
return parseResponse(response, decoders, responseCallback).then(function (data) {
if (response.ok) {
return data;
} else {
var title = response.status + ' ' + response.statusText;
var error = new errors.ErrorMessage(title, data);
return Promise.reject(error);
}
});
});
}
}]);
return HTTPTransport;
}();
module.exports = {
HTTPTransport: HTTPTransport
};
},{"../errors":11,"../utils":15,"isomorphic-fetch":16,"url-parse":19,"url-template":21}],14:[function(require,module,exports){
'use strict';
var http = require('./http');
module.exports = {
HTTPTransport: http.HTTPTransport
};
},{"./http":13}],15:[function(require,module,exports){
'use strict';
var URL = require('url-parse');
var determineTransport = function determineTransport(transports, url) {
var parsedUrl = new URL(url);
var scheme = parsedUrl.protocol.replace(':', '');
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = transports[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var transport = _step.value;
if (transport.schemes.includes(scheme)) {
return transport;
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
throw Error('Unsupported scheme in URL: ' + url);
};
var negotiateDecoder = function negotiateDecoder(decoders, contentType) {
if (contentType === undefined || contentType === null) {
return decoders[0];
}
var fullType = contentType.toLowerCase().split(';')[0].trim();
var mainType = fullType.split('/')[0] + '/*';
var wildcardType = '*/*';
var acceptableTypes = [fullType, mainType, wildcardType];
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = decoders[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var decoder = _step2.value;
if (acceptableTypes.includes(decoder.mediaType)) {
return decoder;
}
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
throw Error('Unsupported media in Content-Type header: ' + contentType);
};
var csrfSafeMethod = function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)
);
};
module.exports = {
determineTransport: determineTransport,
negotiateDecoder: negotiateDecoder,
csrfSafeMethod: csrfSafeMethod
};
},{"url-parse":19}],16:[function(require,module,exports){
// the whatwg-fetch polyfill installs the fetch() function
// on the global object (window or self)
//
// Return that as the export for use in Webpack, Browserify etc.
require('whatwg-fetch');
module.exports = self.fetch.bind(self);
},{"whatwg-fetch":22}],17:[function(require,module,exports){
'use strict';
var has = Object.prototype.hasOwnProperty;
/**
* Simple query string parser.
*
* @param {String} query The query string that needs to be parsed.
* @returns {Object}
* @api public
*/
function querystring(query) {
var parser = /([^=?&]+)=?([^&]*)/g
, result = {}
, part;
//
// Little nifty parsing hack, leverage the fact that RegExp.exec increments
// the lastIndex property so we can continue executing this loop until we've
// parsed all results.
//
for (;
part = parser.exec(query);
result[decodeURIComponent(part[1])] = decodeURIComponent(part[2])
);
return result;
}
/**
* Transform a query string to an object.
*
* @param {Object} obj Object that should be transformed.
* @param {String} prefix Optional prefix.
* @returns {String}
* @api public
*/
function querystringify(obj, prefix) {
prefix = prefix || '';
var pairs = [];
//
// Optionally prefix with a '?' if needed
//
if ('string' !== typeof prefix) prefix = '?';
for (var key in obj) {
if (has.call(obj, key)) {
pairs.push(encodeURIComponent(key) +'='+ encodeURIComponent(obj[key]));
}
}
return pairs.length ? prefix + pairs.join('&') : '';
}
//
// Expose the module.
//
exports.stringify = querystringify;
exports.parse = querystring;
},{}],18:[function(require,module,exports){
'use strict';
/**
* Check if we're required to add a port number.
*
* @see https://url.spec.whatwg.org/#default-port
* @param {Number|String} port Port number we need to check
* @param {String} protocol Protocol we need to check against.
* @returns {Boolean} Is it a default port for the given protocol
* @api private
*/
module.exports = function required(port, protocol) {
protocol = protocol.split(':')[0];
port = +port;
if (!port) return false;
switch (protocol) {
case 'http':
case 'ws':
return port !== 80;
case 'https':
case 'wss':
return port !== 443;
case 'ftp':
return port !== 21;
case 'gopher':
return port !== 70;
case 'file':
return false;
}
return port !== 0;
};
},{}],19:[function(require,module,exports){
'use strict';
var required = require('requires-port')
, lolcation = require('./lolcation')
, qs = require('querystringify')
, protocolre = /^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i;
/**
* These are the parse rules for the URL parser, it informs the parser
* about:
*
* 0. The char it Needs to parse, if it's a string it should be done using
* indexOf, RegExp using exec and NaN means set as current value.
* 1. The property we should set when parsing this value.
* 2. Indication if it's backwards or forward parsing, when set as number it's
* the value of extra chars that should be split off.
* 3. Inherit from location if non existing in the parser.
* 4. `toLowerCase` the resulting value.
*/
var rules = [
['#', 'hash'], // Extract from the back.
['?', 'query'], // Extract from the back.
['/', 'pathname'], // Extract from the back.
['@', 'auth', 1], // Extract from the front.
[NaN, 'host', undefined, 1, 1], // Set left over value.
[/:(\d+)$/, 'port', undefined, 1], // RegExp the back.
[NaN, 'hostname', undefined, 1, 1] // Set left over.
];
/**
* @typedef ProtocolExtract
* @type Object
* @property {String} protocol Protocol matched in the URL, in lowercase.
* @property {Boolean} slashes `true` if protocol is followed by "//", else `false`.
* @property {String} rest Rest of the URL that is not part of the protocol.
*/
/**
* Extract protocol information from a URL with/without double slash ("//").
*
* @param {String} address URL we want to extract from.
* @return {ProtocolExtract} Extracted information.
* @api private
*/
function extractProtocol(address) {
var match = protocolre.exec(address);
return {
protocol: match[1] ? match[1].toLowerCase() : '',
slashes: !!match[2],
rest: match[3]
};
}
/**
* Resolve a relative URL pathname against a base URL pathname.
*
* @param {String} relative Pathname of the relative URL.
* @param {String} base Pathname of the base URL.
* @return {String} Resolved pathname.
* @api private
*/
function resolve(relative, base) {
var path = (base || '/').split('/').slice(0, -1).concat(relative.split('/'))
, i = path.length
, last = path[i - 1]
, unshift = false
, up = 0;
while (i--) {
if (path[i] === '.') {
path.splice(i, 1);
} else if (path[i] === '..') {
path.splice(i, 1);
up++;
} else if (up) {
if (i === 0) unshift = true;
path.splice(i, 1);
up--;
}
}
if (unshift) path.unshift('');
if (last === '.' || last === '..') path.push('');
return path.join('/');
}
/**
* The actual URL instance. Instead of returning an object we've opted-in to
* create an actual constructor as it's much more memory efficient and
* faster and it pleases my OCD.
*
* @constructor
* @param {String} address URL we want to parse.
* @param {Object|String} location Location defaults for relative paths.
* @param {Boolean|Function} parser Parser for the query string.
* @api public
*/
function URL(address, location, parser) {
if (!(this instanceof URL)) {
return new URL(address, location, parser);
}
var relative, extracted, parse, instruction, index, key
, instructions = rules.slice()
, type = typeof location
, url = this
, i = 0;
//
// The following if statements allows this module two have compatibility with
// 2 different API:
//
// 1. Node.js's `url.parse` api which accepts a URL, boolean as arguments
// where the boolean indicates that the query string should also be parsed.
//
// 2. The `URL` interface of the browser which accepts a URL, object as
// arguments. The supplied object will be used as default values / fall-back
// for relative paths.
//
if ('object' !== type && 'string' !== type) {
parser = location;
location = null;
}
if (parser && 'function' !== typeof parser) parser = qs.parse;
location = lolcation(location);
//
// Extract protocol information before running the instructions.
//
extracted = extractProtocol(address || '');
relative = !extracted.protocol && !extracted.slashes;
url.slashes = extracted.slashes || relative && location.slashes;
url.protocol = extracted.protocol || location.protocol || '';
address = extracted.rest;
//
// When the authority component is absent the URL starts with a path
// component.
//
if (!extracted.slashes) instructions[2] = [/(.*)/, 'pathname'];
for (; i < instructions.length; i++) {
instruction = instructions[i];
parse = instruction[0];
key = instruction[1];
if (parse !== parse) {
url[key] = address;
} else if ('string' === typeof parse) {
if (~(index = address.indexOf(parse))) {
if ('number' === typeof instruction[2]) {
url[key] = address.slice(0, index);
address = address.slice(index + instruction[2]);
} else {
url[key] = address.slice(index);
address = address.slice(0, index);
}
}
} else if (index = parse.exec(address)) {
url[key] = index[1];
address = address.slice(0, index.index);
}
url[key] = url[key] || (
relative && instruction[3] ? location[key] || '' : ''
);
//
// Hostname, host and protocol should be lowercased so they can be used to
// create a proper `origin`.
//
if (instruction[4]) url[key] = url[key].toLowerCase();
}
//
// Also parse the supplied query string in to an object. If we're supplied
// with a custom parser as function use that instead of the default build-in
// parser.
//
if (parser) url.query = parser(url.query);
//
// If the URL is relative, resolve the pathname against the base URL.
//
if (
relative
&& location.slashes
&& url.pathname.charAt(0) !== '/'
&& (url.pathname !== '' || location.pathname !== '')
) {
url.pathname = resolve(url.pathname, location.pathname);
}
//
// We should not add port numbers if they are already the default port number
// for a given protocol. As the host also contains the port number we're going
// override it with the hostname which contains no port number.
//
if (!required(url.port, url.protocol)) {
url.host = url.hostname;
url.port = '';
}
//
// Parse down the `auth` for the username and password.
//
url.username = url.password = '';
if (url.auth) {
instruction = url.auth.split(':');
url.username = instruction[0] || '';
url.password = instruction[1] || '';
}
url.origin = url.protocol && url.host && url.protocol !== 'file:'
? url.protocol +'//'+ url.host
: 'null';
//
// The href is just the compiled result.
//
url.href = url.toString();
}
/**
* This is convenience method for changing properties in the URL instance to
* insure that they all propagate correctly.
*
* @param {String} part Property we need to adjust.
* @param {Mixed} value The newly assigned value.
* @param {Boolean|Function} fn When setting the query, it will be the function
* used to parse the query.
* When setting the protocol, double slash will be
* removed from the final url if it is true.
* @returns {URL}
* @api public
*/
URL.prototype.set = function set(part, value, fn) {
var url = this;
switch (part) {
case 'query':
if ('string' === typeof value && value.length) {
value = (fn || qs.parse)(value);
}
url[part] = value;
break;
case 'port':
url[part] = value;
if (!required(value, url.protocol)) {
url.host = url.hostname;
url[part] = '';
} else if (value) {
url.host = url.hostname +':'+ value;
}
break;
case 'hostname':
url[part] = value;
if (url.port) value += ':'+ url.port;
url.host = value;
break;
case 'host':
url[part] = value;
if (/:\d+$/.test(value)) {
value = value.split(':');
url.port = value.pop();
url.hostname = value.join(':');
} else {
url.hostname = value;
url.port = '';
}
break;
case 'protocol':
url.protocol = value.toLowerCase();
url.slashes = !fn;
break;
case 'pathname':
url.pathname = value.length && value.charAt(0) !== '/' ? '/' + value : value;
break;
default:
url[part] = value;
}
for (var i = 0; i < rules.length; i++) {
var ins = rules[i];
if (ins[4]) url[ins[1]] = url[ins[1]].toLowerCase();
}
url.origin = url.protocol && url.host && url.protocol !== 'file:'
? url.protocol +'//'+ url.host
: 'null';
url.href = url.toString();
return url;
};
/**
* Transform the properties back in to a valid and full URL string.
*
* @param {Function} stringify Optional query stringify function.
* @returns {String}
* @api public
*/
URL.prototype.toString = function toString(stringify) {
if (!stringify || 'function' !== typeof stringify) stringify = qs.stringify;
var query
, url = this
, protocol = url.protocol;
if (protocol && protocol.charAt(protocol.length - 1) !== ':') protocol += ':';
var result = protocol + (url.slashes ? '//' : '');
if (url.username) {
result += url.username;
if (url.password) result += ':'+ url.password;
result += '@';
}
result += url.host + url.pathname;
query = 'object' === typeof url.query ? stringify(url.query) : url.query;
if (query) result += '?' !== query.charAt(0) ? '?'+ query : query;
if (url.hash) result += url.hash;
return result;
};
//
// Expose the URL parser and some additional properties that might be useful for
// others or testing.
//
URL.extractProtocol = extractProtocol;
URL.location = lolcation;
URL.qs = qs;
module.exports = URL;
},{"./lolcation":20,"querystringify":17,"requires-port":18}],20:[function(require,module,exports){
(function (global){
'use strict';
var slashes = /^[A-Za-z][A-Za-z0-9+-.]*:\/\//;
/**
* These properties should not be copied or inherited from. This is only needed
* for all non blob URL's as a blob URL does not include a hash, only the
* origin.
*
* @type {Object}
* @private
*/
var ignore = { hash: 1, query: 1 }
, URL;
/**
* The location object differs when your code is loaded through a normal page,
* Worker or through a worker using a blob. And with the blobble begins the
* trouble as the location object will contain the URL of the blob, not the
* location of the page where our code is loaded in. The actual origin is
* encoded in the `pathname` so we can thankfully generate a good "default"
* location from it so we can generate proper relative URL's again.
*
* @param {Object|String} loc Optional default location object.
* @returns {Object} lolcation object.
* @api public
*/
module.exports = function lolcation(loc) {
loc = loc || global.location || {};
URL = URL || require('./');
var finaldestination = {}
, type = typeof loc
, key;
if ('blob:' === loc.protocol) {
finaldestination = new URL(unescape(loc.pathname), {});
} else if ('string' === type) {
finaldestination = new URL(loc, {});
for (key in ignore) delete finaldestination[key];
} else if ('object' === type) {
for (key in loc) {
if (key in ignore) continue;
finaldestination[key] = loc[key];
}
if (finaldestination.slashes === undefined) {
finaldestination.slashes = slashes.test(loc.href);
}
}
return finaldestination;
};
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./":19}],21:[function(require,module,exports){
(function (root, factory) {
if (typeof exports === 'object') {
module.exports = factory();
} else if (typeof define === 'function' && define.amd) {
define([], factory);
} else {
root.urltemplate = factory();
}
}(this, function () {
/**
* @constructor
*/
function UrlTemplate() {
}
/**
* @private
* @param {string} str
* @return {string}
*/
UrlTemplate.prototype.encodeReserved = function (str) {
return str.split(/(%[0-9A-Fa-f]{2})/g).map(function (part) {
if (!/%[0-9A-Fa-f]/.test(part)) {
part = encodeURI(part).replace(/%5B/g, '[').replace(/%5D/g, ']');
}
return part;
}).join('');
};
/**
* @private
* @param {string} str
* @return {string}
*/
UrlTemplate.prototype.encodeUnreserved = function (str) {
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
return '%' + c.charCodeAt(0).toString(16).toUpperCase();
});
}
/**
* @private
* @param {string} operator
* @param {string} value
* @param {string} key
* @return {string}
*/
UrlTemplate.prototype.encodeValue = function (operator, value, key) {
value = (operator === '+' || operator === '#') ? this.encodeReserved(value) : this.encodeUnreserved(value);
if (key) {
return this.encodeUnreserved(key) + '=' + value;
} else {
return value;
}
};
/**
* @private
* @param {*} value
* @return {boolean}
*/
UrlTemplate.prototype.isDefined = function (value) {
return value !== undefined && value !== null;
};
/**
* @private
* @param {string}
* @return {boolean}
*/
UrlTemplate.prototype.isKeyOperator = function (operator) {
return operator === ';' || operator === '&' || operator === '?';
};
/**
* @private
* @param {Object} context
* @param {string} operator
* @param {string} key
* @param {string} modifier
*/
UrlTemplate.prototype.getValues = function (context, operator, key, modifier) {
var value = context[key],
result = [];
if (this.isDefined(value) && value !== '') {
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
value = value.toString();
if (modifier && modifier !== '*') {
value = value.substring(0, parseInt(modifier, 10));
}
result.push(this.encodeValue(operator, value, this.isKeyOperator(operator) ? key : null));
} else {
if (modifier === '*') {
if (Array.isArray(value)) {
value.filter(this.isDefined).forEach(function (value) {
result.push(this.encodeValue(operator, value, this.isKeyOperator(operator) ? key : null));
}, this);
} else {
Object.keys(value).forEach(function (k) {
if (this.isDefined(value[k])) {
result.push(this.encodeValue(operator, value[k], k));
}
}, this);
}
} else {
var tmp = [];
if (Array.isArray(value)) {
value.filter(this.isDefined).forEach(function (value) {
tmp.push(this.encodeValue(operator, value));
}, this);
} else {
Object.keys(value).forEach(function (k) {
if (this.isDefined(value[k])) {
tmp.push(this.encodeUnreserved(k));
tmp.push(this.encodeValue(operator, value[k].toString()));
}
}, this);
}
if (this.isKeyOperator(operator)) {
result.push(this.encodeUnreserved(key) + '=' + tmp.join(','));
} else if (tmp.length !== 0) {
result.push(tmp.join(','));
}
}
}
} else {
if (operator === ';') {
if (this.isDefined(value)) {
result.push(this.encodeUnreserved(key));
}
} else if (value === '' && (operator === '&' || operator === '?')) {
result.push(this.encodeUnreserved(key) + '=');
} else if (value === '') {
result.push('');
}
}
return result;
};
/**
* @param {string} template
* @return {function(Object):string}
*/
UrlTemplate.prototype.parse = function (template) {
var that = this;
var operators = ['+', '#', '.', '/', ';', '?', '&'];
return {
expand: function (context) {
return template.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g, function (_, expression, literal) {
if (expression) {
var operator = null,
values = [];
if (operators.indexOf(expression.charAt(0)) !== -1) {
operator = expression.charAt(0);
expression = expression.substr(1);
}
expression.split(/,/g).forEach(function (variable) {
var tmp = /([^:\*]*)(?::(\d+)|(\*))?/.exec(variable);
values.push.apply(values, that.getValues(context, operator, tmp[1], tmp[2] || tmp[3]));
});
if (operator && operator !== '+') {
var separator = ',';
if (operator === '?') {
separator = '&';
} else if (operator !== '#') {
separator = operator;
}
return (values.length !== 0 ? operator : '') + values.join(separator);
} else {
return values.join(',');
}
} else {
return that.encodeReserved(literal);
}
});
}
};
};
return new UrlTemplate();
}));
},{}],22:[function(require,module,exports){
(function(self) {
'use strict';
if (self.fetch) {
return
}
var support = {
searchParams: 'URLSearchParams' in self,
iterable: 'Symbol' in self && 'iterator' in Symbol,
blob: 'FileReader' in self && 'Blob' in self && (function() {
try {
new Blob()
return true
} catch(e) {
return false
}
})(),
formData: 'FormData' in self,
arrayBuffer: 'ArrayBuffer' in self
}
if (support.arrayBuffer) {
var viewClasses = [
'[object Int8Array]',
'[object Uint8Array]',
'[object Uint8ClampedArray]',
'[object Int16Array]',
'[object Uint16Array]',
'[object Int32Array]',
'[object Uint32Array]',
'[object Float32Array]',
'[object Float64Array]'
]
var isDataView = function(obj) {
return obj && DataView.prototype.isPrototypeOf(obj)
}
var isArrayBufferView = ArrayBuffer.isView || function(obj) {
return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
}
}
function normalizeName(name) {
if (typeof name !== 'string') {
name = String(name)
}
if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) {
throw new TypeError('Invalid character in header field name')
}
return name.toLowerCase()
}
function normalizeValue(value) {
if (typeof value !== 'string') {
value = String(value)
}
return value
}
// Build a destructive iterator for the value list
function iteratorFor(items) {
var iterator = {
next: function() {
var value = items.shift()
return {done: value === undefined, value: value}
}
}
if (support.iterable) {
iterator[Symbol.iterator] = function() {
return iterator
}
}
return iterator
}
function Headers(headers) {
this.map = {}
if (headers instanceof Headers) {
headers.forEach(function(value, name) {
this.append(name, value)
}, this)
} else if (headers) {
Object.getOwnPropertyNames(headers).forEach(function(name) {
this.append(name, headers[name])
}, this)
}
}
Headers.prototype.append = function(name, value) {
name = normalizeName(name)
value = normalizeValue(value)
var oldValue = this.map[name]
this.map[name] = oldValue ? oldValue+','+value : value
}
Headers.prototype['delete'] = function(name) {
delete this.map[normalizeName(name)]
}
Headers.prototype.get = function(name) {
name = normalizeName(name)
return this.has(name) ? this.map[name] : null
}
Headers.prototype.has = function(name) {
return this.map.hasOwnProperty(normalizeName(name))
}
Headers.prototype.set = function(name, value) {
this.map[normalizeName(name)] = normalizeValue(value)
}
Headers.prototype.forEach = function(callback, thisArg) {
for (var name in this.map) {
if (this.map.hasOwnProperty(name)) {
callback.call(thisArg, this.map[name], name, this)
}
}
}
Headers.prototype.keys = function() {
var items = []
this.forEach(function(value, name) { items.push(name) })
return iteratorFor(items)
}
Headers.prototype.values = function() {
var items = []
this.forEach(function(value) { items.push(value) })
return iteratorFor(items)
}
Headers.prototype.entries = function() {
var items = []
this.forEach(function(value, name) { items.push([name, value]) })
return iteratorFor(items)
}
if (support.iterable) {
Headers.prototype[Symbol.iterator] = Headers.prototype.entries
}
function consumed(body) {
if (body.bodyUsed) {
return Promise.reject(new TypeError('Already read'))
}
body.bodyUsed = true
}
function fileReaderReady(reader) {
return new Promise(function(resolve, reject) {
reader.onload = function() {
resolve(reader.result)
}
reader.onerror = function() {
reject(reader.error)
}
})
}
function readBlobAsArrayBuffer(blob) {
var reader = new FileReader()
var promise = fileReaderReady(reader)
reader.readAsArrayBuffer(blob)
return promise
}
function readBlobAsText(blob) {
var reader = new FileReader()
var promise = fileReaderReady(reader)
reader.readAsText(blob)
return promise
}
function bufferClone(buf) {
if (buf.slice) {
return buf.slice(0)
} else {
var view = new Uint8Array(buf.byteLength)
view.set(new Uint8Array(buf))
return view.buffer
}
}
function Body() {
this.bodyUsed = false
this._initBody = function(body) {
this._bodyInit = body
if (!body) {
this._bodyText = ''
} else if (typeof body === 'string') {
this._bodyText = body
} else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
this._bodyBlob = body
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
this._bodyFormData = body
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
this._bodyText = body.toString()
} else if (support.arrayBuffer && support.blob && isDataView(body)) {
this._bodyArrayBuffer = bufferClone(body.buffer)
// IE 10-11 can't handle a DataView body.
this._bodyInit = new Blob([this._bodyArrayBuffer])
} else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
this._bodyArrayBuffer = bufferClone(body)
} else {
throw new Error('unsupported BodyInit type')
}
if (!this.headers.get('content-type')) {
if (typeof body === 'string') {
this.headers.set('content-type', 'text/plain;charset=UTF-8')
} else if (this._bodyBlob && this._bodyBlob.type) {
this.headers.set('content-type', this._bodyBlob.type)
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8')
}
}
}
if (support.blob) {
this.blob = function() {
var rejected = consumed(this)
if (rejected) {
return rejected
}
if (this._bodyBlob) {
return Promise.resolve(this._bodyBlob)
} else if (this._bodyArrayBuffer) {
return Promise.resolve(new Blob([this._bodyArrayBuffer]))
} else if (this._bodyFormData) {
throw new Error('could not read FormData body as blob')
} else {
return Promise.resolve(new Blob([this._bodyText]))
}
}
}
this.text = function() {
var rejected = consumed(this)
if (rejected) {
return rejected
}
if (this._bodyBlob) {
return readBlobAsText(this._bodyBlob)
} else if (this._bodyArrayBuffer) {
var view = new Uint8Array(this._bodyArrayBuffer)
var str = String.fromCharCode.apply(null, view)
return Promise.resolve(str)
} else if (this._bodyFormData) {
throw new Error('could not read FormData body as text')
} else {
return Promise.resolve(this._bodyText)
}
}
if (support.arrayBuffer) {
this.arrayBuffer = function() {
if (this._bodyArrayBuffer) {
return consumed(this) || Promise.resolve(this._bodyArrayBuffer)
} else {
return this.blob().then(readBlobAsArrayBuffer)
}
}
}
if (support.formData) {
this.formData = function() {
return this.text().then(decode)
}
}
this.json = function() {
return this.text().then(JSON.parse)
}
return this
}
// HTTP methods whose capitalization should be normalized
var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']
function normalizeMethod(method) {
var upcased = method.toUpperCase()
return (methods.indexOf(upcased) > -1) ? upcased : method
}
function Request(input, options) {
options = options || {}
var body = options.body
if (typeof input === 'string') {
this.url = input
} else {
if (input.bodyUsed) {
throw new TypeError('Already read')
}
this.url = input.url
this.credentials = input.credentials
if (!options.headers) {
this.headers = new Headers(input.headers)
}
this.method = input.method
this.mode = input.mode
if (!body && input._bodyInit != null) {
body = input._bodyInit
input.bodyUsed = true
}
}
this.credentials = options.credentials || this.credentials || 'omit'
if (options.headers || !this.headers) {
this.headers = new Headers(options.headers)
}
this.method = normalizeMethod(options.method || this.method || 'GET')
this.mode = options.mode || this.mode || null
this.referrer = null
if ((this.method === 'GET' || this.method === 'HEAD') && body) {
throw new TypeError('Body not allowed for GET or HEAD requests')
}
this._initBody(body)
}
Request.prototype.clone = function() {
return new Request(this, { body: this._bodyInit })
}
function decode(body) {
var form = new FormData()
body.trim().split('&').forEach(function(bytes) {
if (bytes) {
var split = bytes.split('=')
var name = split.shift().replace(/\+/g, ' ')
var value = split.join('=').replace(/\+/g, ' ')
form.append(decodeURIComponent(name), decodeURIComponent(value))
}
})
return form
}
function parseHeaders(rawHeaders) {
var headers = new Headers()
rawHeaders.split('\r\n').forEach(function(line) {
var parts = line.split(':')
var key = parts.shift().trim()
if (key) {
var value = parts.join(':').trim()
headers.append(key, value)
}
})
return headers
}
Body.call(Request.prototype)
function Response(bodyInit, options) {
if (!options) {
options = {}
}
this.type = 'default'
this.status = 'status' in options ? options.status : 200
this.ok = this.status >= 200 && this.status < 300
this.statusText = 'statusText' in options ? options.statusText : 'OK'
this.headers = new Headers(options.headers)
this.url = options.url || ''
this._initBody(bodyInit)
}
Body.call(Response.prototype)
Response.prototype.clone = function() {
return new Response(this._bodyInit, {
status: this.status,
statusText: this.statusText,
headers: new Headers(this.headers),
url: this.url
})
}
Response.error = function() {
var response = new Response(null, {status: 0, statusText: ''})
response.type = 'error'
return response
}
var redirectStatuses = [301, 302, 303, 307, 308]
Response.redirect = function(url, status) {
if (redirectStatuses.indexOf(status) === -1) {
throw new RangeError('Invalid status code')
}
return new Response(null, {status: status, headers: {location: url}})
}
self.Headers = Headers
self.Request = Request
self.Response = Response
self.fetch = function(input, init) {
return new Promise(function(resolve, reject) {
var request = new Request(input, init)
var xhr = new XMLHttpRequest()
xhr.onload = function() {
var options = {
status: xhr.status,
statusText: xhr.statusText,
headers: parseHeaders(xhr.getAllResponseHeaders() || '')
}
options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL')
var body = 'response' in xhr ? xhr.response : xhr.responseText
resolve(new Response(body, options))
}
xhr.onerror = function() {
reject(new TypeError('Network request failed'))
}
xhr.ontimeout = function() {
reject(new TypeError('Network request failed'))
}
xhr.open(request.method, request.url, true)
if (request.credentials === 'include') {
xhr.withCredentials = true
}
if ('responseType' in xhr && support.blob) {
xhr.responseType = 'blob'
}
request.headers.forEach(function(value, name) {
xhr.setRequestHeader(name, value)
})
xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit)
})
}
self.fetch.polyfill = true
})(typeof self !== 'undefined' ? self : this);
},{}]},{},[12])(12)
});
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJsaWIvYXV0aC9iYXNpYy5qcyIsImxpYi9hdXRoL2luZGV4LmpzIiwibGliL2F1dGgvc2Vzc2lvbi5qcyIsImxpYi9hdXRoL3Rva2VuLmpzIiwibGliL2NsaWVudC5qcyIsImxpYi9jb2RlY3MvY29yZWpzb24uanMiLCJsaWIvY29kZWNzL2luZGV4LmpzIiwibGliL2NvZGVjcy9qc29uLmpzIiwibGliL2NvZGVjcy90ZXh0LmpzIiwibGliL2RvY3VtZW50LmpzIiwibGliL2Vycm9ycy5qcyIsImxpYi9pbmRle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