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

js-tinyapi

Package Overview
Dependencies
Maintainers
2
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.0.10 to 0.1.0-alpha.0

yarn-error.log

2

lib/index.js

@@ -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)},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")}])});
!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.ajaxSettings=t.postForm=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),l=t.slice(0,p);this.makeCrudEndpoints(c,l)}else{u instanceof Object||(u={name:u});var f=u,v=f.name,h=f.options,y=void 0===h?{}:h;this.makeEndpoint(v,t+"/",d[1],y)}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}}))}}),options:this.makeEndpoint(e+"Options",r,"OPTIONS")}}},{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,l=t.contentType,f=void 0===l?e.contentType:l,v=t.include,h=void 0===v?e.include||[]:v,y=t.filter,m=void 0===y?e.filter||{}:y,g=t.sort,j=void 0===g?e.sort||[]:g,E=t.urlRoot,b=t.additionalHeaders,k=void 0===b?{}:b,T=[],O=void 0;if("GET"!=r&&"OPTIONS"!=r){if(void 0!==c)if("form"==p){O=new FormData;for(var x in c)O.append(x,c[x])}else O=c||{},O=JSON.stringify(O)}else if(void 0!==c)for(var C in c)T.push(C+"="+encodeURIComponent(c[C]));var w=(0,a.supplant)(i,u);if(h&&h.length&&T.push("include="+h.join(",")),j&&j.length&&T.push("sort="+j.join(",")),m&&Object.keys(m).length){var P=!0,S=!1,A=void 0;try{for(var R,N=Object.keys(m)[Symbol.iterator]();!(P=(R=N.next()).done);P=!0){var q=R.value;T.push("filter["+q+"]="+m[q])}}catch(e){S=!0,A=e}finally{try{!P&&N.return&&N.return()}finally{if(S)throw A}}}return T.length>0&&(w+="?"+T.join("&")),E&&("/"==E[E.length-1]&&(E=E.substring(0,E.length-1)),w=E+w),console.debug("API "+r+" "+p+": "+w,c),(0,a.ajax)(w,O,r,p,f,k,!0)}}]),e}();t.default=s,t.ajax=a.ajax,t.postJson=a.postJson,t.postForm=a.postForm,t.ajaxSettings=a.ajaxSettings,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=t.additionalHeaders,u=t.useBearer,d=void 0===u||u,p=new Headers({"X-Requested-With":"XMLHttpRequest"});"json"==o&&p.set("Content-Type",a),/^(GET|HEAD|OPTIONS\TRACE)$/i.test(r)||p.set("X-CSRFToken",f.token),d&&f.bearer&&p.set("Authorization","Bearer "+f.bearer);for(var c in s)p.set(c,s[c]);return p}function u(e,t,n,r,o,i,a){var u={method:n,headers:s({method:n,dataType:r,contentType:o,additionalHeaders:i,useBearer:a}),credentials:"same-origin"};"get"!=n.toLowerCase()&&"head"!=n.toLowerCase()&&"options"!=n.toLowerCase()&&(u.body=t);var d=new Request(e,u);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 d(e,t,n){return u(e,JSON.stringify(t),"post","json",n,{})}function p(e){var t=e.url,n=e.payload,r=e.dataType,o=e.useBearer,i=void 0===o||o,a=new FormData;for(var s in n)a.append(s,n[s]);return u(t,a,"post",r,void 0,{},i)}Object.defineProperty(t,"__esModule",{value:!0}),t.ajaxSettings=t.postForm=t.postJson=void 0,t.ApiError=o,t.supplant=i,t.capitalize=a,t.ajax=u;var c=n(3),l=r(c);o.prototype=Object.create(Error.prototype),o.prototype.name="ApiError";var f={csrf:l.default.get("csrftoken")||"NO-CSRF-TOKEN",bearer:null};t.postJson=d,t.postForm=p,t.ajaxSettings=f},function(e,t){e.exports=require("js-cookie")}])});
{
"name": "js-tinyapi",
"version": "0.0.10",
"version": "0.1.0-alpha.0",
"description": "A simple and lightweight API helper.",

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

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