react-redux-quest
Version:
API and generic utilities for react and redux eco-system
48 lines (31 loc) • 1.53 kB
JavaScript
exports.__esModule = true;
exports.default = validate;
var _invariant = require('invariant');
var _invariant2 = _interopRequireDefault(_invariant);
var _warning = require('warning');
var _warning2 = _interopRequireDefault(_warning);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var SUPPORTED_HTTP_METHODS = [
// safe => idempotent methods
'GET', 'HEAD', 'OPTIONS',
// Not safe but idempotent methods
'PUT', 'DELETE',
// Not safe and not idempotent methods
'POST', 'PATCH'];
var FORBIDDEN_HTTP_METHODS = ['CONNECT', 'TRACE', 'TRACK'];
function validate(settings) {
var url = settings.url,
method = settings.method,
meta = settings.meta;
(0, _invariant2.default)(url, 'Must specify "url"');
var isValidHttpMethod = SUPPORTED_HTTP_METHODS.includes(method.toUpperCase());
(0, _invariant2.default)(isValidHttpMethod, '[MOST LIKELY ITS TYPO]: "method" must be valid http methods.\n Refer: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods');
var isForbiddenMethods = FORBIDDEN_HTTP_METHODS.includes(method);
(0, _warning2.default)(!isForbiddenMethods, '"method" must be one of the fetch supported http methods.\n Refer: https://fetch.spec.whatwg.org/#concept-method-normalize');
!meta && console.info('You might want to specify "meta" object to use "questReducer"\n that updates "isFetching" stateSlice.');
return {
isValidApiSettings: url && isValidHttpMethod
};
}
module.exports = exports['default'];
;