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

kitsu

Package Overview
Dependencies
Maintainers
1
Versions
172
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kitsu - npm Package Compare versions

Comparing version 4.2.0 to 4.2.1

10

CHANGELOG.md

@@ -0,1 +1,11 @@

#### 4.2.1 (2018-01-18)
##### Chores
* **deps:** update jest to ~22.1.0 ([#94](https://github.com/wopian/kitsu/pull/94)) ([5b5a76b8](https://github.com/wopian/kitsu/commit/5b5a76b881856f0ac5fe0ac5107447ff06bbb290))
##### Bug Fixes
* convert CamelCase into lowercase for kebab and snake conversions ([#95](https://github.com/wopian/kitsu/pull/95)) ([ad948322](https://github.com/wopian/kitsu/commit/ad9483228056813c62979850aada1951c4648057))
### 4.2.0 (2018-01-16)

@@ -2,0 +12,0 @@

2

lib/kitsu.js

@@ -1,1 +0,1 @@

(function(global,factory){'object'==typeof exports&&'undefined'!=typeof module?module.exports=factory(require('babel-runtime/regenerator'),require('babel-runtime/helpers/slicedToArray'),require('babel-runtime/helpers/asyncToGenerator'),require('babel-runtime/helpers/classCallCheck'),require('babel-runtime/helpers/createClass'),require('axios')):'function'==typeof define&&define.amd?define(['babel-runtime/regenerator','babel-runtime/helpers/slicedToArray','babel-runtime/helpers/asyncToGenerator','babel-runtime/helpers/classCallCheck','babel-runtime/helpers/createClass','axios'],factory):global.kitsu=factory(global._regeneratorRuntime,global._slicedToArray,global._asyncToGenerator,global._classCallCheck,global._createClass,global.axios)})(this,function(_regeneratorRuntime,_slicedToArray,_asyncToGenerator,_classCallCheck,_createClass,axios){'use strict';function error(E){if(E.response){var e=E.response.data;if(e)return e}else if(E.errors)return E;throw E}function query(params){try{var _query='',_loop=function(param){'object'==typeof params[param]?Object.keys(params[param]).forEach(function(value){_query+=`&${param}[${value}]=${params[param][value]}`}):'string'==typeof params[param]&&(_query+=`&${param}=${params[param]}`)};for(var param in params)_loop(param);return params?_query.slice(1):''}catch(E){error(E)}}_regeneratorRuntime=_regeneratorRuntime&&_regeneratorRuntime.hasOwnProperty('default')?_regeneratorRuntime['default']:_regeneratorRuntime,_slicedToArray=_slicedToArray&&_slicedToArray.hasOwnProperty('default')?_slicedToArray['default']:_slicedToArray,_asyncToGenerator=_asyncToGenerator&&_asyncToGenerator.hasOwnProperty('default')?_asyncToGenerator['default']:_asyncToGenerator,_classCallCheck=_classCallCheck&&_classCallCheck.hasOwnProperty('default')?_classCallCheck['default']:_classCallCheck,_createClass=_createClass&&_createClass.hasOwnProperty('default')?_createClass['default']:_createClass,axios=axios&&axios.hasOwnProperty('default')?axios['default']:axios;var deattribute=function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee2(data){var _this=this;return _regeneratorRuntime.wrap(function(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:if(_context2.prev=0,'object'!=typeof data||null===data){_context2.next=8;break}if(!Array.isArray(data)){_context2.next=7;break}return _context2.next=5,data.map(function(){var _ref2=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(el){return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.abrupt('return',deattribute(el));case 1:case'end':return _context.stop();}},_callee,_this)}));return function(){return _ref2.apply(this,arguments)}}());case 5:_context2.next=8;break;case 7:data.attributes&&data.attributes.constructor===Object&&(Object.keys(data.attributes).forEach(function(key){data[key]=data.attributes[key]}),delete data.attributes);case 8:return _context2.abrupt('return',data);case 11:_context2.prev=11,_context2.t0=_context2['catch'](0),error(_context2.t0);case 14:case'end':return _context2.stop();}},_callee2,this,[[0,11]])}));return function(){return _ref.apply(this,arguments)}}(),deserialiseArray=function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(obj){var _iteratorNormalCompletion,_didIteratorError,_iteratorError,_iterator,_step,value;return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.prev=0,_iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0,_context.prev=4,_context.next=7,obj.data;case 7:_context.t0=Symbol.iterator,_iterator=_context.sent[_context.t0]();case 9:if(_iteratorNormalCompletion=(_step=_iterator.next()).done){_context.next=23;break}if(value=_step.value,!obj.included){_context.next=15;break}return _context.next=14,linkRelationships(value,obj.included);case 14:value=_context.sent;case 15:if(!value.attributes){_context.next=19;break}return _context.next=18,deattribute(value);case 18:value=_context.sent;case 19:obj.data[obj.data.indexOf(value)]=value;case 20:_iteratorNormalCompletion=!0,_context.next=9;break;case 23:_context.next=29;break;case 25:_context.prev=25,_context.t1=_context['catch'](4),_didIteratorError=!0,_iteratorError=_context.t1;case 29:_context.prev=29,_context.prev=30,!_iteratorNormalCompletion&&_iterator.return&&_iterator.return();case 32:if(_context.prev=32,!_didIteratorError){_context.next=35;break}throw _iteratorError;case 35:return _context.finish(32);case 36:return _context.finish(29);case 37:return _context.abrupt('return',obj);case 40:_context.prev=40,_context.t2=_context['catch'](0),error(_context.t2);case 43:case'end':return _context.stop();}},_callee,this,[[0,40],[4,25,29,37],[30,,32,36]])}));return function(){return _ref.apply(this,arguments)}}(),deserialise=function(){var _ref2=_asyncToGenerator(_regeneratorRuntime.mark(function _callee2(obj){return _regeneratorRuntime.wrap(function(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:if(_context2.prev=0,!(obj.data&&obj.data.constructor===Array)){_context2.next=7;break}return _context2.next=4,deserialiseArray(obj);case 4:obj=_context2.sent,_context2.next=11;break;case 7:if(!obj.included){_context2.next=11;break}return _context2.next=10,linkRelationships(obj.data,obj.included);case 10:obj.data=_context2.sent;case 11:if(delete obj.included,!obj.data.attributes){_context2.next=16;break}return _context2.next=15,deattribute(obj.data);case 15:obj.data=_context2.sent;case 16:return _context2.abrupt('return',obj);case 19:_context2.prev=19,_context2.t0=_context2['catch'](0),error(_context2.t0);case 22:case'end':return _context2.stop();}},_callee2,this,[[0,19]])}));return function(){return _ref2.apply(this,arguments)}}(),filterIncludes=function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(included,_ref2){var id=_ref2.id,type=_ref2.type;return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.prev=0,_context.abrupt('return',included.filter(function(el){return el.id===id&&el.type===type})[0]||{id,type});case 4:_context.prev=4,_context.t0=_context['catch'](0),error(_context.t0);case 7:case'end':return _context.stop();}},_callee,this,[[0,4]])}));return function(){return _ref.apply(this,arguments)}}(),linkRelationships=function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(data,included){var relationships,key,_iteratorNormalCompletion,_didIteratorError,_iteratorError,_iterator,_step,_ref2,id,type,deattributed,_relationships$key$da,_id,_type,_deattributed;return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.prev=0,relationships=data.relationships,_context.next=4,relationships;case 4:_context.t0=_regeneratorRuntime.keys(_context.sent);case 5:if((_context.t1=_context.t0()).done){_context.next=59;break}if(key=_context.t1.value,!(relationships[key].data&&Array.isArray(relationships[key].data))){_context.next=46;break}return _iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0,_context.prev=11,_context.next=14,relationships[key].data;case 14:_context.t2=Symbol.iterator,_iterator=_context.sent[_context.t2]();case 16:if(_iteratorNormalCompletion=(_step=_iterator.next()).done){_context.next=30;break}return _ref2=_step.value,id=_ref2.id,type=_ref2.type,_context.t3=deattribute,_context.next=22,filterIncludes(included,{id,type});case 22:return _context.t4=_context.sent,_context.next=25,(0,_context.t3)(_context.t4);case 25:deattributed=_context.sent,'undefined'!=typeof deattributed&&(!data[key]&&(data[key]=[]),data[key].push(deattributed));case 27:_iteratorNormalCompletion=!0,_context.next=16;break;case 30:_context.next=36;break;case 32:_context.prev=32,_context.t5=_context['catch'](11),_didIteratorError=!0,_iteratorError=_context.t5;case 36:_context.prev=36,_context.prev=37,!_iteratorNormalCompletion&&_iterator.return&&_iterator.return();case 39:if(_context.prev=39,!_didIteratorError){_context.next=42;break}throw _iteratorError;case 42:return _context.finish(39);case 43:return _context.finish(36);case 44:_context.next=57;break;case 46:if(!relationships[key].data){_context.next=57;break}return _relationships$key$da=relationships[key].data,_id=_relationships$key$da.id,_type=_relationships$key$da.type,_context.t6=deattribute,_context.next=51,filterIncludes(included,{id:_id,type:_type});case 51:return _context.t7=_context.sent,_context.next=54,(0,_context.t6)(_context.t7);case 54:_deattributed=_context.sent,'undefined'==typeof _deattributed||data[key]||(data[key]=_deattributed),delete data[key].relationships;case 57:_context.next=5;break;case 59:return delete data.relationships,_context.abrupt('return',data);case 63:_context.prev=63,_context.t8=_context['catch'](0),error(_context.t8);case 66:case'end':return _context.stop();}},_callee,this,[[0,63],[11,32,36,44],[37,,39,43]])}));return function(){return _ref.apply(this,arguments)}}(),serialise=function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(model){var type,data,_loop,prop,_this=this,obj=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},method=2<arguments.length&&arguments[2]!==void 0?arguments[2]:'POST';return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:if(_context.prev=0,obj.constructor===Object&&0!==Object.keys(obj).length){_context.next=3;break}throw new Error(`${method} requires a JSON object body`);case 3:if(type=this.plural(this.camel(model)),data={type},'POST'===method||'undefined'!=typeof obj.id){_context.next=7;break}throw new Error(`${method} requires an ID for the ${type} type`);case 7:for(prop in'POST'!==method&&(data.id=obj.id.toString()),_loop=function(prop){if(null!==obj[prop]&&obj[prop].constructor===Object){if('string'==typeof obj[prop].id)'undefined'==typeof data.relationships&&(data.relationships={}),'undefined'==typeof obj[prop].type&&(obj[prop].type=_this.plural(_this.camel(prop))),data.relationships[prop]={data:Object.assign(obj[prop])};else throw new Error(`${method} requires an ID for the ${prop} relationships`);}else if(null!==obj[prop]&&Array.isArray(obj[prop])){var ptype=_this.plural(_this.camel(prop));'undefined'==typeof data.relationships&&(data.relationships={}),data.relationships[prop]={data:obj[prop].map(function(elem){if('undefined'==typeof elem.id)throw new Error(`${method} requires an ID for the ${prop} relationships`);return{id:elem.id,type:elem.type||ptype}})}}else'id'!==prop&&'type'!==prop&&('undefined'==typeof data.attributes&&(data.attributes={}),data.attributes[prop]=obj[prop])},obj)_loop(prop);return _context.abrupt('return',{data});case 13:throw _context.prev=13,_context.t0=_context['catch'](0),_context.t0;case 16:case'end':return _context.stop();}},_callee,this,[[0,13]])}));return function(){return _ref.apply(this,arguments)}}(),camel=function(s){return s.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g,function(match){return match.slice(1).toUpperCase()})},kebab=function(s){return s.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,function(match){return'-'+match.toLowerCase()})},snake=function(s){return s.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,function(match){return'_'+match.toLowerCase()})},jsonAPI='application/vnd.api+json',jsonAPIHeader={Accept:jsonAPI,"Content-Type":jsonAPI},Kitsu=function(){function Kitsu(){var options=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};_classCallCheck(this,Kitsu),this.fetch=this.get,this.update=this.patch,this.create=this.post,this.camel=!1===options.camelCaseTypes?function(s){return s}:camel,this.resCase='none'===options.resourceCase?function(s){return s}:'snake'===options.resourceCase?snake:kebab,this.plural=!1===options.pluralize?function(s){return s}:require('pluralize'),this.headers=Object.assign({},options.headers,jsonAPIHeader),axios.defaults.baseURL=options.baseURL||'https://kitsu.io/api/edge',axios.defaults.timeout=options.timeout||3e4}return _createClass(Kitsu,[{key:'get',value:function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(model){var _model$split,_model$split2,res,id,url,_ref2,data,params=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},headers=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.prev=0,_model$split=model.split('/'),_model$split2=_slicedToArray(_model$split,2),res=_model$split2[0],id=_model$split2[1],url=this.plural(this.resCase(res))+(id?'/'+id:''),_context.next=5,axios.get(url,{params,paramsSerializer:function(p){return query(p)},headers:Object.assign(this.headers,headers,jsonAPIHeader)});case 5:return _ref2=_context.sent,data=_ref2.data,_context.abrupt('return',deserialise(data));case 10:return _context.prev=10,_context.t0=_context['catch'](0),_context.abrupt('return',error(_context.t0));case 13:case'end':return _context.stop();}},_callee,this,[[0,10]])}));return function(){return _ref.apply(this,arguments)}}()},{key:'patch',value:function(){var _ref3=_asyncToGenerator(_regeneratorRuntime.mark(function _callee2(model,body){var url,_ref4,data,headers=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return _regeneratorRuntime.wrap(function(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:if(_context2.prev=0,headers=Object.assign(this.headers,headers,jsonAPIHeader),this.isAuth){_context2.next=4;break}throw new Error('Not logged in');case 4:if('undefined'!=typeof body.id){_context2.next=6;break}throw new Error('Updating a resource requires an ID');case 6:return url=this.plural(this.resCase(model))+'/'+body.id,_context2.t0=axios,_context2.t1=url,_context2.next=11,serialise.apply(this,[model,body,'PATCH']);case 11:return _context2.t2=_context2.sent,_context2.t3={headers},_context2.next=15,_context2.t0.patch.call(_context2.t0,_context2.t1,_context2.t2,_context2.t3);case 15:return _ref4=_context2.sent,data=_ref4.data,_context2.abrupt('return',data);case 20:return _context2.prev=20,_context2.t4=_context2['catch'](0),_context2.abrupt('return',error(_context2.t4));case 23:case'end':return _context2.stop();}},_callee2,this,[[0,20]])}));return function(){return _ref3.apply(this,arguments)}}()},{key:'post',value:function(){var _ref5=_asyncToGenerator(_regeneratorRuntime.mark(function _callee3(model,body){var url,_ref6,data,headers=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return _regeneratorRuntime.wrap(function(_context3){for(;;)switch(_context3.prev=_context3.next){case 0:if(_context3.prev=0,headers=Object.assign(this.headers,headers,jsonAPIHeader),this.isAuth){_context3.next=4;break}throw new Error('Not logged in');case 4:return url=this.plural(this.resCase(model)),_context3.t0=axios,_context3.t1=url,_context3.next=9,serialise.apply(this,[model,body]);case 9:return _context3.t2=_context3.sent,_context3.t3={headers},_context3.next=13,_context3.t0.post.call(_context3.t0,_context3.t1,_context3.t2,_context3.t3);case 13:return _ref6=_context3.sent,data=_ref6.data,_context3.abrupt('return',data);case 18:return _context3.prev=18,_context3.t4=_context3['catch'](0),_context3.abrupt('return',error(_context3.t4));case 21:case'end':return _context3.stop();}},_callee3,this,[[0,18]])}));return function(){return _ref5.apply(this,arguments)}}()},{key:'remove',value:function(){var _ref7=_asyncToGenerator(_regeneratorRuntime.mark(function _callee4(model,id){var url,_ref8,data,headers=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return _regeneratorRuntime.wrap(function(_context4){for(;;)switch(_context4.prev=_context4.next){case 0:if(_context4.prev=0,headers=Object.assign(this.headers,headers,jsonAPIHeader),this.isAuth){_context4.next=4;break}throw new Error('Not logged in');case 4:return url=this.plural(this.resCase(model))+'/'+id,_context4.t0=axios,_context4.t1=url,_context4.next=9,serialise.apply(this,[model,{id},'DELETE']);case 9:return _context4.t2=_context4.sent,_context4.t3=headers,_context4.t4={data:_context4.t2,headers:_context4.t3},_context4.next=14,_context4.t0.delete.call(_context4.t0,_context4.t1,_context4.t4);case 14:return _ref8=_context4.sent,data=_ref8.data,_context4.abrupt('return',data);case 19:return _context4.prev=19,_context4.t5=_context4['catch'](0),_context4.abrupt('return',error(_context4.t5));case 22:case'end':return _context4.stop();}},_callee4,this,[[0,19]])}));return function(){return _ref7.apply(this,arguments)}}()},{key:'self',value:function(){var _ref9=_asyncToGenerator(_regeneratorRuntime.mark(function _callee5(){var res,params=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},headers=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return _regeneratorRuntime.wrap(function(_context5){for(;;)switch(_context5.prev=_context5.next){case 0:return _context5.prev=0,_context5.next=3,this.get('users',Object.assign({filter:{self:!0}},params),headers);case 3:if(res=_context5.sent,!res.errors){_context5.next=6;break}throw res;case 6:return _context5.abrupt('return',res.data[0]);case 9:return _context5.prev=9,_context5.t0=_context5['catch'](0),_context5.abrupt('return',error(_context5.t0));case 12:case'end':return _context5.stop();}},_callee5,this,[[0,9]])}));return function(){return _ref9.apply(this,arguments)}}()},{key:'isAuth',get:function(){return!!this.headers.Authorization}}]),Kitsu}();return Kitsu});
(function(global,factory){'object'==typeof exports&&'undefined'!=typeof module?module.exports=factory(require('babel-runtime/regenerator'),require('babel-runtime/helpers/slicedToArray'),require('babel-runtime/helpers/asyncToGenerator'),require('babel-runtime/helpers/classCallCheck'),require('babel-runtime/helpers/createClass'),require('axios')):'function'==typeof define&&define.amd?define(['babel-runtime/regenerator','babel-runtime/helpers/slicedToArray','babel-runtime/helpers/asyncToGenerator','babel-runtime/helpers/classCallCheck','babel-runtime/helpers/createClass','axios'],factory):global.kitsu=factory(global._regeneratorRuntime,global._slicedToArray,global._asyncToGenerator,global._classCallCheck,global._createClass,global.axios)})(this,function(_regeneratorRuntime,_slicedToArray,_asyncToGenerator,_classCallCheck,_createClass,axios){'use strict';function error(E){if(E.response){var e=E.response.data;if(e)return e}else if(E.errors)return E;throw E}function query(params){try{var _query='',_loop=function(param){'object'==typeof params[param]?Object.keys(params[param]).forEach(function(value){_query+=`&${param}[${value}]=${params[param][value]}`}):'string'==typeof params[param]&&(_query+=`&${param}=${params[param]}`)};for(var param in params)_loop(param);return params?_query.slice(1):''}catch(E){error(E)}}_regeneratorRuntime=_regeneratorRuntime&&_regeneratorRuntime.hasOwnProperty('default')?_regeneratorRuntime['default']:_regeneratorRuntime,_slicedToArray=_slicedToArray&&_slicedToArray.hasOwnProperty('default')?_slicedToArray['default']:_slicedToArray,_asyncToGenerator=_asyncToGenerator&&_asyncToGenerator.hasOwnProperty('default')?_asyncToGenerator['default']:_asyncToGenerator,_classCallCheck=_classCallCheck&&_classCallCheck.hasOwnProperty('default')?_classCallCheck['default']:_classCallCheck,_createClass=_createClass&&_createClass.hasOwnProperty('default')?_createClass['default']:_createClass,axios=axios&&axios.hasOwnProperty('default')?axios['default']:axios;var deattribute=function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee2(data){var _this=this;return _regeneratorRuntime.wrap(function(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:if(_context2.prev=0,'object'!=typeof data||null===data){_context2.next=8;break}if(!Array.isArray(data)){_context2.next=7;break}return _context2.next=5,data.map(function(){var _ref2=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(el){return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.abrupt('return',deattribute(el));case 1:case'end':return _context.stop();}},_callee,_this)}));return function(){return _ref2.apply(this,arguments)}}());case 5:_context2.next=8;break;case 7:data.attributes&&data.attributes.constructor===Object&&(Object.keys(data.attributes).forEach(function(key){data[key]=data.attributes[key]}),delete data.attributes);case 8:return _context2.abrupt('return',data);case 11:_context2.prev=11,_context2.t0=_context2['catch'](0),error(_context2.t0);case 14:case'end':return _context2.stop();}},_callee2,this,[[0,11]])}));return function(){return _ref.apply(this,arguments)}}(),deserialiseArray=function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(obj){var _iteratorNormalCompletion,_didIteratorError,_iteratorError,_iterator,_step,value;return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.prev=0,_iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0,_context.prev=4,_context.next=7,obj.data;case 7:_context.t0=Symbol.iterator,_iterator=_context.sent[_context.t0]();case 9:if(_iteratorNormalCompletion=(_step=_iterator.next()).done){_context.next=23;break}if(value=_step.value,!obj.included){_context.next=15;break}return _context.next=14,linkRelationships(value,obj.included);case 14:value=_context.sent;case 15:if(!value.attributes){_context.next=19;break}return _context.next=18,deattribute(value);case 18:value=_context.sent;case 19:obj.data[obj.data.indexOf(value)]=value;case 20:_iteratorNormalCompletion=!0,_context.next=9;break;case 23:_context.next=29;break;case 25:_context.prev=25,_context.t1=_context['catch'](4),_didIteratorError=!0,_iteratorError=_context.t1;case 29:_context.prev=29,_context.prev=30,!_iteratorNormalCompletion&&_iterator.return&&_iterator.return();case 32:if(_context.prev=32,!_didIteratorError){_context.next=35;break}throw _iteratorError;case 35:return _context.finish(32);case 36:return _context.finish(29);case 37:return _context.abrupt('return',obj);case 40:_context.prev=40,_context.t2=_context['catch'](0),error(_context.t2);case 43:case'end':return _context.stop();}},_callee,this,[[0,40],[4,25,29,37],[30,,32,36]])}));return function(){return _ref.apply(this,arguments)}}(),deserialise=function(){var _ref2=_asyncToGenerator(_regeneratorRuntime.mark(function _callee2(obj){return _regeneratorRuntime.wrap(function(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:if(_context2.prev=0,!(obj.data&&obj.data.constructor===Array)){_context2.next=7;break}return _context2.next=4,deserialiseArray(obj);case 4:obj=_context2.sent,_context2.next=11;break;case 7:if(!obj.included){_context2.next=11;break}return _context2.next=10,linkRelationships(obj.data,obj.included);case 10:obj.data=_context2.sent;case 11:if(delete obj.included,!obj.data.attributes){_context2.next=16;break}return _context2.next=15,deattribute(obj.data);case 15:obj.data=_context2.sent;case 16:return _context2.abrupt('return',obj);case 19:_context2.prev=19,_context2.t0=_context2['catch'](0),error(_context2.t0);case 22:case'end':return _context2.stop();}},_callee2,this,[[0,19]])}));return function(){return _ref2.apply(this,arguments)}}(),filterIncludes=function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(included,_ref2){var id=_ref2.id,type=_ref2.type;return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.prev=0,_context.abrupt('return',included.filter(function(el){return el.id===id&&el.type===type})[0]||{id,type});case 4:_context.prev=4,_context.t0=_context['catch'](0),error(_context.t0);case 7:case'end':return _context.stop();}},_callee,this,[[0,4]])}));return function(){return _ref.apply(this,arguments)}}(),linkRelationships=function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(data,included){var relationships,key,_iteratorNormalCompletion,_didIteratorError,_iteratorError,_iterator,_step,_ref2,id,type,deattributed,_relationships$key$da,_id,_type,_deattributed;return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.prev=0,relationships=data.relationships,_context.next=4,relationships;case 4:_context.t0=_regeneratorRuntime.keys(_context.sent);case 5:if((_context.t1=_context.t0()).done){_context.next=59;break}if(key=_context.t1.value,!(relationships[key].data&&Array.isArray(relationships[key].data))){_context.next=46;break}return _iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0,_context.prev=11,_context.next=14,relationships[key].data;case 14:_context.t2=Symbol.iterator,_iterator=_context.sent[_context.t2]();case 16:if(_iteratorNormalCompletion=(_step=_iterator.next()).done){_context.next=30;break}return _ref2=_step.value,id=_ref2.id,type=_ref2.type,_context.t3=deattribute,_context.next=22,filterIncludes(included,{id,type});case 22:return _context.t4=_context.sent,_context.next=25,(0,_context.t3)(_context.t4);case 25:deattributed=_context.sent,'undefined'!=typeof deattributed&&(!data[key]&&(data[key]=[]),data[key].push(deattributed));case 27:_iteratorNormalCompletion=!0,_context.next=16;break;case 30:_context.next=36;break;case 32:_context.prev=32,_context.t5=_context['catch'](11),_didIteratorError=!0,_iteratorError=_context.t5;case 36:_context.prev=36,_context.prev=37,!_iteratorNormalCompletion&&_iterator.return&&_iterator.return();case 39:if(_context.prev=39,!_didIteratorError){_context.next=42;break}throw _iteratorError;case 42:return _context.finish(39);case 43:return _context.finish(36);case 44:_context.next=57;break;case 46:if(!relationships[key].data){_context.next=57;break}return _relationships$key$da=relationships[key].data,_id=_relationships$key$da.id,_type=_relationships$key$da.type,_context.t6=deattribute,_context.next=51,filterIncludes(included,{id:_id,type:_type});case 51:return _context.t7=_context.sent,_context.next=54,(0,_context.t6)(_context.t7);case 54:_deattributed=_context.sent,'undefined'==typeof _deattributed||data[key]||(data[key]=_deattributed),delete data[key].relationships;case 57:_context.next=5;break;case 59:return delete data.relationships,_context.abrupt('return',data);case 63:_context.prev=63,_context.t8=_context['catch'](0),error(_context.t8);case 66:case'end':return _context.stop();}},_callee,this,[[0,63],[11,32,36,44],[37,,39,43]])}));return function(){return _ref.apply(this,arguments)}}(),serialise=function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(model){var type,data,_loop,prop,_this=this,obj=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},method=2<arguments.length&&arguments[2]!==void 0?arguments[2]:'POST';return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:if(_context.prev=0,obj.constructor===Object&&0!==Object.keys(obj).length){_context.next=3;break}throw new Error(`${method} requires a JSON object body`);case 3:if(type=this.plural(this.camel(model)),data={type},'POST'===method||'undefined'!=typeof obj.id){_context.next=7;break}throw new Error(`${method} requires an ID for the ${type} type`);case 7:for(prop in'POST'!==method&&(data.id=obj.id.toString()),_loop=function(prop){if(null!==obj[prop]&&obj[prop].constructor===Object){if('string'==typeof obj[prop].id)'undefined'==typeof data.relationships&&(data.relationships={}),'undefined'==typeof obj[prop].type&&(obj[prop].type=_this.plural(_this.camel(prop))),data.relationships[prop]={data:Object.assign(obj[prop])};else throw new Error(`${method} requires an ID for the ${prop} relationships`);}else if(null!==obj[prop]&&Array.isArray(obj[prop])){var ptype=_this.plural(_this.camel(prop));'undefined'==typeof data.relationships&&(data.relationships={}),data.relationships[prop]={data:obj[prop].map(function(elem){if('undefined'==typeof elem.id)throw new Error(`${method} requires an ID for the ${prop} relationships`);return{id:elem.id,type:elem.type||ptype}})}}else'id'!==prop&&'type'!==prop&&('undefined'==typeof data.attributes&&(data.attributes={}),data.attributes[prop]=obj[prop])},obj)_loop(prop);return _context.abrupt('return',{data});case 13:throw _context.prev=13,_context.t0=_context['catch'](0),_context.t0;case 16:case'end':return _context.stop();}},_callee,this,[[0,13]])}));return function(){return _ref.apply(this,arguments)}}(),camel=function(s){return s.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g,function(match){return match.slice(1).toUpperCase()})},kebab=function(s){return s.charAt(0).toLowerCase()+s.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,function(match){return'-'+match.toLowerCase()})},snake=function(s){return s.charAt(0).toLowerCase()+s.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,function(match){return'_'+match.toLowerCase()})},jsonAPI='application/vnd.api+json',jsonAPIHeader={Accept:jsonAPI,"Content-Type":jsonAPI},Kitsu=function(){function Kitsu(){var options=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};_classCallCheck(this,Kitsu),this.fetch=this.get,this.update=this.patch,this.create=this.post,this.camel=!1===options.camelCaseTypes?function(s){return s}:camel,this.resCase='none'===options.resourceCase?function(s){return s}:'snake'===options.resourceCase?snake:kebab,this.plural=!1===options.pluralize?function(s){return s}:require('pluralize'),this.headers=Object.assign({},options.headers,jsonAPIHeader),axios.defaults.baseURL=options.baseURL||'https://kitsu.io/api/edge',axios.defaults.timeout=options.timeout||3e4}return _createClass(Kitsu,[{key:'get',value:function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(model){var _model$split,_model$split2,res,id,url,_ref2,data,params=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},headers=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.prev=0,_model$split=model.split('/'),_model$split2=_slicedToArray(_model$split,2),res=_model$split2[0],id=_model$split2[1],url=this.plural(this.resCase(res))+(id?'/'+id:''),_context.next=5,axios.get(url,{params,paramsSerializer:function(p){return query(p)},headers:Object.assign(this.headers,headers,jsonAPIHeader)});case 5:return _ref2=_context.sent,data=_ref2.data,_context.abrupt('return',deserialise(data));case 10:return _context.prev=10,_context.t0=_context['catch'](0),_context.abrupt('return',error(_context.t0));case 13:case'end':return _context.stop();}},_callee,this,[[0,10]])}));return function(){return _ref.apply(this,arguments)}}()},{key:'patch',value:function(){var _ref3=_asyncToGenerator(_regeneratorRuntime.mark(function _callee2(model,body){var url,_ref4,data,headers=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return _regeneratorRuntime.wrap(function(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:if(_context2.prev=0,headers=Object.assign(this.headers,headers,jsonAPIHeader),this.isAuth){_context2.next=4;break}throw new Error('Not logged in');case 4:if('undefined'!=typeof body.id){_context2.next=6;break}throw new Error('Updating a resource requires an ID');case 6:return url=this.plural(this.resCase(model))+'/'+body.id,_context2.t0=axios,_context2.t1=url,_context2.next=11,serialise.apply(this,[model,body,'PATCH']);case 11:return _context2.t2=_context2.sent,_context2.t3={headers},_context2.next=15,_context2.t0.patch.call(_context2.t0,_context2.t1,_context2.t2,_context2.t3);case 15:return _ref4=_context2.sent,data=_ref4.data,_context2.abrupt('return',data);case 20:return _context2.prev=20,_context2.t4=_context2['catch'](0),_context2.abrupt('return',error(_context2.t4));case 23:case'end':return _context2.stop();}},_callee2,this,[[0,20]])}));return function(){return _ref3.apply(this,arguments)}}()},{key:'post',value:function(){var _ref5=_asyncToGenerator(_regeneratorRuntime.mark(function _callee3(model,body){var url,_ref6,data,headers=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return _regeneratorRuntime.wrap(function(_context3){for(;;)switch(_context3.prev=_context3.next){case 0:if(_context3.prev=0,headers=Object.assign(this.headers,headers,jsonAPIHeader),this.isAuth){_context3.next=4;break}throw new Error('Not logged in');case 4:return url=this.plural(this.resCase(model)),_context3.t0=axios,_context3.t1=url,_context3.next=9,serialise.apply(this,[model,body]);case 9:return _context3.t2=_context3.sent,_context3.t3={headers},_context3.next=13,_context3.t0.post.call(_context3.t0,_context3.t1,_context3.t2,_context3.t3);case 13:return _ref6=_context3.sent,data=_ref6.data,_context3.abrupt('return',data);case 18:return _context3.prev=18,_context3.t4=_context3['catch'](0),_context3.abrupt('return',error(_context3.t4));case 21:case'end':return _context3.stop();}},_callee3,this,[[0,18]])}));return function(){return _ref5.apply(this,arguments)}}()},{key:'remove',value:function(){var _ref7=_asyncToGenerator(_regeneratorRuntime.mark(function _callee4(model,id){var url,_ref8,data,headers=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return _regeneratorRuntime.wrap(function(_context4){for(;;)switch(_context4.prev=_context4.next){case 0:if(_context4.prev=0,headers=Object.assign(this.headers,headers,jsonAPIHeader),this.isAuth){_context4.next=4;break}throw new Error('Not logged in');case 4:return url=this.plural(this.resCase(model))+'/'+id,_context4.t0=axios,_context4.t1=url,_context4.next=9,serialise.apply(this,[model,{id},'DELETE']);case 9:return _context4.t2=_context4.sent,_context4.t3=headers,_context4.t4={data:_context4.t2,headers:_context4.t3},_context4.next=14,_context4.t0.delete.call(_context4.t0,_context4.t1,_context4.t4);case 14:return _ref8=_context4.sent,data=_ref8.data,_context4.abrupt('return',data);case 19:return _context4.prev=19,_context4.t5=_context4['catch'](0),_context4.abrupt('return',error(_context4.t5));case 22:case'end':return _context4.stop();}},_callee4,this,[[0,19]])}));return function(){return _ref7.apply(this,arguments)}}()},{key:'self',value:function(){var _ref9=_asyncToGenerator(_regeneratorRuntime.mark(function _callee5(){var res,params=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},headers=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return _regeneratorRuntime.wrap(function(_context5){for(;;)switch(_context5.prev=_context5.next){case 0:return _context5.prev=0,_context5.next=3,this.get('users',Object.assign({filter:{self:!0}},params),headers);case 3:if(res=_context5.sent,!res.errors){_context5.next=6;break}throw res;case 6:return _context5.abrupt('return',res.data[0]);case 9:return _context5.prev=9,_context5.t0=_context5['catch'](0),_context5.abrupt('return',error(_context5.t0));case 12:case'end':return _context5.stop();}},_callee5,this,[[0,9]])}));return function(){return _ref9.apply(this,arguments)}}()},{key:'isAuth',get:function(){return!!this.headers.Authorization}}]),Kitsu}();return Kitsu});

