js-tinyapi
Advanced tools
Comparing version 0.0.9 to 0.0.10
@@ -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 o in n)("object"==typeof exports?exports:e)[o]=n[o]}}(this,function(e){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={exports:{},id:o,loaded:!1};return e[o].call(r.exports,r,r.exports,t),r.loaded=!0,r.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 o(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 r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},i=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),a=n(2),s=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};o(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 o=this,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},a=r({type:"json",path:t+("/"==t[t.length-1]?"":"/"),method:n},i),s=function(e){return o.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,o=!1,r=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){o=!0,r=e}finally{try{!n&&a.return&&a.return()}finally{if(o)throw r}}}},{key:"makeCrudEndpoints",value:function(e,t){var n="/"==t[t.length-1]?"":"/",o=t+n+e;this.crud[e]={list:this.makeEndpoint(e+"List",o,"GET"),create:this.makeEndpoint(e+"Create",o,"POST",{handler:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(r({},n,{payload:t}))}}),detail:this.makeEndpoint(e+"Get",o+"/{id}","GET",{handler:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(r({},n,{params:{id:t}}))}}),update:this.makeEndpoint(e+"Update",o+"/{id}","PATCH",{handler:function(e,t,n){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return e(r({},o,{params:{id:t},payload:n}))}}),remove:this.makeEndpoint(e+"Remove",o+"/{id}","DELETE",{handler:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(r({},n,{params:{id:t}}))}}),options:this.makeEndpoint(e+"Options",o,"OPTIONS")}}},{key:"request",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.method,o=void 0===n?e.method:n,r=t.path,i=void 0===r?e.path:r,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=t.urlRoot,y=t.additionalHeaders,g=void 0===y?{}:y,E=[],j=void 0;if("GET"!=o&&"OPTIONS"!=o){if(void 0!==c)if("form"==p){j=new FormData;for(var k in c)j.append(k,c[k])}else j=c||{},j=JSON.stringify(j)}else if(void 0!==c)for(var T in c)E.push(T+"="+encodeURIComponent(c[T]));var O=(0,a.supplant)(i,u);return h&&h.length&&E.push("include="+h.join(",")),E.length>0&&(O+="?"+E.join("&")),m&&("/"==m[m.length-1]&&(m=m.substring(0,m.length-1)),O=m+O),console.debug("API "+o+" "+p+": "+O,c),(0,a.ajax)(O,j,o,p,l,g)}}]),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 o(e){return e&&e.__esModule?e:{default:e}}function r(e){this.message=e,this.stack=(new Error).stack}function i(e,t){return e.replace(/{([^{}]*)}/g,function(e,n){var o=t[n];if(void 0===o)throw new r("Missing string template: "+n);return"string"==typeof o||"number"==typeof o?o:e})}function a(e){return e[0].toUpperCase()+e.slice(1)}function s(e){var t=e||{},n=t.method,o=void 0===n?"get":n,r=t.dataType,i=t.contentType,a=void 0===i?"application/vnd.api+json":i,s=t.additionalHeaders,u=new Headers({"X-Requested-With":"XMLHttpRequest"});"json"==r&&u.set("Content-Type",a),/^(GET|HEAD|OPTIONS\TRACE)$/i.test(o)||u.set("X-CSRFToken",l.token);for(var d in s)u.set(d,s[d]);return u}function u(e,t,n,o,r,i){var a={method:n,headers:s({method:n,dataType:o,contentType:r,additionalHeaders:i}),credentials:"same-origin"};"get"!=n.toLowerCase()&&"head"!=n.toLowerCase()&&"options"!=n.toLowerCase()&&(a.body=t);var u=new Request(e,a);return fetch(u).then(function(e){return e.ok?204!=e.status?TINYAPI_NODE?e: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 o=new FormData;for(var r in t)o.append(r,t[r]);return u(e,o,"post",n,{})}Object.defineProperty(t,"__esModule",{value:!0}),t.csrfSettings=t.postForm=t.postJson=void 0,t.ApiError=r,t.supplant=i,t.capitalize=a,t.ajax=u;var c=n(3),f=o(c);r.prototype=Object.create(Error.prototype),r.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")}])}); | ||
!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 o in n)("object"==typeof exports?exports:e)[o]=n[o]}}(this,function(e){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={exports:{},id:o,loaded:!1};return e[o].call(r.exports,r,r.exports,t),r.loaded=!0,r.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 o(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 r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},i=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),a=n(2),s=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};o(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 o=this,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},a=r({type:"json",path:t+("/"==t[t.length-1]?"":"/"),method:n},i),s=function(e){return o.request(a,e)},d=i.handler;return void 0!==d?this[e]=function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return d.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,o=!1,r=void 0;try{for(var i,a=Object.keys(e)[Symbol.iterator]();!(n=(i=a.next()).done);n=!0){var s=i.value,d=e[s],u=/^(GET|POST|PUT|PATCH|DELETE|CRUD)$/.exec(s);if(u)if("CRUD"==u[1]){var p=t.lastIndexOf("/")+1,c=t.slice(p),f=t.slice(0,p);this.makeCrudEndpoints(c,f)}else{d instanceof Object||(d={name:d});var l=d,v=l.name,h=l.options,m=void 0===h?{}:h;this.makeEndpoint(v,t+"/",u[1],m)}else"CRUD"==d?this.makeCrudEndpoints(s,t):this.merge(d,t+"/"+s)}}catch(e){o=!0,r=e}finally{try{!n&&a.return&&a.return()}finally{if(o)throw r}}}},{key:"makeCrudEndpoints",value:function(e,t){var n="/"==t[t.length-1]?"":"/",o=t+n+e;this.crud[e]={list:this.makeEndpoint(e+"List",o,"GET"),create:this.makeEndpoint(e+"Create",o,"POST",{handler:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(r({},n,{payload:t}))}}),detail:this.makeEndpoint(e+"Get",o+"/{id}","GET",{handler:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(r({},n,{params:{id:t}}))}}),update:this.makeEndpoint(e+"Update",o+"/{id}","PATCH",{handler:function(e,t,n){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return e(r({},o,{params:{id:t},payload:n}))}}),remove:this.makeEndpoint(e+"Remove",o+"/{id}","DELETE",{handler:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(r({},n,{params:{id:t}}))}}),options:this.makeEndpoint(e+"Options",o,"OPTIONS")}}},{key:"request",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.method,o=void 0===n?e.method:n,r=t.path,i=void 0===r?e.path:r,s=t.params,d=void 0===s?{}:s,u=t.type,p=void 0===u?e.type:u,c=t.payload,f=t.contentType,l=void 0===f?e.contentType:f,v=t.include,h=void 0===v?e.include||[]:v,m=t.urlRoot,y=t.additionalHeaders,g=void 0===y?{}:y,E=[],j=void 0;if("GET"!=o&&"OPTIONS"!=o){if(void 0!==c)if("form"==p){j=new FormData;for(var k in c)j.append(k,c[k])}else j=c||{},j=JSON.stringify(j)}else if(void 0!==c)for(var T in c)E.push(T+"="+encodeURIComponent(c[T]));var O=(0,a.supplant)(i,d);return h&&h.length&&E.push("include="+h.join(",")),E.length>0&&(O+="?"+E.join("&")),m&&("/"==m[m.length-1]&&(m=m.substring(0,m.length-1)),O=m+O),console.debug("API "+o+" "+p+": "+O,c),(0,a.ajax)(O,j,o,p,l,g)}}]),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 o(e){return e&&e.__esModule?e:{default:e}}function r(e){this.message=e,this.stack=(new Error).stack}function i(e,t){return e.replace(/{([^{}]*)}/g,function(e,n){var o=t[n];if(void 0===o)throw new r("Missing string template: "+n);return"string"==typeof o||"number"==typeof o?o:e})}function a(e){return e[0].toUpperCase()+e.slice(1)}function s(e){var t=e||{},n=t.method,o=void 0===n?"get":n,r=t.dataType,i=t.contentType,a=void 0===i?"application/vnd.api+json":i,s=t.additionalHeaders,d=new Headers({"X-Requested-With":"XMLHttpRequest"});"json"==r&&d.set("Content-Type",a),/^(GET|HEAD|OPTIONS\TRACE)$/i.test(o)||d.set("X-CSRFToken",l.token);for(var u in s)d.set(u,s[u]);return d}function d(e,t,n,o,r,i){var a={method:n,headers:s({method:n,dataType:o,contentType:r,additionalHeaders:i}),credentials:"same-origin"};"get"!=n.toLowerCase()&&"head"!=n.toLowerCase()&&"options"!=n.toLowerCase()&&(a.body=t);var d=new Request(e,a);return fetch(d).then(function(e){return e.ok?204!=e.status?"undefined"!=typeof TINYAPI_NODE&&TINYAPI_NODE?e:e.json():{}:e.json().catch(function(t){return Object({status:e.status})}).then(function(e){return Promise.reject(e)})})}function u(e,t,n){return d(e,JSON.stringify(t),"post","json",n,{})}function p(e,t,n){var o=new FormData;for(var r in t)o.append(r,t[r]);return d(e,o,"post",n,{})}Object.defineProperty(t,"__esModule",{value:!0}),t.csrfSettings=t.postForm=t.postJson=void 0,t.ApiError=r,t.supplant=i,t.capitalize=a,t.ajax=d;var c=n(3),f=o(c);r.prototype=Object.create(Error.prototype),r.prototype.name="ApiError";var l={token:f.default.get("csrftoken")||"NO-CSRF-TOKEN"};t.postJson=u,t.postForm=p,t.csrfSettings=l},function(e,t){e.exports=require("js-cookie")}])}); |
{ | ||
"name": "js-tinyapi", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"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
43138