Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-isomorphic-tools

Package Overview
Dependencies
Maintainers
1
Versions
124
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-isomorphic-tools - npm Package Compare versions

Comparing version 3.0.0-alpha.15 to 3.0.0-alpha.16

167

dist/Data/Fetcher.js

@@ -22,4 +22,2 @@ 'use strict';

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -32,116 +30,73 @@

this.fetcher = function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(url) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
this.fetcher = function (url) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var _options$params = options.params,
params = _options$params === undefined ? {} : _options$params,
_options$queryParams = options.queryParams,
queryParams = _options$queryParams === undefined ? {} : _options$queryParams,
_options$type = options.type,
type = _options$type === undefined ? 'json' : _options$type,
_options$baseUrl = options.baseUrl,
baseUrl = _options$baseUrl === undefined ? (0, _settings.getBaseUrl)() : _options$baseUrl,
_options$method = options.method,
method = _options$method === undefined ? 'get' : _options$method,
_options$customHeader = options.customHeaders,
customHeaders = _options$customHeader === undefined ? false : _options$customHeader;
var _options$params, params, _options$queryParams, queryParams, _options$type, type, _options$baseUrl, baseUrl, _options$method, method, _options$customHeader, customHeaders, args, query, data, contentType;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_options$params = options.params, params = _options$params === undefined ? {} : _options$params, _options$queryParams = options.queryParams, queryParams = _options$queryParams === undefined ? {} : _options$queryParams, _options$type = options.type, type = _options$type === undefined ? 'json' : _options$type, _options$baseUrl = options.baseUrl, baseUrl = _options$baseUrl === undefined ? (0, _settings.getBaseUrl)() : _options$baseUrl, _options$method = options.method, method = _options$method === undefined ? 'get' : _options$method, _options$customHeader = options.customHeaders, customHeaders = _options$customHeader === undefined ? false : _options$customHeader;
args = {
mode: 'cors',
credentials: 'same-origin',
method: method.toUpperCase()
};
query = '';
var args = {
mode: 'cors',
credentials: 'same-origin',
method: method.toUpperCase()
};
if (!(type === 'form-data')) {
_context.next = 8;
break;
}
var query = '';
if (type === 'form-data') {
args.body = params;
query = _this.stringifyQuery(queryParams);
} else if (type === 'json') {
if (args.method === 'GET' || args.method === 'DELETE') {
query = _this.stringifyQuery(params);
} else {
args.body = JSON.stringify(params);
query = _this.stringifyQuery(queryParams);
}
args.headers = new Headers({
Accept: 'application/json',
'Content-Type': 'application/json',
cookie: _this.getCookiesData()
});
} else {
throw new Error('Type \'' + type + '\' - is not supported in the Fetcher');
}
args.body = params;
query = _this.stringifyQuery(queryParams);
_context.next = 14;
break;
if ((0, _settings.isAuthenticated)()) {
args.headers.set('Authorization', (0, _settings.getTokenPrefix)() + (0, _settings.getToken)());
}
case 8:
if (!(type === 'json')) {
_context.next = 13;
break;
}
if (customHeaders) {
args.headers = customHeaders;
}
if (args.method === 'GET' || args.method === 'DELETE') {
query = _this.stringifyQuery(params);
} else {
args.body = JSON.stringify(params);
query = _this.stringifyQuery(queryParams);
}
args.headers = new Headers({
Accept: 'application/json',
'Content-Type': 'application/json',
cookie: _this.getCookiesData()
});
_context.next = 14;
break;
return new Promise(function (res, rej) {
fetch(baseUrl + url + query, args).then(function (data) {
var contentType = data.headers.get('content-type');
case 13:
throw new Error('Type \'' + type + '\' - is not supported in the Fetcher');
case 14:
if ((0, _settings.isAuthenticated)()) {
args.headers.set('Authorization', (0, _settings.getTokenPrefix)() + (0, _settings.getToken)());
}
if (customHeaders) {
args.headers = customHeaders;
}
_context.prev = 16;
_context.next = 19;
return fetch(baseUrl + url + query, args);
case 19:
data = _context.sent;
contentType = data.headers.get('content-type');
if (!(contentType && contentType.indexOf('application/json') !== -1)) {
_context.next = 25;
break;
}
_context.next = 24;
return data.json();
case 24:
return _context.abrupt('return', _context.sent);
case 25:
_context.next = 27;
return data.text();
case 27:
return _context.abrupt('return', _context.sent);
case 30:
_context.prev = 30;
_context.t0 = _context['catch'](16);
throw {
type: 'notAvailableResource',
params: {
method: method,
baseUrl: baseUrl,
url: url,
params: params
},
e: _context.t0
};
case 33:
case 'end':
return _context.stop();
if (data.status >= 400) {
if (contentType.indexOf('application/json') !== -1) {
data.json().then(rej);
} else {
data.text().then(rej);
}
} else {
if (contentType && contentType.indexOf('application/json') !== -1) {
data.json().then(res);
} else {
data.text().then(res);
}
}
}, _callee, _this, [[16, 30]]);
}));
}).catch(rej);
});
};
return function (_x) {
return _ref.apply(this, arguments);
};
}();
this.stringifyQuery = function (params) {

@@ -148,0 +103,0 @@ return _qs2.default.stringify(params, { addQueryPrefix: true }) || '';

{
"name": "react-isomorphic-tools",
"version": "3.0.0-alpha.15",
"version": "3.0.0-alpha.16",
"description": "Authorization, Fetcher, Preload. Tools for ServerSide rendering",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc