js-tinyapi
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,1 +0,1 @@ | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("js-cookie"));else if("function"==typeof define&&define.amd)define(["js-cookie"],t);else{var n=t("object"==typeof exports?require("js-cookie"):e["js-cookie"]);for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(this,function(e){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){e.exports=n(1)},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0}),t.ApiError=t.csrfSettings=t.postJson=void 0;var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=n(2),s=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};r(this,e),this.merge=this.merge.bind(this),this.request=this.request.bind(this),this.crud={},this.merge(t)}return i(e,[{key:"makeEndpoint",value:function(e,t,n){var r=this,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},a=o({type:"json",path:t+("/"==t[t.length-1]?"":"/"),method:n},i),s=function(e){return r.request(a,e)},u=i.handler;return void 0!==u?this[e]=function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return u.apply(void 0,[s].concat(t))}:this[e]=s,this[e]}},{key:"merge",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=!0,r=!1,o=void 0;try{for(var i,a=Object.keys(e)[Symbol.iterator]();!(n=(i=a.next()).done);n=!0){var s=i.value,u=e[s],c=/^(GET|POST|PUT|PATCH|DELETE|CRUD)$/.exec(s);if(c)if("CRUD"==c[1]){var d=t.lastIndexOf("/")+1,p=t.slice(d),f=t.slice(0,d);this.makeCrudEndpoints(p,f)}else{u instanceof Object||(u={name:u});var l=u,v=l.name,h=l.options,m=void 0===h?{}:h;this.makeEndpoint(v,t+"/",c[1],m)}else"CRUD"==u?this.makeCrudEndpoints(s,t):this.merge(u,t+"/"+s)}}catch(e){r=!0,o=e}finally{try{!n&&a.return&&a.return()}finally{if(r)throw o}}}},{key:"makeCrudEndpoints",value:function(e,t){var n=[e.slice(0,-1),e],r="/"==t[t.length-1]?"":"/",i=t+r+n[1],s=(0,a.capitalize)(n[0]),u=(0,a.capitalize)(n[1]);this.crud[n[0]]={list:this.makeEndpoint("list"+u,i,"GET"),create:this.makeEndpoint("create"+s,i,"POST",{handler:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(o({},n,{data:t}))}}),detail:this.makeEndpoint("get"+s,i+"/{id}","GET",{handler:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(o({},n,{args:{id:t}}))}}),update:this.makeEndpoint("update"+s,i+"/{id}","PATCH",{handler:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return e(o({},r,{args:{id:t},data:n}))}}),remove:this.makeEndpoint("remove"+s,i+"/{id}","DELETE",{handler:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(o({},n,{args:{id:t}}))}})}}},{key:"request",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.method,r=void 0===n?e.method:n,o=t.path,i=void 0===o?e.path:o,s=t.args,u=void 0===s?{}:s,c=t.type,d=void 0===c?e.type:c,p=t.data,f=t.contentType,l=void 0===f?e.contentType:f,v=t.include,h=void 0===v?e.include||[]:v,m=[],g=void 0;if("GET"!=r){if(void 0!==p)if("form"==d){g=new FormData;for(var y in p)g.append(y,p[y])}else g=p||{},g=JSON.stringify(g)}else if(void 0!==p)for(var E in p)m.push(E+"="+encodeURIComponent(p[E]));var j=(0,a.supplant)(i,u);return h&&h.length&&m.push("include="+h.join(",")),m.length>0&&(j+="?"+m.join("&")),console.debug("API "+r+" "+d+": "+j,p),(0,a.ajax)(j,g,r,d,l)}}]),e}();t.default=s,t.postJson=a.postJson,t.csrfSettings=a.csrfSettings,t.ApiError=a.ApiError},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e){this.message=e,this.stack=(new Error).stack}function i(e,t){return e.replace(/{([^{}]*)}/g,function(e,n){var r=t[n];if(void 0===r)throw new o("Missing string template: "+n);return"string"==typeof r||"number"==typeof r?r:e})}function a(e){return e[0].toUpperCase()+e.slice(1)}function s(e){var t=e||{},n=t.method,r=void 0===n?"get":n,o=t.dataType,i=t.contentType,a=void 0===i?"application/vnd.api+json":i,s=new Headers({"X-Requested-With":"XMLHttpRequest"});return"json"==o&&s.set("Content-Type",a),/^(GET|HEAD|OPTIONS\TRACE)$/i.test(r)||s.set("X-CSRFToken",l.token),s}function u(e,t,n,r,o){var i=new Request(e,{method:n,headers:s({method:n,dataType:r,contentType:o}),credentials:"same-origin",body:t});return fetch(i).then(function(e){return e.ok?204!=e.status?e.json():{}:e.json().catch(function(t){return Object({status:e.status})}).then(function(e){return Promise.reject(e)})})}function c(e,t,n){return u(e,JSON.stringify(t),"post","json",n)}function d(e,t,n){var r=new FormData;for(var o in t)r.append(o,t[o]);return u(e,r,"post",n)}Object.defineProperty(t,"__esModule",{value:!0}),t.csrfSettings=t.postForm=t.postJson=void 0,t.ApiError=o,t.supplant=i,t.capitalize=a,t.ajax=u;var p=n(3),f=r(p);o.prototype=Object.create(Error.prototype),o.prototype.name="ApiError";var l={token:f.default.get("csrftoken")||"NO-CSRF-TOKEN"};t.postJson=c,t.postForm=d,t.csrfSettings=l},function(e,t){e.exports=require("js-cookie")}])}); | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("js-cookie"));else if("function"==typeof define&&define.amd)define(["js-cookie"],t);else{var n=t("object"==typeof exports?require("js-cookie"):e["js-cookie"]);for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(this,function(e){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){e.exports=n(1)},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0}),t.ApiError=t.csrfSettings=t.postJson=t.ajax=void 0;var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=n(2),s=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};r(this,e),this.merge=this.merge.bind(this),this.request=this.request.bind(this),this.crud={},this.merge(t)}return i(e,[{key:"makeEndpoint",value:function(e,t,n){var r=this,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},a=o({type:"json",path:t+("/"==t[t.length-1]?"":"/"),method:n},i),s=function(e){return r.request(a,e)},u=i.handler;return void 0!==u?this[e]=function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return u.apply(void 0,[s].concat(t))}:this[e]=s,this[e]}},{key:"merge",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if(!e)throw new Error("invalid endpoint data given to Api.merge");var n=!0,r=!1,o=void 0;try{for(var i,a=Object.keys(e)[Symbol.iterator]();!(n=(i=a.next()).done);n=!0){var s=i.value,u=e[s],d=/^(GET|POST|PUT|PATCH|DELETE|CRUD)$/.exec(s);if(d)if("CRUD"==d[1]){var p=t.lastIndexOf("/")+1,c=t.slice(p),f=t.slice(0,p);this.makeCrudEndpoints(c,f)}else{u instanceof Object||(u={name:u});var l=u,v=l.name,h=l.options,m=void 0===h?{}:h;this.makeEndpoint(v,t+"/",d[1],m)}else"CRUD"==u?this.makeCrudEndpoints(s,t):this.merge(u,t+"/"+s)}}catch(e){r=!0,o=e}finally{try{!n&&a.return&&a.return()}finally{if(r)throw o}}}},{key:"makeCrudEndpoints",value:function(e,t){var n="/"==t[t.length-1]?"":"/",r=t+n+e;this.crud[e]={list:this.makeEndpoint(e+"List",r,"GET"),create:this.makeEndpoint(e+"Create",r,"POST",{handler:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(o({},n,{payload:t}))}}),detail:this.makeEndpoint(e+"Get",r+"/{id}","GET",{handler:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(o({},n,{params:{id:t}}))}}),update:this.makeEndpoint(e+"Update",r+"/{id}","PATCH",{handler:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return e(o({},r,{params:{id:t},payload:n}))}}),remove:this.makeEndpoint(e+"Remove",r+"/{id}","DELETE",{handler:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(o({},n,{params:{id:t}}))}})}}},{key:"request",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.method,r=void 0===n?e.method:n,o=t.path,i=void 0===o?e.path:o,s=t.params,u=void 0===s?{}:s,d=t.type,p=void 0===d?e.type:d,c=t.payload,f=t.contentType,l=void 0===f?e.contentType:f,v=t.include,h=void 0===v?e.include||[]:v,m=[],y=void 0;if("GET"!=r){if(void 0!==c)if("form"==p){y=new FormData;for(var g in c)y.append(g,c[g])}else y=c||{},y=JSON.stringify(y)}else if(void 0!==c)for(var E in c)m.push(E+"="+encodeURIComponent(c[E]));var j=(0,a.supplant)(i,u);return h&&h.length&&m.push("include="+h.join(",")),m.length>0&&(j+="?"+m.join("&")),console.debug("API "+r+" "+p+": "+j,c),(0,a.ajax)(j,y,r,p,l)}}]),e}();t.default=s,t.ajax=a.ajax,t.postJson=a.postJson,t.csrfSettings=a.csrfSettings,t.ApiError=a.ApiError},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e){this.message=e,this.stack=(new Error).stack}function i(e,t){return e.replace(/{([^{}]*)}/g,function(e,n){var r=t[n];if(void 0===r)throw new o("Missing string template: "+n);return"string"==typeof r||"number"==typeof r?r:e})}function a(e){return e[0].toUpperCase()+e.slice(1)}function s(e){var t=e||{},n=t.method,r=void 0===n?"get":n,o=t.dataType,i=t.contentType,a=void 0===i?"application/vnd.api+json":i,s=new Headers({"X-Requested-With":"XMLHttpRequest"});return"json"==o&&s.set("Content-Type",a),/^(GET|HEAD|OPTIONS\TRACE)$/i.test(r)||s.set("X-CSRFToken",l.token),s}function u(e,t,n,r,o){var i={method:n,headers:s({method:n,dataType:r,contentType:o}),credentials:"same-origin"};"get"!=n.toLowerCase()&&"head"!=n.toLowerCase()&&(i.body=t);var a=new Request(e,i);return fetch(a).then(function(e){return e.ok?204!=e.status?e.json():{}:e.json().catch(function(t){return Object({status:e.status})}).then(function(e){return Promise.reject(e)})})}function d(e,t,n){return u(e,JSON.stringify(t),"post","json",n)}function p(e,t,n){var r=new FormData;for(var o in t)r.append(o,t[o]);return u(e,r,"post",n)}Object.defineProperty(t,"__esModule",{value:!0}),t.csrfSettings=t.postForm=t.postJson=void 0,t.ApiError=o,t.supplant=i,t.capitalize=a,t.ajax=u;var c=n(3),f=r(c);o.prototype=Object.create(Error.prototype),o.prototype.name="ApiError";var l={token:f.default.get("csrftoken")||"NO-CSRF-TOKEN"};t.postJson=d,t.postForm=p,t.csrfSettings=l},function(e,t){e.exports=require("js-cookie")}])}); |
{ | ||
"name": "js-tinyapi", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A simple and lightweight API helper.", | ||
@@ -5,0 +5,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42637
5