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

js-tinyapi

Package Overview
Dependencies
Maintainers
3
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-tinyapi - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

2

dist/index.js

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

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("js-cookie")):"function"==typeof define&&define.amd?define(["js-cookie"],t):"object"==typeof exports?exports["js-tinyapi"]=t(require("js-cookie")):e["js-tinyapi"]=t(e["js-cookie"])}(window,function(e){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},r.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}({0:function(e,t,r){e.exports=r("tjUo")},"4fRq":function(e,t){var r="undefined"!=typeof crypto&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&msCrypto.getRandomValues.bind(msCrypto);if(r){var n=new Uint8Array(16);e.exports=function(){return r(n),n}}else{var o=new Array(16);e.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),o[t]=e>>>((3&t)<<3)&255;return o}}},Al62:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.fetchHeaders=t.makeHeaders=t.ajaxWithRequest=t.makeRequest=t.makeFormData=t.matchContentType=t.contentTypes=t.ajaxSettings=t.postForm=t.postJson=t.ajax=t.addTrailingSlash=void 0;var n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e};t.supplant=function(e,t){return e.replace(/{([^{}]*)}/g,function(e,r){var n=t[r];if(void 0===n)throw new u.ApiError("Missing string template: "+r);return"string"==typeof n||"number"==typeof n?n:e})},t.capitalize=function(e){return e[0].toUpperCase()+e.slice(1)},t.takeFirst=function(){if(arguments){var e=!0,t=!1,r=void 0;try{for(var n,o=arguments[Symbol.iterator]();!(e=(n=o.next()).done);e=!0){var a=n.value;if(void 0!==a)return a}}catch(e){t=!0,r=e}finally{try{!e&&o.return&&o.return()}finally{if(t)throw r}}}};var o,a=r("vmXh"),i=(o=a)&&o.__esModule?o:{default:o},u=r("yMsT");var s={form:"application/x-www-form-urlencoded",multiForm:"multipart/form-data",json:"application/json",jsonApi:"application/vnd.api+json"};var c={csrf:i.default?i.default.get("csrftoken"):void 0,bearer:null};function l(e){var t,r=e||{},o=r.method,a=void 0===o?"get":o,i=r.contentType,u=void 0===i?s.json:i,l=r.extraHeaders,f=r.useBearer,d=void 0===f||f,p=r.bearer,h={"X-Requested-With":"XMLHttpRequest","Content-Type":u};return""===(t=c.csrf)||void 0===t||null===t||/^(GET|HEAD|OPTIONS\TRACE)$/i.test(a)||(h["X-CSRFToken"]=c.csrf),p||(p=c.bearer),d&&p&&(h.Authorization="Bearer "+p),h=n({},h,l)}function f(e){return new Headers(l(e))}function d(e){var t=(e.method||"get").toUpperCase(),r=e||{},n=r.url,o=r.body,a=r.contentType,i=r.extraHeaders,u=r.useBearer,s={method:t,headers:f({method:t,contentType:a,extraHeaders:i,useBearer:void 0===u||u,bearer:r.bearer}),credentials:"same-origin"};"GET"!=t&&"HEAD"!=t&&"OPTIONS"!=t&&(s.body=o);var c=new Request(n,s);return fetch(c).then(function(e){return e.ok?204==e.status?{}:"undefined"!=typeof TINYAPI_NODE&&TINYAPI_NODE?e:e.json?e.json():e:e.json?e.json().catch(function(t){return Object({status:e.status})}).then(function(e){return Promise.reject(e)}):e})}function p(e){var t=new FormData;for(var r in e||{})t.append(r,e[r]);return t}t.addTrailingSlash=function(e){return e+("/"==e[e.length-1]?"":"/")},t.ajax=d,t.postJson=function(e){var t=e.url,r=e.payload,n=e.contentType,o=e.useBearer;return d({url:t,method:"post",body:JSON.stringify(r||{}),contentType:n,useBearer:o})},t.postForm=function(e){var t=e.url,r=e.payload,n=e.useBearer;return d({url:t,body:p(r),method:"post",useBearer:n})},t.ajaxSettings=c,t.contentTypes=s,t.matchContentType=function(e,t){if(!e)return!1;var r=e.indexOf(";");return r>=0&&(e=e.substring(0,r)),e.toLowerCase()==s[t]},t.makeFormData=p,t.makeRequest=function(e){var t=(e.method||"get").toUpperCase(),r=e||{},n=r.url,o=r.body,a=r.contentType,i=r.extraHeaders,u=r.useBearer,s={url:n,method:t,headers:l({method:t,contentType:a,extraHeaders:i,useBearer:void 0===u||u,bearer:r.bearer}),credentials:"same-origin"};return"GET"!=t&&"HEAD"!=t&&"OPTIONS"!=t&&(s.body=o),s},t.ajaxWithRequest=function(e){var t=e.url,r=function(e,t){var r={};for(var n in e)t.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n]);return r}(e,["url"]),n=new Request(t,r);return fetch(n).then(function(e){return e.ok?204==e.status?{}:"undefined"!=typeof TINYAPI_NODE&&TINYAPI_NODE?e:e.json?e.json().then(function(t){return{data:t,response:e}}):{response:e}:e.json?{data:e.json().catch(function(t){return Object({status:e.status})}).then(function(e){return Promise.reject(e)}),response:e}:{response:e}})},t.makeHeaders=l,t.fetchHeaders=f},EcEN:function(e,t,r){var n=r("xDdU"),o=r("xk4V"),a=o;a.v1=n,a.v4=o,e.exports=a},I2ZF:function(e,t){for(var r=[],n=0;n<256;++n)r[n]=(n+256).toString(16).substr(1);e.exports=function(e,t){var n=t||0,o=r;return o[e[n++]]+o[e[n++]]+o[e[n++]]+o[e[n++]]+"-"+o[e[n++]]+o[e[n++]]+"-"+o[e[n++]]+o[e[n++]]+"-"+o[e[n++]]+o[e[n++]]+"-"+o[e[n++]]+o[e[n++]]+o[e[n++]]+o[e[n++]]+o[e[n++]]+o[e[n++]]}},KmhG:function(e,t,r){"use strict";function n(e,t){return Array.isArray(e)||(e=[e]),e&&e.length?[t+"="+e.join(",")]:[]}Object.defineProperty(t,"__esModule",{value:!0}),t.jsonApiQuery=function(e){var t,r,o=e||{},a=o.include,i=o.sort,u=o.filter,s=o.fields,c=o.rawFilters,l=(e.initial||[]).concat((t=a,n(t,r||"include")).concat(function(e,t){var r=t||{},n=(r.key,r.raw);if(e&&Object.keys(e).length){var o=n?function(e,t){return e+"="+t}:function(e,t){return"filter["+e+"]="+t};return Object.keys(e).map(function(t){return o(t,e[t])})}return[]}(u,{raw:c}).concat(function(e,t){return n(e,t||"sort")}(i).concat(function(e,t){return e&&Object.keys(e).length?Object.keys(e).map(function(t){return"fields["+t+"]="+e[t]}):[]}(s)))));return l.length>0?"?"+l.join("&"):""}},XyvK:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},o=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=s(r("EcEN")),i=r("Al62"),u=s(r("f/LL"));function s(e){return e&&e.__esModule?e:{default:e}}var c=function(e){function t(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var r=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return r.process=function(e,t,o){var a={request:t};if((o=n({},e.batchOptions||{},o)).skipBatching)return r.submit(t);var i=new Promise(function(e,t){a.resolve=e,a.reject=t}),u=o.group||"auto";return r.batch[u]=r.batch[u]||[],r.batch[u].push(a),"auto"==u&&(r.batch[u].length==r.maximum?(clearTimeout(r._to),r.submitBatch()):r._to||(r._to=setTimeout(r.submitBatch,r.timeout))),i},r.submitBatch=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"auto",t=r.batch[e]||[];delete r.batch[e],"auto"==e&&(r._to=null);var n=r.combineRequests(t);return r.submit(n).then(function(e){return r.splitResponses(t,e)})},r.combineRequests=function(e){return{url:r.selectUrl(e),method:"post",body:JSON.stringify({batch:e.map(function(e){return r.transformRequest(e.request)})}),headers:(0,i.fetchHeaders)({method:"post"}),credentials:"same-origin"}},r.selectUrl=function(e){var t=!0,n=!1,o=void 0;try{for(var a,i=e[Symbol.iterator]();!(t=(a=i.next()).done);t=!0){var u=a.value;if(r.mutMethods.has(u.request.method.toLowerCase()))return r.mutableBatchUrl}}catch(e){n=!0,o=e}finally{try{!t&&i.return&&i.return()}finally{if(n)throw o}}return r.batchUrl},r.transformRequest=function(e){var t={url:e.url,method:e.method,headers:e.headers};return e.body&&(t.body=e.body),t},r.splitResponses=function(e,t){for(var r=[],n=0;n<e.length;++n){var o=t.data[n];if(o.status_code&&o.status_code>=300){var a={status_code:o.status_code,reason_phrase:o.reason_phrase,headers:o.headers||{},body:o.body};e[n].reject({response:a,data:a}),r.push(a)}else e[n].resolve({response:o,data:o.body}),r.push(o.body)}return r},r.batchUrl=e.batchUrl,r.mutableBatchUrl=e.mutableBatchUrl||r.batchUrl,r.batch={auto:[]},r.maximum=20,r.timeout=e.timeout,r.mutMethods=new Set(["post","put","patch"]),r._to=null,r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,u.default),o(t,[{key:"contributeToApi",value:function(e){var t=this;e.batch=function(){var r=Object.create(e),n=a.default.v4();return r.batchOptions={group:n},r.send=function(){return t.submitBatch(n)},r.clear=function(){delete t.batch[n]},r}}}]),t}();t.default=c},"f/LL":function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),o=r("Al62");var a=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.preProcess=function(e,t,r){return t},this.postProcess=function(e,t,r){return t},this.process=function(e,t,r){return t},this.submit=function(e){return(0,o.ajaxWithRequest)(e)}}return n(e,[{key:"contributeToApi",value:function(e){}}]),e}();t.default=a},tjUo:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Batch=t.Middleware=t.ApiError=t.ajaxSettings=t.postForm=t.postJson=t.ajax=void 0;var n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},o=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=r("KmhG"),i=r("Al62"),u=r("yMsT"),s=l(r("f/LL")),c=l(r("XyvK"));function l(e){return e&&e.__esModule?e:{default:e}}var f=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),d.call(this),this.crud={},this.middlewares=[],this.merge(t),this.urlRoot=null,this.defaultType=null}return o(e,[{key:"makeCrudEndpoints",value:function(e,t){var r=t+("/"==t[t.length-1]?"":"/")+e;this.crud[e]={list:this.makeEndpoint(e+"List",r,"GET"),create:this.makeEndpoint(e+"Create",r,"POST",{handler:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(n({},r,{payload:t}))}}),detail:this.makeEndpoint(e+"Get",r+"/{id}","GET",{handler:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(n({},r,{params:{id:t}}))}}),update:this.makeEndpoint(e+"Update",r+"/{id}","PATCH",{handler:function(e,t,r){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return e(n({},o,{params:{id:t},payload:r}))}}),remove:this.makeEndpoint(e+"Remove",r+"/{id}","DELETE",{handler:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(n({},r,{params:{id:t}}))}}),options:this.makeEndpoint(e+"Options",r,"OPTIONS")}}},{key:"request",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=r.method,o=void 0===n?(e.method||"").toLowerCase():n,u=r.path,s=void 0===u?e.path:u,c=r.params,l=void 0===c?{}:c,f=r.payload,d=r.type,p=void 0===d?e.type||this.defaultType:d,h=r.extraHeaders,v=void 0===h?{}:h,y=r.include,m=void 0===y?e.include||[]:y,b=r.filter,j=void 0===b?e.filter||{}:b,g=r.sort,w=void 0===g?e.sort||[]:g,O=r.fields,T=void 0===O?e.fields||[]:O,x=r.rawFilters,E=function(e,t){var r={};for(var n in e)t.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n]);return r}(r,["method","path","params","payload","type","extraHeaders","include","filter","sort","fields","rawFilters"]),_=r.urlRoot,k=void 0===_?this.urlRoot:_,P=r.contentType,A=void 0===P?e.contentType:P;p&&!A&&(A=i.contentTypes[p]);var R=void 0,C=[];if("get"!=o&&"options"!=o)void 0!==f&&(R=(0,i.matchContentType)(A,"form")||(0,i.matchContentType)(A,"multiForm")?(0,i.makeFormData)(f):JSON.stringify(f||{}));else if(void 0!==f)for(var q in f)C.push(q+"="+encodeURIComponent(f[q]));var S=(0,i.supplant)(s,l);S+=(0,a.jsonApiQuery)({initial:C,include:m,filter:j,sort:w,fields:T,rawFilters:(0,i.takeFirst)(x,this.rawFilters,e.rawFilters)}),k&&("/"==k[k.length-1]&&(k=k.substring(0,k.length-1)),S=k+S);var M={url:S,method:o,body:R,contentType:A,extraHeaders:v,bearer:this.bearer},F=void 0;if(this.middlewares.length){M=(0,i.makeRequest)(M);var U=!0,B=!1,D=void 0;try{for(var H,I=this.middlewares[Symbol.iterator]();!(U=(H=I.next()).done);U=!0){M=H.value.preProcess(this,M,E)}}catch(e){B=!0,D=e}finally{try{!U&&I.return&&I.return()}finally{if(B)throw D}}var N=0;for(F=this.middlewares[N++].process(this,M,E);N<this.middlewares.length;++N)if(Promise.resolve(F)==F)for(var L=function(){var e=t.middlewares[N];F=F.then(function(r){return e.process(t,r,E)})};N<this.middlewares.length;++N)L();else F=this.middlewares[N].process(this,F,E);Promise.resolve(F)!=F&&(F=ajaxWithRequest(F));var G=function(e){F=F.then(function(r){return e.postProcess(t,r,E)})},J=!0,X=!1,W=void 0;try{for(var K,V=this.middlewares.reverse()[Symbol.iterator]();!(J=(K=V.next()).done);J=!0){G(K.value)}}catch(e){X=!0,W=e}finally{try{!J&&V.return&&V.return()}finally{if(X)throw W}}}else F=(0,i.ajax)(M);return F.then(function(e){return e.data})}}]),e}(),d=function(){var e=this;this.pushMiddleware=function(t){Array.isArray(t)||(t=[t]),t.forEach(function(t){t.api=e,e.middlewares.push(t),t.contributeToApi(e)})},this.unshiftMiddleware=function(t){Array.isArray(t)||(t=[t]),t.forEach(function(t){t.api=e,e.middlewares.unshift(t)})},this.merge=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if(!t)throw new Error("Empty endpoint data given to Api.merge.");var n=!0,o=!1,a=void 0;try{for(var i,u=Object.keys(t)[Symbol.iterator]();!(n=(i=u.next()).done);n=!0){var s=i.value,c=t[s],l=/^(GET|POST|PUT|PATCH|DELETE|CRUD)$/.exec(s);if(l)if("CRUD"==l[1]){var f=r.lastIndexOf("/")+1,d=r.slice(f),p=r.slice(0,f);e.makeCrudEndpoints(d,p)}else{c instanceof Object||(c={name:c});var h=c,v=h.name,y=h.options,m=void 0===y?{}:y;e.makeEndpoint(v,r+"/",l[1],m)}else"CRUD"==c?e.makeCrudEndpoints(s,r):e.merge(c,r+"/"+s)}}catch(e){o=!0,a=e}finally{try{!n&&u.return&&u.return()}finally{if(o)throw a}}},this.makeEndpoint=function(t,r,o){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if(void 0!==e[t])throw new Error("Duplicate name in Api: "+t);var u=n({},a,{path:(0,i.addTrailingSlash)(r),method:o}),s=function(e){return this.request(u,e)},c=a.handler;if(void 0!==c){var l=function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return c.apply(void 0,[s.bind(this)].concat(t))};l.context=u,e[t]=l}else s.context=u,e[t]=s;return e[t]}};t.default=f,t.ajax=i.ajax,t.postJson=i.postJson,t.postForm=i.postForm,t.ajaxSettings=i.ajaxSettings,t.ApiError=u.ApiError,t.Middleware=s.default,t.Batch=c.default},vmXh:function(t,r){t.exports=e},xDdU:function(e,t,r){var n,o,a=r("4fRq"),i=r("I2ZF"),u=0,s=0;e.exports=function(e,t,r){var c=t&&r||0,l=t||[],f=(e=e||{}).node||n,d=void 0!==e.clockseq?e.clockseq:o;if(null==f||null==d){var p=a();null==f&&(f=n=[1|p[0],p[1],p[2],p[3],p[4],p[5]]),null==d&&(d=o=16383&(p[6]<<8|p[7]))}var h=void 0!==e.msecs?e.msecs:(new Date).getTime(),v=void 0!==e.nsecs?e.nsecs:s+1,y=h-u+(v-s)/1e4;if(y<0&&void 0===e.clockseq&&(d=d+1&16383),(y<0||h>u)&&void 0===e.nsecs&&(v=0),v>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");u=h,s=v,o=d;var m=(1e4*(268435455&(h+=122192928e5))+v)%4294967296;l[c++]=m>>>24&255,l[c++]=m>>>16&255,l[c++]=m>>>8&255,l[c++]=255&m;var b=h/4294967296*1e4&268435455;l[c++]=b>>>8&255,l[c++]=255&b,l[c++]=b>>>24&15|16,l[c++]=b>>>16&255,l[c++]=d>>>8|128,l[c++]=255&d;for(var j=0;j<6;++j)l[c+j]=f[j];return t||i(l)}},xk4V:function(e,t,r){var n=r("4fRq"),o=r("I2ZF");e.exports=function(e,t,r){var a=t&&r||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var i=(e=e||{}).random||(e.rng||n)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t)for(var u=0;u<16;++u)t[a+u]=i[u];return t||o(i)}},yMsT:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(e){function t(){var e;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var r=arguments.length,n=Array(r),o=0;o<r;o++)n[o]=arguments[o];var a=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(n)));try{Error.captureStackTrace(a,t)}catch(e){}return a}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,Error),t}();t.ApiError=n}})});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("js-cookie")):"function"==typeof define&&define.amd?define(["js-cookie"],t):"object"==typeof exports?exports["js-tinyapi"]=t(require("js-cookie")):e["js-tinyapi"]=t(e["js-cookie"])}(window,function(e){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},r.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}({0:function(e,t,r){e.exports=r("tjUo")},"4fRq":function(e,t){var r="undefined"!=typeof crypto&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&msCrypto.getRandomValues.bind(msCrypto);if(r){var n=new Uint8Array(16);e.exports=function(){return r(n),n}}else{var o=new Array(16);e.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),o[t]=e>>>((3&t)<<3)&255;return o}}},Al62:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.fetchHeaders=t.makeHeaders=t.ajaxWithRequest=t.makeRequest=t.makeFormData=t.matchContentType=t.contentTypes=t.ajaxSettings=t.postForm=t.postJson=t.ajax=t.addTrailingSlash=void 0;var n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e};t.supplant=function(e,t){return e.replace(/{([^{}]*)}/g,function(e,r){var n=t[r];if(void 0===n)throw new u.ApiError("Missing string template: "+r);return"string"==typeof n||"number"==typeof n?n:e})},t.capitalize=function(e){return e[0].toUpperCase()+e.slice(1)},t.takeFirst=function(){if(arguments){var e=!0,t=!1,r=void 0;try{for(var n,o=arguments[Symbol.iterator]();!(e=(n=o.next()).done);e=!0){var a=n.value;if(void 0!==a)return a}}catch(e){t=!0,r=e}finally{try{!e&&o.return&&o.return()}finally{if(t)throw r}}}};var o,a=r("vmXh"),i=(o=a)&&o.__esModule?o:{default:o},u=r("yMsT");var s={form:"application/x-www-form-urlencoded",multiForm:"multipart/form-data",json:"application/json",jsonApi:"application/vnd.api+json"};var c={csrf:i.default?i.default.get("csrftoken"):void 0,bearer:null};function l(e){var t,r=e||{},o=r.method,a=void 0===o?"get":o,i=r.contentType,u=void 0===i?s.json:i,l=r.extraHeaders,f=r.useBearer,d=void 0===f||f,p=r.bearer,h={"X-Requested-With":"XMLHttpRequest"};return u!==s.multiForm&&(h["Content-Type"]=u),""===(t=c.csrf)||void 0===t||null===t||/^(GET|HEAD|OPTIONS\TRACE)$/i.test(a)||(h["X-CSRFToken"]=c.csrf),p||(p=c.bearer),d&&p&&(h.Authorization="Bearer "+p),h=n({},h,l)}function f(e){return new Headers(l(e))}function d(e){var t=(e.method||"get").toUpperCase(),r=e||{},n=r.url,o=r.body,a=r.contentType,i=r.extraHeaders,u=r.useBearer,s={method:t,headers:f({method:t,contentType:a,extraHeaders:i,useBearer:void 0===u||u,bearer:r.bearer}),credentials:"same-origin"};"GET"!=t&&"HEAD"!=t&&"OPTIONS"!=t&&(s.body=o);var c=new Request(n,s);return fetch(c).then(function(e){return e.ok?204==e.status?{}:"undefined"!=typeof TINYAPI_NODE&&TINYAPI_NODE?e:e.json?e.json():e:e.json?e.json().catch(function(t){return Object({status:e.status})}).then(function(e){return Promise.reject(e)}):e})}function p(e){var t=new FormData;for(var r in e||{})t.append(r,e[r]);return t}t.addTrailingSlash=function(e){return e+("/"==e[e.length-1]?"":"/")},t.ajax=d,t.postJson=function(e){var t=e.url,r=e.payload,n=e.contentType,o=e.useBearer;return d({url:t,method:"post",body:JSON.stringify(r||{}),contentType:n,useBearer:o})},t.postForm=function(e){var t=e.url,r=e.payload,n=e.useBearer;return d({url:t,body:p(r),method:"post",useBearer:n})},t.ajaxSettings=c,t.contentTypes=s,t.matchContentType=function(e,t){if(!e)return!1;var r=e.indexOf(";");return r>=0&&(e=e.substring(0,r)),e.toLowerCase()==s[t]},t.makeFormData=p,t.makeRequest=function(e){var t=(e.method||"get").toUpperCase(),r=e||{},n=r.url,o=r.body,a=r.contentType,i=r.extraHeaders,u=r.useBearer,s={url:n,method:t,headers:l({method:t,contentType:a,extraHeaders:i,useBearer:void 0===u||u,bearer:r.bearer}),credentials:"same-origin"};return"GET"!=t&&"HEAD"!=t&&"OPTIONS"!=t&&(s.body=o),s},t.ajaxWithRequest=function(e){var t=e.url,r=function(e,t){var r={};for(var n in e)t.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n]);return r}(e,["url"]),n=new Request(t,r);return fetch(n).then(function(e){return e.ok?204==e.status?{}:"undefined"!=typeof TINYAPI_NODE&&TINYAPI_NODE?e:e.json?e.json().then(function(t){return{data:t,response:e}}):{response:e}:e.json?{data:e.json().catch(function(t){return Object({status:e.status})}).then(function(e){return Promise.reject(e)}),response:e}:{response:e}})},t.makeHeaders=l,t.fetchHeaders=f},EcEN:function(e,t,r){var n=r("xDdU"),o=r("xk4V"),a=o;a.v1=n,a.v4=o,e.exports=a},I2ZF:function(e,t){for(var r=[],n=0;n<256;++n)r[n]=(n+256).toString(16).substr(1);e.exports=function(e,t){var n=t||0,o=r;return o[e[n++]]+o[e[n++]]+o[e[n++]]+o[e[n++]]+"-"+o[e[n++]]+o[e[n++]]+"-"+o[e[n++]]+o[e[n++]]+"-"+o[e[n++]]+o[e[n++]]+"-"+o[e[n++]]+o[e[n++]]+o[e[n++]]+o[e[n++]]+o[e[n++]]+o[e[n++]]}},KmhG:function(e,t,r){"use strict";function n(e,t){return Array.isArray(e)||(e=[e]),e&&e.length?[t+"="+e.join(",")]:[]}Object.defineProperty(t,"__esModule",{value:!0}),t.jsonApiQuery=function(e){var t,r,o=e||{},a=o.include,i=o.sort,u=o.filter,s=o.fields,c=o.rawFilters,l=(e.initial||[]).concat((t=a,n(t,r||"include")).concat(function(e,t){var r=t||{},n=(r.key,r.raw);if(e&&Object.keys(e).length){var o=n?function(e,t){return e+"="+t}:function(e,t){return"filter["+e+"]="+t};return Object.keys(e).map(function(t){return o(t,e[t])})}return[]}(u,{raw:c}).concat(function(e,t){return n(e,t||"sort")}(i).concat(function(e,t){return e&&Object.keys(e).length?Object.keys(e).map(function(t){return"fields["+t+"]="+e[t]}):[]}(s)))));return l.length>0?"?"+l.join("&"):""}},XyvK:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},o=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=s(r("EcEN")),i=r("Al62"),u=s(r("f/LL"));function s(e){return e&&e.__esModule?e:{default:e}}var c=function(e){function t(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var r=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return r.process=function(e,t,o){var a={request:t};if((o=n({},e.batchOptions||{},o)).skipBatching)return r.submit(t);var i=new Promise(function(e,t){a.resolve=e,a.reject=t}),u=o.group||"auto";return r.batch[u]=r.batch[u]||[],r.batch[u].push(a),"auto"==u&&(r.batch[u].length==r.maximum?(clearTimeout(r._to),r.submitBatch()):r._to||(r._to=setTimeout(r.submitBatch,r.timeout))),i},r.submitBatch=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"auto",t=r.batch[e]||[];delete r.batch[e],"auto"==e&&(r._to=null);var n=r.combineRequests(t);return r.submit(n).then(function(e){return r.splitResponses(t,e)})},r.combineRequests=function(e){return{url:r.selectUrl(e),method:"post",body:JSON.stringify({batch:e.map(function(e){return r.transformRequest(e.request)})}),headers:(0,i.fetchHeaders)({method:"post"}),credentials:"same-origin"}},r.selectUrl=function(e){var t=!0,n=!1,o=void 0;try{for(var a,i=e[Symbol.iterator]();!(t=(a=i.next()).done);t=!0){var u=a.value;if(r.mutMethods.has(u.request.method.toLowerCase()))return r.mutableBatchUrl}}catch(e){n=!0,o=e}finally{try{!t&&i.return&&i.return()}finally{if(n)throw o}}return r.batchUrl},r.transformRequest=function(e){var t={url:e.url,method:e.method,headers:e.headers};return e.body&&(t.body=e.body),t},r.splitResponses=function(e,t){for(var r=[],n=0;n<e.length;++n){var o=t.data[n];if(o.status_code&&o.status_code>=300){var a={status_code:o.status_code,reason_phrase:o.reason_phrase,headers:o.headers||{},body:o.body};e[n].reject({response:a,data:a}),r.push(a)}else e[n].resolve({response:o,data:o.body}),r.push(o.body)}return r},r.batchUrl=e.batchUrl,r.mutableBatchUrl=e.mutableBatchUrl||r.batchUrl,r.batch={auto:[]},r.maximum=20,r.timeout=e.timeout,r.mutMethods=new Set(["post","put","patch"]),r._to=null,r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,u.default),o(t,[{key:"contributeToApi",value:function(e){var t=this;e.batch=function(){var r=Object.create(e),n=a.default.v4();return r.batchOptions={group:n},r.send=function(){return t.submitBatch(n)},r.clear=function(){delete t.batch[n]},r}}}]),t}();t.default=c},"f/LL":function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),o=r("Al62");var a=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.preProcess=function(e,t,r){return t},this.postProcess=function(e,t,r){return t},this.process=function(e,t,r){return t},this.submit=function(e){return(0,o.ajaxWithRequest)(e)}}return n(e,[{key:"contributeToApi",value:function(e){}}]),e}();t.default=a},tjUo:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Batch=t.Middleware=t.ApiError=t.ajaxSettings=t.postForm=t.postJson=t.ajax=void 0;var n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},o=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=r("KmhG"),i=r("Al62"),u=r("yMsT"),s=l(r("f/LL")),c=l(r("XyvK"));function l(e){return e&&e.__esModule?e:{default:e}}var f=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),d.call(this),this.crud={},this.middlewares=[],this.merge(t),this.urlRoot=null,this.defaultType=null}return o(e,[{key:"makeCrudEndpoints",value:function(e,t){var r=t+("/"==t[t.length-1]?"":"/")+e;this.crud[e]={list:this.makeEndpoint(e+"List",r,"GET"),create:this.makeEndpoint(e+"Create",r,"POST",{handler:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(n({},r,{payload:t}))}}),detail:this.makeEndpoint(e+"Get",r+"/{id}","GET",{handler:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(n({},r,{params:{id:t}}))}}),update:this.makeEndpoint(e+"Update",r+"/{id}","PATCH",{handler:function(e,t,r){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return e(n({},o,{params:{id:t},payload:r}))}}),remove:this.makeEndpoint(e+"Remove",r+"/{id}","DELETE",{handler:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(n({},r,{params:{id:t}}))}}),options:this.makeEndpoint(e+"Options",r,"OPTIONS")}}},{key:"request",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=r.method,o=void 0===n?(e.method||"").toLowerCase():n,u=r.path,s=void 0===u?e.path:u,c=r.params,l=void 0===c?{}:c,f=r.payload,d=r.type,p=void 0===d?e.type||this.defaultType:d,h=r.extraHeaders,v=void 0===h?{}:h,y=r.include,m=void 0===y?e.include||[]:y,b=r.filter,j=void 0===b?e.filter||{}:b,g=r.sort,w=void 0===g?e.sort||[]:g,O=r.fields,T=void 0===O?e.fields||[]:O,x=r.rawFilters,E=function(e,t){var r={};for(var n in e)t.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n]);return r}(r,["method","path","params","payload","type","extraHeaders","include","filter","sort","fields","rawFilters"]),_=r.urlRoot,k=void 0===_?this.urlRoot:_,P=r.contentType,A=void 0===P?e.contentType:P;p&&!A&&(A=i.contentTypes[p]);var R=void 0,C=[];if("get"!=o&&"options"!=o)void 0!==f&&(R=(0,i.matchContentType)(A,"form")||(0,i.matchContentType)(A,"multiForm")?(0,i.makeFormData)(f):JSON.stringify(f||{}));else if(void 0!==f)for(var q in f)C.push(q+"="+encodeURIComponent(f[q]));var S=(0,i.supplant)(s,l);S+=(0,a.jsonApiQuery)({initial:C,include:m,filter:j,sort:w,fields:T,rawFilters:(0,i.takeFirst)(x,this.rawFilters,e.rawFilters)}),k&&("/"==k[k.length-1]&&(k=k.substring(0,k.length-1)),S=k+S);var F={url:S,method:o,body:R,contentType:A,extraHeaders:v,bearer:this.bearer},M=void 0;if(this.middlewares.length){F=(0,i.makeRequest)(F);var U=!0,B=!1,D=void 0;try{for(var H,I=this.middlewares[Symbol.iterator]();!(U=(H=I.next()).done);U=!0){F=H.value.preProcess(this,F,E)}}catch(e){B=!0,D=e}finally{try{!U&&I.return&&I.return()}finally{if(B)throw D}}var N=0;for(M=this.middlewares[N++].process(this,F,E);N<this.middlewares.length;++N)if(Promise.resolve(M)==M)for(var L=function(){var e=t.middlewares[N];M=M.then(function(r){return e.process(t,r,E)})};N<this.middlewares.length;++N)L();else M=this.middlewares[N].process(this,M,E);Promise.resolve(M)!=M&&(M=ajaxWithRequest(M));var G=function(e){M=M.then(function(r){return e.postProcess(t,r,E)})},J=!0,X=!1,W=void 0;try{for(var K,V=this.middlewares.reverse()[Symbol.iterator]();!(J=(K=V.next()).done);J=!0){G(K.value)}}catch(e){X=!0,W=e}finally{try{!J&&V.return&&V.return()}finally{if(X)throw W}}}else M=(0,i.ajax)(F);return M.then(function(e){return e.data})}}]),e}(),d=function(){var e=this;this.pushMiddleware=function(t){Array.isArray(t)||(t=[t]),t.forEach(function(t){t.api=e,e.middlewares.push(t),t.contributeToApi(e)})},this.unshiftMiddleware=function(t){Array.isArray(t)||(t=[t]),t.forEach(function(t){t.api=e,e.middlewares.unshift(t)})},this.merge=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if(!t)throw new Error("Empty endpoint data given to Api.merge.");var n=!0,o=!1,a=void 0;try{for(var i,u=Object.keys(t)[Symbol.iterator]();!(n=(i=u.next()).done);n=!0){var s=i.value,c=t[s],l=/^(GET|POST|PUT|PATCH|DELETE|CRUD)$/.exec(s);if(l)if("CRUD"==l[1]){var f=r.lastIndexOf("/")+1,d=r.slice(f),p=r.slice(0,f);e.makeCrudEndpoints(d,p)}else{c instanceof Object||(c={name:c});var h=c,v=h.name,y=h.options,m=void 0===y?{}:y;e.makeEndpoint(v,r+"/",l[1],m)}else"CRUD"==c?e.makeCrudEndpoints(s,r):e.merge(c,r+"/"+s)}}catch(e){o=!0,a=e}finally{try{!n&&u.return&&u.return()}finally{if(o)throw a}}},this.makeEndpoint=function(t,r,o){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if(void 0!==e[t])throw new Error("Duplicate name in Api: "+t);var u=n({},a,{path:(0,i.addTrailingSlash)(r),method:o}),s=function(e){return this.request(u,e)},c=a.handler;if(void 0!==c){var l=function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return c.apply(void 0,[s.bind(this)].concat(t))};l.context=u,e[t]=l}else s.context=u,e[t]=s;return e[t]}};t.default=f,t.ajax=i.ajax,t.postJson=i.postJson,t.postForm=i.postForm,t.ajaxSettings=i.ajaxSettings,t.ApiError=u.ApiError,t.Middleware=s.default,t.Batch=c.default},vmXh:function(t,r){t.exports=e},xDdU:function(e,t,r){var n,o,a=r("4fRq"),i=r("I2ZF"),u=0,s=0;e.exports=function(e,t,r){var c=t&&r||0,l=t||[],f=(e=e||{}).node||n,d=void 0!==e.clockseq?e.clockseq:o;if(null==f||null==d){var p=a();null==f&&(f=n=[1|p[0],p[1],p[2],p[3],p[4],p[5]]),null==d&&(d=o=16383&(p[6]<<8|p[7]))}var h=void 0!==e.msecs?e.msecs:(new Date).getTime(),v=void 0!==e.nsecs?e.nsecs:s+1,y=h-u+(v-s)/1e4;if(y<0&&void 0===e.clockseq&&(d=d+1&16383),(y<0||h>u)&&void 0===e.nsecs&&(v=0),v>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");u=h,s=v,o=d;var m=(1e4*(268435455&(h+=122192928e5))+v)%4294967296;l[c++]=m>>>24&255,l[c++]=m>>>16&255,l[c++]=m>>>8&255,l[c++]=255&m;var b=h/4294967296*1e4&268435455;l[c++]=b>>>8&255,l[c++]=255&b,l[c++]=b>>>24&15|16,l[c++]=b>>>16&255,l[c++]=d>>>8|128,l[c++]=255&d;for(var j=0;j<6;++j)l[c+j]=f[j];return t||i(l)}},xk4V:function(e,t,r){var n=r("4fRq"),o=r("I2ZF");e.exports=function(e,t,r){var a=t&&r||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var i=(e=e||{}).random||(e.rng||n)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t)for(var u=0;u<16;++u)t[a+u]=i[u];return t||o(i)}},yMsT:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(e){function t(){var e;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var r=arguments.length,n=Array(r),o=0;o<r;o++)n[o]=arguments[o];var a=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(n)));try{Error.captureStackTrace(a,t)}catch(e){}return a}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,Error),t}();t.ApiError=n}})});
{
"name": "js-tinyapi",
"version": "0.2.2",
"version": "0.2.3",
"description": "A simple and lightweight API helper.",

@@ -5,0 +5,0 @@ "repository": {

@@ -89,4 +89,6 @@ import Cookies from 'js-cookie'

'X-Requested-With': 'XMLHttpRequest',
'Content-Type': contentType
}
if (contentType !== contentTypes.multiForm) {
headers['Content-Type'] = contentType
}
if (!isEmpty(ajaxSettings.csrf) && !(/^(GET|HEAD|OPTIONS\TRACE)$/i.test(method))) {

@@ -93,0 +95,0 @@ headers['X-CSRFToken'] = ajaxSettings.csrf

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