@@ -1,1 +0,1 @@

(function(global,factory){'object'==typeof exports&&'undefined'!=typeof module?module.exports=factory(require('babel-runtime/regenerator'),require('babel-runtime/helpers/slicedToArray'),require('babel-runtime/helpers/asyncToGenerator'),require('babel-runtime/helpers/classCallCheck'),require('babel-runtime/helpers/createClass'),require('axios'),require('babel-runtime/helpers/typeof')):'function'==typeof define&&define.amd?define(['babel-runtime/regenerator','babel-runtime/helpers/slicedToArray','babel-runtime/helpers/asyncToGenerator','babel-runtime/helpers/classCallCheck','babel-runtime/helpers/createClass','axios','babel-runtime/helpers/typeof'],factory):global.kitsu=factory(global._regeneratorRuntime,global._slicedToArray,global._asyncToGenerator,global._classCallCheck,global._createClass,global.axios,global._typeof)})(this,function(_regeneratorRuntime,_slicedToArray,_asyncToGenerator,_classCallCheck,_createClass,axios,_typeof){'use strict';function error(E){if(E.response){var e=E.response.data;if(e)return e}else if(E.errors)return E;throw E}function query(params){try{var _query='',_loop=function(param){'object'===_typeof(params[param])?Object.keys(params[param]).forEach(function(value){_query+='&'+param+'['+value+']='+params[param][value]}):'string'==typeof params[param]&&(_query+='&'+param+'='+params[param])};for(var param in params)_loop(param);return params?_query.slice(1):''}catch(E){error(E)}}_regeneratorRuntime=_regeneratorRuntime&&_regeneratorRuntime.hasOwnProperty('default')?_regeneratorRuntime['default']:_regeneratorRuntime,_slicedToArray=_slicedToArray&&_slicedToArray.hasOwnProperty('default')?_slicedToArray['default']:_slicedToArray,_asyncToGenerator=_asyncToGenerator&&_asyncToGenerator.hasOwnProperty('default')?_asyncToGenerator['default']:_asyncToGenerator,_classCallCheck=_classCallCheck&&_classCallCheck.hasOwnProperty('default')?_classCallCheck['default']:_classCallCheck,_createClass=_createClass&&_createClass.hasOwnProperty('default')?_createClass['default']:_createClass,axios=axios&&axios.hasOwnProperty('default')?axios['default']:axios,_typeof=_typeof&&_typeof.hasOwnProperty('default')?_typeof['default']:_typeof;var deattribute=function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee2(data){var _this=this;return _regeneratorRuntime.wrap(function(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:if(_context2.prev=0,'object'!==('undefined'==typeof data?'undefined':_typeof(data))||null===data){_context2.next=8;break}if(!Array.isArray(data)){_context2.next=7;break}return _context2.next=5,data.map(function(){var _ref2=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(el){return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.abrupt('return',deattribute(el));case 1:case'end':return _context.stop();}},_callee,_this)}));return function(){return _ref2.apply(this,arguments)}}());case 5:_context2.next=8;break;case 7:data.attributes&&data.attributes.constructor===Object&&(Object.keys(data.attributes).forEach(function(key){data[key]=data.attributes[key]}),delete data.attributes);case 8:return _context2.abrupt('return',data);case 11:_context2.prev=11,_context2.t0=_context2['catch'](0),error(_context2.t0);case 14:case'end':return _context2.stop();}},_callee2,this,[[0,11]])}));return function(){return _ref.apply(this,arguments)}}(),deserialiseArray=function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(obj){var _iteratorNormalCompletion,_didIteratorError,_iteratorError,_iterator,_step,value;return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.prev=0,_iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0,_context.prev=4,_context.next=7,obj.data;case 7:_context.t0=Symbol.iterator,_iterator=_context.sent[_context.t0]();case 9:if(_iteratorNormalCompletion=(_step=_iterator.next()).done){_context.next=23;break}if(value=_step.value,!obj.included){_context.next=15;break}return _context.next=14,linkRelationships(value,obj.included);case 14:value=_context.sent;case 15:if(!value.attributes){_context.next=19;break}return _context.next=18,deattribute(value);case 18:value=_context.sent;case 19:obj.data[obj.data.indexOf(value)]=value;case 20:_iteratorNormalCompletion=!0,_context.next=9;break;case 23:_context.next=29;break;case 25:_context.prev=25,_context.t1=_context['catch'](4),_didIteratorError=!0,_iteratorError=_context.t1;case 29:_context.prev=29,_context.prev=30,!_iteratorNormalCompletion&&_iterator.return&&_iterator.return();case 32:if(_context.prev=32,!_didIteratorError){_context.next=35;break}throw _iteratorError;case 35:return _context.finish(32);case 36:return _context.finish(29);case 37:return _context.abrupt('return',obj);case 40:_context.prev=40,_context.t2=_context['catch'](0),error(_context.t2);case 43:case'end':return _context.stop();}},_callee,this,[[0,40],[4,25,29,37],[30,,32,36]])}));return function(){return _ref.apply(this,arguments)}}(),deserialise=function(){var _ref2=_asyncToGenerator(_regeneratorRuntime.mark(function _callee2(obj){return _regeneratorRuntime.wrap(function(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:if(_context2.prev=0,!(obj.data&&obj.data.constructor===Array)){_context2.next=7;break}return _context2.next=4,deserialiseArray(obj);case 4:obj=_context2.sent,_context2.next=11;break;case 7:if(!obj.included){_context2.next=11;break}return _context2.next=10,linkRelationships(obj.data,obj.included);case 10:obj.data=_context2.sent;case 11:if(delete obj.included,!obj.data.attributes){_context2.next=16;break}return _context2.next=15,deattribute(obj.data);case 15:obj.data=_context2.sent;case 16:return _context2.abrupt('return',obj);case 19:_context2.prev=19,_context2.t0=_context2['catch'](0),error(_context2.t0);case 22:case'end':return _context2.stop();}},_callee2,this,[[0,19]])}));return function(){return _ref2.apply(this,arguments)}}(),filterIncludes=function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(included,_ref2){var id=_ref2.id,type=_ref2.type;return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.prev=0,_context.abrupt('return',included.filter(function(el){return el.id===id&&el.type===type})[0]||{id:id,type:type});case 4:_context.prev=4,_context.t0=_context['catch'](0),error(_context.t0);case 7:case'end':return _context.stop();}},_callee,this,[[0,4]])}));return function(){return _ref.apply(this,arguments)}}(),linkRelationships=function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(data,included){var relationships,key,_iteratorNormalCompletion,_didIteratorError,_iteratorError,_iterator,_step,_ref2,id,type,deattributed,_relationships$key$da,_id,_type,_deattributed;return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.prev=0,relationships=data.relationships,_context.next=4,relationships;case 4:_context.t0=_regeneratorRuntime.keys(_context.sent);case 5:if((_context.t1=_context.t0()).done){_context.next=59;break}if(key=_context.t1.value,!(relationships[key].data&&Array.isArray(relationships[key].data))){_context.next=46;break}return _iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0,_context.prev=11,_context.next=14,relationships[key].data;case 14:_context.t2=Symbol.iterator,_iterator=_context.sent[_context.t2]();case 16:if(_iteratorNormalCompletion=(_step=_iterator.next()).done){_context.next=30;break}return _ref2=_step.value,id=_ref2.id,type=_ref2.type,_context.t3=deattribute,_context.next=22,filterIncludes(included,{id:id,type:type});case 22:return _context.t4=_context.sent,_context.next=25,(0,_context.t3)(_context.t4);case 25:deattributed=_context.sent,'undefined'!=typeof deattributed&&(!data[key]&&(data[key]=[]),data[key].push(deattributed));case 27:_iteratorNormalCompletion=!0,_context.next=16;break;case 30:_context.next=36;break;case 32:_context.prev=32,_context.t5=_context['catch'](11),_didIteratorError=!0,_iteratorError=_context.t5;case 36:_context.prev=36,_context.prev=37,!_iteratorNormalCompletion&&_iterator.return&&_iterator.return();case 39:if(_context.prev=39,!_didIteratorError){_context.next=42;break}throw _iteratorError;case 42:return _context.finish(39);case 43:return _context.finish(36);case 44:_context.next=57;break;case 46:if(!relationships[key].data){_context.next=57;break}return _relationships$key$da=relationships[key].data,_id=_relationships$key$da.id,_type=_relationships$key$da.type,_context.t6=deattribute,_context.next=51,filterIncludes(included,{id:_id,type:_type});case 51:return _context.t7=_context.sent,_context.next=54,(0,_context.t6)(_context.t7);case 54:_deattributed=_context.sent,'undefined'==typeof _deattributed||data[key]||(data[key]=_deattributed),delete data[key].relationships;case 57:_context.next=5;break;case 59:return delete data.relationships,_context.abrupt('return',data);case 63:_context.prev=63,_context.t8=_context['catch'](0),error(_context.t8);case 66:case'end':return _context.stop();}},_callee,this,[[0,63],[11,32,36,44],[37,,39,43]])}));return function(){return _ref.apply(this,arguments)}}(),serialise=function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(model){var type,data,_loop,prop,_this=this,obj=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},method=2<arguments.length&&arguments[2]!==void 0?arguments[2]:'POST';return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:if(_context.prev=0,obj.constructor===Object&&0!==Object.keys(obj).length){_context.next=3;break}throw new Error(method+' requires a JSON object body');case 3:if(type=this.plural(this.camel(model)),data={type:type},'POST'===method||'undefined'!=typeof obj.id){_context.next=7;break}throw new Error(method+' requires an ID for the '+type+' type');case 7:for(prop in'POST'!==method&&(data.id=obj.id.toString()),_loop=function(prop){if(null!==obj[prop]&&obj[prop].constructor===Object){if('string'==typeof obj[prop].id)'undefined'==typeof data.relationships&&(data.relationships={}),'undefined'==typeof obj[prop].type&&(obj[prop].type=_this.plural(_this.camel(prop))),data.relationships[prop]={data:Object.assign(obj[prop])};else throw new Error(method+' requires an ID for the '+prop+' relationships');}else if(null!==obj[prop]&&Array.isArray(obj[prop])){var ptype=_this.plural(_this.camel(prop));'undefined'==typeof data.relationships&&(data.relationships={}),data.relationships[prop]={data:obj[prop].map(function(elem){if('undefined'==typeof elem.id)throw new Error(method+' requires an ID for the '+prop+' relationships');return{id:elem.id,type:elem.type||ptype}})}}else'id'!==prop&&'type'!==prop&&('undefined'==typeof data.attributes&&(data.attributes={}),data.attributes[prop]=obj[prop])},obj)_loop(prop);return _context.abrupt('return',{data:data});case 13:throw _context.prev=13,_context.t0=_context['catch'](0),_context.t0;case 16:case'end':return _context.stop();}},_callee,this,[[0,13]])}));return function(){return _ref.apply(this,arguments)}}(),camel=function(s){return s.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g,function(match){return match.slice(1).toUpperCase()})},kebab=function(s){return s.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,function(match){return'-'+match.toLowerCase()})},snake=function(s){return s.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,function(match){return'_'+match.toLowerCase()})},jsonAPI='application/vnd.api+json',jsonAPIHeader={Accept:jsonAPI,"Content-Type":jsonAPI},Kitsu=function(){function Kitsu(){var options=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};_classCallCheck(this,Kitsu),this.fetch=this.get,this.update=this.patch,this.create=this.post,this.camel=!1===options.camelCaseTypes?function(s){return s}:camel,this.resCase='none'===options.resourceCase?function(s){return s}:'snake'===options.resourceCase?snake:kebab,this.plural=!1===options.pluralize?function(s){return s}:require('pluralize'),this.headers=Object.assign({},options.headers,jsonAPIHeader),axios.defaults.baseURL=options.baseURL||'https://kitsu.io/api/edge',axios.defaults.timeout=options.timeout||3e4}return _createClass(Kitsu,[{key:'get',value:function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(model){var _model$split,_model$split2,res,id,url,_ref2,data,params=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},headers=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.prev=0,_model$split=model.split('/'),_model$split2=_slicedToArray(_model$split,2),res=_model$split2[0],id=_model$split2[1],url=this.plural(this.resCase(res))+(id?'/'+id:''),_context.next=5,axios.get(url,{params:params,paramsSerializer:function(p){return query(p)},headers:Object.assign(this.headers,headers,jsonAPIHeader)});case 5:return _ref2=_context.sent,data=_ref2.data,_context.abrupt('return',deserialise(data));case 10:return _context.prev=10,_context.t0=_context['catch'](0),_context.abrupt('return',error(_context.t0));case 13:case'end':return _context.stop();}},_callee,this,[[0,10]])}));return function(){return _ref.apply(this,arguments)}}()},{key:'patch',value:function(){var _ref3=_asyncToGenerator(_regeneratorRuntime.mark(function _callee2(model,body){var url,_ref4,data,headers=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return _regeneratorRuntime.wrap(function(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:if(_context2.prev=0,headers=Object.assign(this.headers,headers,jsonAPIHeader),this.isAuth){_context2.next=4;break}throw new Error('Not logged in');case 4:if('undefined'!=typeof body.id){_context2.next=6;break}throw new Error('Updating a resource requires an ID');case 6:return url=this.plural(this.resCase(model))+'/'+body.id,_context2.t0=axios,_context2.t1=url,_context2.next=11,serialise.apply(this,[model,body,'PATCH']);case 11:return _context2.t2=_context2.sent,_context2.t3={headers:headers},_context2.next=15,_context2.t0.patch.call(_context2.t0,_context2.t1,_context2.t2,_context2.t3);case 15:return _ref4=_context2.sent,data=_ref4.data,_context2.abrupt('return',data);case 20:return _context2.prev=20,_context2.t4=_context2['catch'](0),_context2.abrupt('return',error(_context2.t4));case 23:case'end':return _context2.stop();}},_callee2,this,[[0,20]])}));return function(){return _ref3.apply(this,arguments)}}()},{key:'post',value:function(){var _ref5=_asyncToGenerator(_regeneratorRuntime.mark(function _callee3(model,body){var url,_ref6,data,headers=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return _regeneratorRuntime.wrap(function(_context3){for(;;)switch(_context3.prev=_context3.next){case 0:if(_context3.prev=0,headers=Object.assign(this.headers,headers,jsonAPIHeader),this.isAuth){_context3.next=4;break}throw new Error('Not logged in');case 4:return url=this.plural(this.resCase(model)),_context3.t0=axios,_context3.t1=url,_context3.next=9,serialise.apply(this,[model,body]);case 9:return _context3.t2=_context3.sent,_context3.t3={headers:headers},_context3.next=13,_context3.t0.post.call(_context3.t0,_context3.t1,_context3.t2,_context3.t3);case 13:return _ref6=_context3.sent,data=_ref6.data,_context3.abrupt('return',data);case 18:return _context3.prev=18,_context3.t4=_context3['catch'](0),_context3.abrupt('return',error(_context3.t4));case 21:case'end':return _context3.stop();}},_callee3,this,[[0,18]])}));return function(){return _ref5.apply(this,arguments)}}()},{key:'remove',value:function(){var _ref7=_asyncToGenerator(_regeneratorRuntime.mark(function _callee4(model,id){var url,_ref8,data,headers=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return _regeneratorRuntime.wrap(function(_context4){for(;;)switch(_context4.prev=_context4.next){case 0:if(_context4.prev=0,headers=Object.assign(this.headers,headers,jsonAPIHeader),this.isAuth){_context4.next=4;break}throw new Error('Not logged in');case 4:return url=this.plural(this.resCase(model))+'/'+id,_context4.t0=axios,_context4.t1=url,_context4.next=9,serialise.apply(this,[model,{id:id},'DELETE']);case 9:return _context4.t2=_context4.sent,_context4.t3=headers,_context4.t4={data:_context4.t2,headers:_context4.t3},_context4.next=14,_context4.t0.delete.call(_context4.t0,_context4.t1,_context4.t4);case 14:return _ref8=_context4.sent,data=_ref8.data,_context4.abrupt('return',data);case 19:return _context4.prev=19,_context4.t5=_context4['catch'](0),_context4.abrupt('return',error(_context4.t5));case 22:case'end':return _context4.stop();}},_callee4,this,[[0,19]])}));return function(){return _ref7.apply(this,arguments)}}()},{key:'self',value:function(){var _ref9=_asyncToGenerator(_regeneratorRuntime.mark(function _callee5(){var res,params=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},headers=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return _regeneratorRuntime.wrap(function(_context5){for(;;)switch(_context5.prev=_context5.next){case 0:return _context5.prev=0,_context5.next=3,this.get('users',Object.assign({filter:{self:!0}},params),headers);case 3:if(res=_context5.sent,!res.errors){_context5.next=6;break}throw res;case 6:return _context5.abrupt('return',res.data[0]);case 9:return _context5.prev=9,_context5.t0=_context5['catch'](0),_context5.abrupt('return',error(_context5.t0));case 12:case'end':return _context5.stop();}},_callee5,this,[[0,9]])}));return function(){return _ref9.apply(this,arguments)}}()},{key:'isAuth',get:function(){return!!this.headers.Authorization}}]),Kitsu}();return Kitsu});
(function(global,factory){'object'==typeof exports&&'undefined'!=typeof module?module.exports=factory(require('babel-runtime/regenerator'),require('babel-runtime/helpers/slicedToArray'),require('babel-runtime/helpers/asyncToGenerator'),require('babel-runtime/helpers/classCallCheck'),require('babel-runtime/helpers/createClass'),require('axios'),require('babel-runtime/helpers/typeof')):'function'==typeof define&&define.amd?define(['babel-runtime/regenerator','babel-runtime/helpers/slicedToArray','babel-runtime/helpers/asyncToGenerator','babel-runtime/helpers/classCallCheck','babel-runtime/helpers/createClass','axios','babel-runtime/helpers/typeof'],factory):global.kitsu=factory(global._regeneratorRuntime,global._slicedToArray,global._asyncToGenerator,global._classCallCheck,global._createClass,global.axios,global._typeof)})(this,function(_regeneratorRuntime,_slicedToArray,_asyncToGenerator,_classCallCheck,_createClass,axios,_typeof){'use strict';function error(E){if(E.response){var e=E.response.data;if(e)return e}else if(E.errors)return E;throw E}function query(params){try{var _query='',_loop=function(param){'object'===_typeof(params[param])?Object.keys(params[param]).forEach(function(value){_query+='&'+param+'['+value+']='+params[param][value]}):'string'==typeof params[param]&&(_query+='&'+param+'='+params[param])};for(var param in params)_loop(param);return params?_query.slice(1):''}catch(E){error(E)}}_regeneratorRuntime=_regeneratorRuntime&&_regeneratorRuntime.hasOwnProperty('default')?_regeneratorRuntime['default']:_regeneratorRuntime,_slicedToArray=_slicedToArray&&_slicedToArray.hasOwnProperty('default')?_slicedToArray['default']:_slicedToArray,_asyncToGenerator=_asyncToGenerator&&_asyncToGenerator.hasOwnProperty('default')?_asyncToGenerator['default']:_asyncToGenerator,_classCallCheck=_classCallCheck&&_classCallCheck.hasOwnProperty('default')?_classCallCheck['default']:_classCallCheck,_createClass=_createClass&&_createClass.hasOwnProperty('default')?_createClass['default']:_createClass,axios=axios&&axios.hasOwnProperty('default')?axios['default']:axios,_typeof=_typeof&&_typeof.hasOwnProperty('default')?_typeof['default']:_typeof;var deattribute=function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee2(data){var _this=this;return _regeneratorRuntime.wrap(function(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:if(_context2.prev=0,'object'!==('undefined'==typeof data?'undefined':_typeof(data))||null===data){_context2.next=8;break}if(!Array.isArray(data)){_context2.next=7;break}return _context2.next=5,data.map(function(){var _ref2=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(el){return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.abrupt('return',deattribute(el));case 1:case'end':return _context.stop();}},_callee,_this)}));return function(){return _ref2.apply(this,arguments)}}());case 5:_context2.next=8;break;case 7:data.attributes&&data.attributes.constructor===Object&&(Object.keys(data.attributes).forEach(function(key){data[key]=data.attributes[key]}),delete data.attributes);case 8:return _context2.abrupt('return',data);case 11:_context2.prev=11,_context2.t0=_context2['catch'](0),error(_context2.t0);case 14:case'end':return _context2.stop();}},_callee2,this,[[0,11]])}));return function(){return _ref.apply(this,arguments)}}(),deserialiseArray=function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(obj){var _iteratorNormalCompletion,_didIteratorError,_iteratorError,_iterator,_step,value;return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.prev=0,_iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0,_context.prev=4,_context.next=7,obj.data;case 7:_context.t0=Symbol.iterator,_iterator=_context.sent[_context.t0]();case 9:if(_iteratorNormalCompletion=(_step=_iterator.next()).done){_context.next=23;break}if(value=_step.value,!obj.included){_context.next=15;break}return _context.next=14,linkRelationships(value,obj.included);case 14:value=_context.sent;case 15:if(!value.attributes){_context.next=19;break}return _context.next=18,deattribute(value);case 18:value=_context.sent;case 19:obj.data[obj.data.indexOf(value)]=value;case 20:_iteratorNormalCompletion=!0,_context.next=9;break;case 23:_context.next=29;break;case 25:_context.prev=25,_context.t1=_context['catch'](4),_didIteratorError=!0,_iteratorError=_context.t1;case 29:_context.prev=29,_context.prev=30,!_iteratorNormalCompletion&&_iterator.return&&_iterator.return();case 32:if(_context.prev=32,!_didIteratorError){_context.next=35;break}throw _iteratorError;case 35:return _context.finish(32);case 36:return _context.finish(29);case 37:return _context.abrupt('return',obj);case 40:_context.prev=40,_context.t2=_context['catch'](0),error(_context.t2);case 43:case'end':return _context.stop();}},_callee,this,[[0,40],[4,25,29,37],[30,,32,36]])}));return function(){return _ref.apply(this,arguments)}}(),deserialise=function(){var _ref2=_asyncToGenerator(_regeneratorRuntime.mark(function _callee2(obj){return _regeneratorRuntime.wrap(function(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:if(_context2.prev=0,!(obj.data&&obj.data.constructor===Array)){_context2.next=7;break}return _context2.next=4,deserialiseArray(obj);case 4:obj=_context2.sent,_context2.next=11;break;case 7:if(!obj.included){_context2.next=11;break}return _context2.next=10,linkRelationships(obj.data,obj.included);case 10:obj.data=_context2.sent;case 11:if(delete obj.included,!obj.data.attributes){_context2.next=16;break}return _context2.next=15,deattribute(obj.data);case 15:obj.data=_context2.sent;case 16:return _context2.abrupt('return',obj);case 19:_context2.prev=19,_context2.t0=_context2['catch'](0),error(_context2.t0);case 22:case'end':return _context2.stop();}},_callee2,this,[[0,19]])}));return function(){return _ref2.apply(this,arguments)}}(),filterIncludes=function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(included,_ref2){var id=_ref2.id,type=_ref2.type;return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.prev=0,_context.abrupt('return',included.filter(function(el){return el.id===id&&el.type===type})[0]||{id:id,type:type});case 4:_context.prev=4,_context.t0=_context['catch'](0),error(_context.t0);case 7:case'end':return _context.stop();}},_callee,this,[[0,4]])}));return function(){return _ref.apply(this,arguments)}}(),linkRelationships=function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(data,included){var relationships,key,_iteratorNormalCompletion,_didIteratorError,_iteratorError,_iterator,_step,_ref2,id,type,deattributed,_relationships$key$da,_id,_type,_deattributed;return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.prev=0,relationships=data.relationships,_context.next=4,relationships;case 4:_context.t0=_regeneratorRuntime.keys(_context.sent);case 5:if((_context.t1=_context.t0()).done){_context.next=59;break}if(key=_context.t1.value,!(relationships[key].data&&Array.isArray(relationships[key].data))){_context.next=46;break}return _iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0,_context.prev=11,_context.next=14,relationships[key].data;case 14:_context.t2=Symbol.iterator,_iterator=_context.sent[_context.t2]();case 16:if(_iteratorNormalCompletion=(_step=_iterator.next()).done){_context.next=30;break}return _ref2=_step.value,id=_ref2.id,type=_ref2.type,_context.t3=deattribute,_context.next=22,filterIncludes(included,{id:id,type:type});case 22:return _context.t4=_context.sent,_context.next=25,(0,_context.t3)(_context.t4);case 25:deattributed=_context.sent,'undefined'!=typeof deattributed&&(!data[key]&&(data[key]=[]),data[key].push(deattributed));case 27:_iteratorNormalCompletion=!0,_context.next=16;break;case 30:_context.next=36;break;case 32:_context.prev=32,_context.t5=_context['catch'](11),_didIteratorError=!0,_iteratorError=_context.t5;case 36:_context.prev=36,_context.prev=37,!_iteratorNormalCompletion&&_iterator.return&&_iterator.return();case 39:if(_context.prev=39,!_didIteratorError){_context.next=42;break}throw _iteratorError;case 42:return _context.finish(39);case 43:return _context.finish(36);case 44:_context.next=57;break;case 46:if(!relationships[key].data){_context.next=57;break}return _relationships$key$da=relationships[key].data,_id=_relationships$key$da.id,_type=_relationships$key$da.type,_context.t6=deattribute,_context.next=51,filterIncludes(included,{id:_id,type:_type});case 51:return _context.t7=_context.sent,_context.next=54,(0,_context.t6)(_context.t7);case 54:_deattributed=_context.sent,'undefined'==typeof _deattributed||data[key]||(data[key]=_deattributed),delete data[key].relationships;case 57:_context.next=5;break;case 59:return delete data.relationships,_context.abrupt('return',data);case 63:_context.prev=63,_context.t8=_context['catch'](0),error(_context.t8);case 66:case'end':return _context.stop();}},_callee,this,[[0,63],[11,32,36,44],[37,,39,43]])}));return function(){return _ref.apply(this,arguments)}}(),serialise=function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(model){var type,data,_loop,prop,_this=this,obj=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},method=2<arguments.length&&arguments[2]!==void 0?arguments[2]:'POST';return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:if(_context.prev=0,obj.constructor===Object&&0!==Object.keys(obj).length){_context.next=3;break}throw new Error(method+' requires a JSON object body');case 3:if(type=this.plural(this.camel(model)),data={type:type},'POST'===method||'undefined'!=typeof obj.id){_context.next=7;break}throw new Error(method+' requires an ID for the '+type+' type');case 7:for(prop in'POST'!==method&&(data.id=obj.id.toString()),_loop=function(prop){if(null!==obj[prop]&&obj[prop].constructor===Object){if('string'==typeof obj[prop].id)'undefined'==typeof data.relationships&&(data.relationships={}),'undefined'==typeof obj[prop].type&&(obj[prop].type=_this.plural(_this.camel(prop))),data.relationships[prop]={data:Object.assign(obj[prop])};else throw new Error(method+' requires an ID for the '+prop+' relationships');}else if(null!==obj[prop]&&Array.isArray(obj[prop])){var ptype=_this.plural(_this.camel(prop));'undefined'==typeof data.relationships&&(data.relationships={}),data.relationships[prop]={data:obj[prop].map(function(elem){if('undefined'==typeof elem.id)throw new Error(method+' requires an ID for the '+prop+' relationships');return{id:elem.id,type:elem.type||ptype}})}}else'id'!==prop&&'type'!==prop&&('undefined'==typeof data.attributes&&(data.attributes={}),data.attributes[prop]=obj[prop])},obj)_loop(prop);return _context.abrupt('return',{data:data});case 13:throw _context.prev=13,_context.t0=_context['catch'](0),_context.t0;case 16:case'end':return _context.stop();}},_callee,this,[[0,13]])}));return function(){return _ref.apply(this,arguments)}}(),camel=function(s){return s.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g,function(match){return match.slice(1).toUpperCase()})},kebab=function(s){return s.charAt(0).toLowerCase()+s.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,function(match){return'-'+match.toLowerCase()})},snake=function(s){return s.charAt(0).toLowerCase()+s.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,function(match){return'_'+match.toLowerCase()})},jsonAPI='application/vnd.api+json',jsonAPIHeader={Accept:jsonAPI,"Content-Type":jsonAPI},Kitsu=function(){function Kitsu(){var options=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};_classCallCheck(this,Kitsu),this.fetch=this.get,this.update=this.patch,this.create=this.post,this.camel=!1===options.camelCaseTypes?function(s){return s}:camel,this.resCase='none'===options.resourceCase?function(s){return s}:'snake'===options.resourceCase?snake:kebab,this.plural=!1===options.pluralize?function(s){return s}:require('pluralize'),this.headers=Object.assign({},options.headers,jsonAPIHeader),axios.defaults.baseURL=options.baseURL||'https://kitsu.io/api/edge',axios.defaults.timeout=options.timeout||3e4}return _createClass(Kitsu,[{key:'get',value:function(){var _ref=_asyncToGenerator(_regeneratorRuntime.mark(function _callee(model){var _model$split,_model$split2,res,id,url,_ref2,data,params=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},headers=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return _regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.prev=0,_model$split=model.split('/'),_model$split2=_slicedToArray(_model$split,2),res=_model$split2[0],id=_model$split2[1],url=this.plural(this.resCase(res))+(id?'/'+id:''),_context.next=5,axios.get(url,{params:params,paramsSerializer:function(p){return query(p)},headers:Object.assign(this.headers,headers,jsonAPIHeader)});case 5:return _ref2=_context.sent,data=_ref2.data,_context.abrupt('return',deserialise(data));case 10:return _context.prev=10,_context.t0=_context['catch'](0),_context.abrupt('return',error(_context.t0));case 13:case'end':return _context.stop();}},_callee,this,[[0,10]])}));return function(){return _ref.apply(this,arguments)}}()},{key:'patch',value:function(){var _ref3=_asyncToGenerator(_regeneratorRuntime.mark(function _callee2(model,body){var url,_ref4,data,headers=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return _regeneratorRuntime.wrap(function(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:if(_context2.prev=0,headers=Object.assign(this.headers,headers,jsonAPIHeader),this.isAuth){_context2.next=4;break}throw new Error('Not logged in');case 4:if('undefined'!=typeof body.id){_context2.next=6;break}throw new Error('Updating a resource requires an ID');case 6:return url=this.plural(this.resCase(model))+'/'+body.id,_context2.t0=axios,_context2.t1=url,_context2.next=11,serialise.apply(this,[model,body,'PATCH']);case 11:return _context2.t2=_context2.sent,_context2.t3={headers:headers},_context2.next=15,_context2.t0.patch.call(_context2.t0,_context2.t1,_context2.t2,_context2.t3);case 15:return _ref4=_context2.sent,data=_ref4.data,_context2.abrupt('return',data);case 20:return _context2.prev=20,_context2.t4=_context2['catch'](0),_context2.abrupt('return',error(_context2.t4));case 23:case'end':return _context2.stop();}},_callee2,this,[[0,20]])}));return function(){return _ref3.apply(this,arguments)}}()},{key:'post',value:function(){var _ref5=_asyncToGenerator(_regeneratorRuntime.mark(function _callee3(model,body){var url,_ref6,data,headers=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return _regeneratorRuntime.wrap(function(_context3){for(;;)switch(_context3.prev=_context3.next){case 0:if(_context3.prev=0,headers=Object.assign(this.headers,headers,jsonAPIHeader),this.isAuth){_context3.next=4;break}throw new Error('Not logged in');case 4:return url=this.plural(this.resCase(model)),_context3.t0=axios,_context3.t1=url,_context3.next=9,serialise.apply(this,[model,body]);case 9:return _context3.t2=_context3.sent,_context3.t3={headers:headers},_context3.next=13,_context3.t0.post.call(_context3.t0,_context3.t1,_context3.t2,_context3.t3);case 13:return _ref6=_context3.sent,data=_ref6.data,_context3.abrupt('return',data);case 18:return _context3.prev=18,_context3.t4=_context3['catch'](0),_context3.abrupt('return',error(_context3.t4));case 21:case'end':return _context3.stop();}},_callee3,this,[[0,18]])}));return function(){return _ref5.apply(this,arguments)}}()},{key:'remove',value:function(){var _ref7=_asyncToGenerator(_regeneratorRuntime.mark(function _callee4(model,id){var url,_ref8,data,headers=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return _regeneratorRuntime.wrap(function(_context4){for(;;)switch(_context4.prev=_context4.next){case 0:if(_context4.prev=0,headers=Object.assign(this.headers,headers,jsonAPIHeader),this.isAuth){_context4.next=4;break}throw new Error('Not logged in');case 4:return url=this.plural(this.resCase(model))+'/'+id,_context4.t0=axios,_context4.t1=url,_context4.next=9,serialise.apply(this,[model,{id:id},'DELETE']);case 9:return _context4.t2=_context4.sent,_context4.t3=headers,_context4.t4={data:_context4.t2,headers:_context4.t3},_context4.next=14,_context4.t0.delete.call(_context4.t0,_context4.t1,_context4.t4);case 14:return _ref8=_context4.sent,data=_ref8.data,_context4.abrupt('return',data);case 19:return _context4.prev=19,_context4.t5=_context4['catch'](0),_context4.abrupt('return',error(_context4.t5));case 22:case'end':return _context4.stop();}},_callee4,this,[[0,19]])}));return function(){return _ref7.apply(this,arguments)}}()},{key:'self',value:function(){var _ref9=_asyncToGenerator(_regeneratorRuntime.mark(function _callee5(){var res,params=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},headers=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return _regeneratorRuntime.wrap(function(_context5){for(;;)switch(_context5.prev=_context5.next){case 0:return _context5.prev=0,_context5.next=3,this.get('users',Object.assign({filter:{self:!0}},params),headers);case 3:if(res=_context5.sent,!res.errors){_context5.next=6;break}throw res;case 6:return _context5.abrupt('return',res.data[0]);case 9:return _context5.prev=9,_context5.t0=_context5['catch'](0),_context5.abrupt('return',error(_context5.t0));case 12:case'end':return _context5.stop();}},_callee5,this,[[0,9]])}));return function(){return _ref9.apply(this,arguments)}}()},{key:'isAuth',get:function(){return!!this.headers.Authorization}}]),Kitsu}();return Kitsu});

@@ -1,1 +0,1 @@

(function(global,factory){'object'==typeof exports&&'undefined'!=typeof module?module.exports=factory(require('babel-runtime/helpers/asyncToGenerator'),require('axios')):'function'==typeof define&&define.amd?define(['babel-runtime/helpers/asyncToGenerator','axios'],factory):global.kitsu=factory(global._asyncToGenerator,global.axios)})(this,function(_asyncToGenerator,axios){'use strict';function error(E){if(E.response){const e=E.response.data;if(e)return e}else if(E.errors)return E;throw E}function query(params){try{let query='';for(let param in params)'object'==typeof params[param]?Object.keys(params[param]).forEach(value=>{query+=`&${param}[${value}]=${params[param][value]}`}):'string'==typeof params[param]&&(query+=`&${param}=${params[param]}`);return params?query.slice(1):''}catch(E){error(E)}}_asyncToGenerator=_asyncToGenerator&&_asyncToGenerator.hasOwnProperty('default')?_asyncToGenerator['default']:_asyncToGenerator,axios=axios&&axios.hasOwnProperty('default')?axios['default']:axios;let deattribute=(()=>{var _ref=_asyncToGenerator(function*(data){try{return'object'==typeof data&&null!==data&&(Array.isArray(data)?yield data.map((()=>{var _ref2=_asyncToGenerator(function*(el){return deattribute(el)});return function(){return _ref2.apply(this,arguments)}})()):data.attributes&&data.attributes.constructor===Object&&(Object.keys(data.attributes).forEach(function(key){data[key]=data.attributes[key]}),delete data.attributes)),data}catch(E){error(E)}});return function(){return _ref.apply(this,arguments)}})(),deserialiseArray=(()=>{var _ref=_asyncToGenerator(function*(obj){try{for(let value of yield obj.data)obj.included&&(value=yield linkRelationships(value,obj.included)),value.attributes&&(value=yield deattribute(value)),obj.data[obj.data.indexOf(value)]=value;return obj}catch(E){error(E)}});return function(){return _ref.apply(this,arguments)}})(),deserialise=(()=>{var _ref2=_asyncToGenerator(function*(obj){try{return obj.data&&obj.data.constructor===Array?obj=yield deserialiseArray(obj):obj.included&&(obj.data=yield linkRelationships(obj.data,obj.included)),delete obj.included,obj.data.attributes&&(obj.data=yield deattribute(obj.data)),obj}catch(E){error(E)}});return function(){return _ref2.apply(this,arguments)}})(),filterIncludes=(()=>{var _ref=_asyncToGenerator(function*(included,{id,type}){try{return included.filter(function(el){return el.id===id&&el.type===type})[0]||{id,type}}catch(E){error(E)}});return function(){return _ref.apply(this,arguments)}})(),linkRelationships=(()=>{var _ref=_asyncToGenerator(function*(data,included){try{const{relationships}=data;for(let key in yield relationships)if(relationships[key].data&&Array.isArray(relationships[key].data))for(let _ref2 of yield relationships[key].data){let{id,type}=_ref2;const deattributed=yield deattribute((yield filterIncludes(included,{id,type})));'undefined'!=typeof deattributed&&(!data[key]&&(data[key]=[]),data[key].push(deattributed))}else if(relationships[key].data){const{id,type}=relationships[key].data,deattributed=yield deattribute((yield filterIncludes(included,{id,type})));'undefined'==typeof deattributed||data[key]||(data[key]=deattributed),delete data[key].relationships}return delete data.relationships,data}catch(E){error(E)}});return function(){return _ref.apply(this,arguments)}})(),serialise=(()=>{var _ref=_asyncToGenerator(function*(model,obj={},method='POST'){try{if(obj.constructor!==Object||0===Object.keys(obj).length)throw new Error(`${method} requires a JSON object body`);const type=this.plural(this.camel(model)),data={type};if('POST'!==method&&'undefined'==typeof obj.id)throw new Error(`${method} requires an ID for the ${type} type`);for(let prop in'POST'!==method&&(data.id=obj.id.toString()),obj)if(null!==obj[prop]&&obj[prop].constructor===Object){if('string'==typeof obj[prop].id)'undefined'==typeof data.relationships&&(data.relationships={}),'undefined'==typeof obj[prop].type&&(obj[prop].type=this.plural(this.camel(prop))),data.relationships[prop]={data:Object.assign(obj[prop])};else throw new Error(`${method} requires an ID for the ${prop} relationships`);}else if(null!==obj[prop]&&Array.isArray(obj[prop])){const ptype=this.plural(this.camel(prop));'undefined'==typeof data.relationships&&(data.relationships={}),data.relationships[prop]={data:obj[prop].map(function(elem){if('undefined'==typeof elem.id)throw new Error(`${method} requires an ID for the ${prop} relationships`);return{id:elem.id,type:elem.type||ptype}})}}else'id'!=prop&&'type'!=prop&&('undefined'==typeof data.attributes&&(data.attributes={}),data.attributes[prop]=obj[prop]);return{data}}catch(e){throw e}});return function(){return _ref.apply(this,arguments)}})();var camel=s=>s.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g,match=>match.slice(1).toUpperCase()),kebab=s=>s.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,match=>'-'+match.toLowerCase()),snake=s=>s.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,match=>'_'+match.toLowerCase());const jsonAPI='application/vnd.api+json',jsonAPIHeader={Accept:jsonAPI,"Content-Type":jsonAPI};class Kitsu{constructor(options={}){this.fetch=this.get,this.update=this.patch,this.create=this.post,this.camel=!1===options.camelCaseTypes?s=>s:camel,this.resCase='none'===options.resourceCase?s=>s:'snake'===options.resourceCase?snake:kebab,this.plural=!1===options.pluralize?s=>s:require('pluralize'),this.headers=Object.assign({},options.headers,jsonAPIHeader),axios.defaults.baseURL=options.baseURL||'https://kitsu.io/api/edge',axios.defaults.timeout=options.timeout||3e4}get isAuth(){return!!this.headers.Authorization}get(model,params={},headers={}){var _this=this;return _asyncToGenerator(function*(){try{let[res,id]=model.split('/');const url=_this.plural(_this.resCase(res))+(id?'/'+id:''),{data}=yield axios.get(url,{params,paramsSerializer:function(p){return query(p)},headers:Object.assign(_this.headers,headers,jsonAPIHeader)});return deserialise(data)}catch(E){return error(E)}})()}patch(model,body,headers={}){var _this2=this;return _asyncToGenerator(function*(){try{if(headers=Object.assign(_this2.headers,headers,jsonAPIHeader),!_this2.isAuth)throw new Error('Not logged in');if('undefined'==typeof body.id)throw new Error('Updating a resource requires an ID');const url=_this2.plural(_this2.resCase(model))+'/'+body.id,{data}=yield axios.patch(url,(yield serialise.apply(_this2,[model,body,'PATCH'])),{headers});return data}catch(E){return error(E)}})()}post(model,body,headers={}){var _this3=this;return _asyncToGenerator(function*(){try{if(headers=Object.assign(_this3.headers,headers,jsonAPIHeader),!_this3.isAuth)throw new Error('Not logged in');const url=_this3.plural(_this3.resCase(model)),{data}=yield axios.post(url,(yield serialise.apply(_this3,[model,body])),{headers});return data}catch(E){return error(E)}})()}remove(model,id,headers={}){var _this4=this;return _asyncToGenerator(function*(){try{if(headers=Object.assign(_this4.headers,headers,jsonAPIHeader),!_this4.isAuth)throw new Error('Not logged in');const url=_this4.plural(_this4.resCase(model))+'/'+id,{data}=yield axios.delete(url,{data:yield serialise.apply(_this4,[model,{id},'DELETE']),headers});return data}catch(E){return error(E)}})()}self(params={},headers={}){var _this5=this;return _asyncToGenerator(function*(){try{const res=yield _this5.get('users',Object.assign({filter:{self:!0}},params),headers);if(res.errors)throw res;return res.data[0]}catch(E){return error(E)}})()}}return Kitsu});
(function(global,factory){'object'==typeof exports&&'undefined'!=typeof module?module.exports=factory(require('babel-runtime/helpers/asyncToGenerator'),require('axios')):'function'==typeof define&&define.amd?define(['babel-runtime/helpers/asyncToGenerator','axios'],factory):global.kitsu=factory(global._asyncToGenerator,global.axios)})(this,function(_asyncToGenerator,axios){'use strict';function error(E){if(E.response){const e=E.response.data;if(e)return e}else if(E.errors)return E;throw E}function query(params){try{let query='';for(let param in params)'object'==typeof params[param]?Object.keys(params[param]).forEach(value=>{query+=`&${param}[${value}]=${params[param][value]}`}):'string'==typeof params[param]&&(query+=`&${param}=${params[param]}`);return params?query.slice(1):''}catch(E){error(E)}}_asyncToGenerator=_asyncToGenerator&&_asyncToGenerator.hasOwnProperty('default')?_asyncToGenerator['default']:_asyncToGenerator,axios=axios&&axios.hasOwnProperty('default')?axios['default']:axios;let deattribute=(()=>{var _ref=_asyncToGenerator(function*(data){try{return'object'==typeof data&&null!==data&&(Array.isArray(data)?yield data.map((()=>{var _ref2=_asyncToGenerator(function*(el){return deattribute(el)});return function(){return _ref2.apply(this,arguments)}})()):data.attributes&&data.attributes.constructor===Object&&(Object.keys(data.attributes).forEach(function(key){data[key]=data.attributes[key]}),delete data.attributes)),data}catch(E){error(E)}});return function(){return _ref.apply(this,arguments)}})(),deserialiseArray=(()=>{var _ref=_asyncToGenerator(function*(obj){try{for(let value of yield obj.data)obj.included&&(value=yield linkRelationships(value,obj.included)),value.attributes&&(value=yield deattribute(value)),obj.data[obj.data.indexOf(value)]=value;return obj}catch(E){error(E)}});return function(){return _ref.apply(this,arguments)}})(),deserialise=(()=>{var _ref2=_asyncToGenerator(function*(obj){try{return obj.data&&obj.data.constructor===Array?obj=yield deserialiseArray(obj):obj.included&&(obj.data=yield linkRelationships(obj.data,obj.included)),delete obj.included,obj.data.attributes&&(obj.data=yield deattribute(obj.data)),obj}catch(E){error(E)}});return function(){return _ref2.apply(this,arguments)}})(),filterIncludes=(()=>{var _ref=_asyncToGenerator(function*(included,{id,type}){try{return included.filter(function(el){return el.id===id&&el.type===type})[0]||{id,type}}catch(E){error(E)}});return function(){return _ref.apply(this,arguments)}})(),linkRelationships=(()=>{var _ref=_asyncToGenerator(function*(data,included){try{const{relationships}=data;for(let key in yield relationships)if(relationships[key].data&&Array.isArray(relationships[key].data))for(let _ref2 of yield relationships[key].data){let{id,type}=_ref2;const deattributed=yield deattribute((yield filterIncludes(included,{id,type})));'undefined'!=typeof deattributed&&(!data[key]&&(data[key]=[]),data[key].push(deattributed))}else if(relationships[key].data){const{id,type}=relationships[key].data,deattributed=yield deattribute((yield filterIncludes(included,{id,type})));'undefined'==typeof deattributed||data[key]||(data[key]=deattributed),delete data[key].relationships}return delete data.relationships,data}catch(E){error(E)}});return function(){return _ref.apply(this,arguments)}})(),serialise=(()=>{var _ref=_asyncToGenerator(function*(model,obj={},method='POST'){try{if(obj.constructor!==Object||0===Object.keys(obj).length)throw new Error(`${method} requires a JSON object body`);const type=this.plural(this.camel(model)),data={type};if('POST'!==method&&'undefined'==typeof obj.id)throw new Error(`${method} requires an ID for the ${type} type`);for(let prop in'POST'!==method&&(data.id=obj.id.toString()),obj)if(null!==obj[prop]&&obj[prop].constructor===Object){if('string'==typeof obj[prop].id)'undefined'==typeof data.relationships&&(data.relationships={}),'undefined'==typeof obj[prop].type&&(obj[prop].type=this.plural(this.camel(prop))),data.relationships[prop]={data:Object.assign(obj[prop])};else throw new Error(`${method} requires an ID for the ${prop} relationships`);}else if(null!==obj[prop]&&Array.isArray(obj[prop])){const ptype=this.plural(this.camel(prop));'undefined'==typeof data.relationships&&(data.relationships={}),data.relationships[prop]={data:obj[prop].map(function(elem){if('undefined'==typeof elem.id)throw new Error(`${method} requires an ID for the ${prop} relationships`);return{id:elem.id,type:elem.type||ptype}})}}else'id'!=prop&&'type'!=prop&&('undefined'==typeof data.attributes&&(data.attributes={}),data.attributes[prop]=obj[prop]);return{data}}catch(e){throw e}});return function(){return _ref.apply(this,arguments)}})();var camel=s=>s.replace(/[-_][a-z\u00E0-\u00F6\u00F8-\u00FE]/g,match=>match.slice(1).toUpperCase()),kebab=s=>s.charAt(0).toLowerCase()+s.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,match=>'-'+match.toLowerCase()),snake=s=>s.charAt(0).toLowerCase()+s.slice(1).replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,match=>'_'+match.toLowerCase());const jsonAPI='application/vnd.api+json',jsonAPIHeader={Accept:jsonAPI,"Content-Type":jsonAPI};class Kitsu{constructor(options={}){this.fetch=this.get,this.update=this.patch,this.create=this.post,this.camel=!1===options.camelCaseTypes?s=>s:camel,this.resCase='none'===options.resourceCase?s=>s:'snake'===options.resourceCase?snake:kebab,this.plural=!1===options.pluralize?s=>s:require('pluralize'),this.headers=Object.assign({},options.headers,jsonAPIHeader),axios.defaults.baseURL=options.baseURL||'https://kitsu.io/api/edge',axios.defaults.timeout=options.timeout||3e4}get isAuth(){return!!this.headers.Authorization}get(model,params={},headers={}){var _this=this;return _asyncToGenerator(function*(){try{let[res,id]=model.split('/');const url=_this.plural(_this.resCase(res))+(id?'/'+id:''),{data}=yield axios.get(url,{params,paramsSerializer:function(p){return query(p)},headers:Object.assign(_this.headers,headers,jsonAPIHeader)});return deserialise(data)}catch(E){return error(E)}})()}patch(model,body,headers={}){var _this2=this;return _asyncToGenerator(function*(){try{if(headers=Object.assign(_this2.headers,headers,jsonAPIHeader),!_this2.isAuth)throw new Error('Not logged in');if('undefined'==typeof body.id)throw new Error('Updating a resource requires an ID');const url=_this2.plural(_this2.resCase(model))+'/'+body.id,{data}=yield axios.patch(url,(yield serialise.apply(_this2,[model,body,'PATCH'])),{headers});return data}catch(E){return error(E)}})()}post(model,body,headers={}){var _this3=this;return _asyncToGenerator(function*(){try{if(headers=Object.assign(_this3.headers,headers,jsonAPIHeader),!_this3.isAuth)throw new Error('Not logged in');const url=_this3.plural(_this3.resCase(model)),{data}=yield axios.post(url,(yield serialise.apply(_this3,[model,body])),{headers});return data}catch(E){return error(E)}})()}remove(model,id,headers={}){var _this4=this;return _asyncToGenerator(function*(){try{if(headers=Object.assign(_this4.headers,headers,jsonAPIHeader),!_this4.isAuth)throw new Error('Not logged in');const url=_this4.plural(_this4.resCase(model))+'/'+id,{data}=yield axios.delete(url,{data:yield serialise.apply(_this4,[model,{id},'DELETE']),headers});return data}catch(E){return error(E)}})()}self(params={},headers={}){var _this5=this;return _asyncToGenerator(function*(){try{const res=yield _this5.get('users',Object.assign({filter:{self:!0}},params),headers);if(res.errors)throw res;return res.data[0]}catch(E){return error(E)}})()}}return Kitsu});

@@ -0,0 +0,0 @@ MIT License

{
"name": "kitsu",
"version": "4.2.0",
"version": "4.2.1",
"description": "Simple & lightweight JSON-API client for Kitsu and other compliant APIs",

@@ -103,3 +103,3 @@ "license": "MIT",

"generate-changelog": "~1.7.0",
"jest": "~22.0.0",
"jest": "~22.1.0",
"js-beautify": "~1.7.4",

@@ -106,0 +106,0 @@ "rollup": "~0.54.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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