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

apisauce

Package Overview
Dependencies
Maintainers
3
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apisauce - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

1

apisauce.d.ts

@@ -28,2 +28,3 @@ import {AxiosInstance, AxiosRequestConfig, AxiosError, CancelTokenStatic} from 'axios';

baseURL: string | undefined;
axiosInstance: AxiosInstance | undefined;
}

@@ -30,0 +31,0 @@

2

dist/apisauce.js

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

"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var _partial=_interopDefault(require("ramda/src/partial")),_curry=_interopDefault(require("ramda/src/curry")),_pipe=_interopDefault(require("ramda/src/pipe")),_keys=_interopDefault(require("ramda/src/keys")),_forEach=_interopDefault(require("ramda/src/forEach")),_dissoc=_interopDefault(require("ramda/src/dissoc")),_merge=_interopDefault(require("ramda/src/merge")),_prop=_interopDefault(require("ramda/src/prop")),_always=_interopDefault(require("ramda/src/always")),_ifElse=_interopDefault(require("ramda/src/ifElse")),_contains=_interopDefault(require("ramda/src/contains")),_gte=_interopDefault(require("ramda/src/gte")),_curryN=_interopDefault(require("ramda/src/curryN")),_T=_interopDefault(require("ramda/src/T")),_is=_interopDefault(require("ramda/src/is")),_identity=_interopDefault(require("ramda/src/identity")),_isNil=_interopDefault(require("ramda/src/isNil")),_cond=_interopDefault(require("ramda/src/cond")),axios=_interopDefault(require("axios")),__assign=function(){return(__assign=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var a in r=arguments[t])Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a]);return e}).apply(this,arguments)},__awaiter=function(e,r,t,n){return new(t||(t=Promise))(function(a,i){function o(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){e.done?a(e.value):new t(function(r){r(e.value)}).then(o,s)}u((n=n.apply(e,r||[])).next())})},__generator=function(e,r){var t,n,a,i,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;o;)try{if(t=1,n&&(a=2&i[0]?n.return:i[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,i[1])).done)return a;switch(n=0,a&&(i=[2&i[0],a.value]),i[0]){case 0:case 1:a=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,n=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!(a=(a=o.trys).length>0&&a[a.length-1])&&(6===i[0]||2===i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]<a[3])){o.label=i[1];break}if(6===i[0]&&o.label<a[1]){o.label=a[1],a=i;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(i);break}a[2]&&o.ops.pop(),o.trys.pop();continue}i=r.call(e,o)}catch(e){i=[6,e],n=0}finally{t=a=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}},_this=void 0,toNumber=_cond([[_isNil,_identity],[_is(Number),_identity],[_T,function(e){return Number(e)}]]),isWithin=_curryN(3,function(e,r,t){var n=_is(Number);return n(e)&&n(r)&&n(t)&&_gte(t,e)&&_gte(r,t)}),containsText=_curryN(2,function(e,r){return _contains(r,e)}),isPromise=function(e){return!!e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then},DEFAULT_HEADERS={Accept:"application/json","Content-Type":"application/json"},DEFAULT_CONFIG={timeout:0},NONE=null,CLIENT_ERROR="CLIENT_ERROR",SERVER_ERROR="SERVER_ERROR",TIMEOUT_ERROR="TIMEOUT_ERROR",CONNECTION_ERROR="CONNECTION_ERROR",NETWORK_ERROR="NETWORK_ERROR",UNKNOWN_ERROR="UNKNOWN_ERROR",CANCEL_ERROR="CANCEL_ERROR",TIMEOUT_ERROR_CODES=["ECONNABORTED"],NODEJS_CONNECTION_ERROR_CODES=["ENOTFOUND","ECONNREFUSED","ECONNRESET"],in200s=isWithin(200,299),in400s=isWithin(400,499),in500s=isWithin(500,599),statusNil=_ifElse(_isNil,_always(void 0),_prop("status")),getProblemFromError=function(e){return"Network Error"===e.message?NETWORK_ERROR:axios.isCancel(e)?CANCEL_ERROR:_cond([[_isNil,function(){return getProblemFromStatus(statusNil(e.response))}],[containsText(TIMEOUT_ERROR_CODES),_always(TIMEOUT_ERROR)],[containsText(NODEJS_CONNECTION_ERROR_CODES),_always(CONNECTION_ERROR)],[_T,_always(UNKNOWN_ERROR)]])(e.code)},getProblemFromStatus=function(e){return _cond([[_isNil,_always(UNKNOWN_ERROR)],[in200s,_always(NONE)],[in400s,_always(CLIENT_ERROR)],[in500s,_always(SERVER_ERROR)],[_T,_always(UNKNOWN_ERROR)]])(e)},create=function(e){var r=_merge(DEFAULT_HEADERS,e.headers||{}),t=_merge(DEFAULT_CONFIG,_dissoc("headers",e)),n=axios.create(t),a=[],i=[],o=[],s=[],u=function(e,t){return r[e]=t,n},R=function(e,r,t,n){return void 0===t&&(t={}),void 0===n&&(n={}),c(_merge({url:r,params:t,method:e},n))},_=function(e,r,t,n){return void 0===t&&(t=null),void 0===n&&(n={}),c(_merge({url:r,method:e,data:t},n))},c=function(e){return __awaiter(_this,void 0,void 0,function(){var t,a,s;return __generator(this,function(u){switch(u.label){case 0:if(e.headers=__assign({},r,e.headers),i.length>0&&_forEach(function(r){return r(e)},i),!(o.length>0))return[3,6];t=0,u.label=1;case 1:return t<o.length?(a=o[t](e),isPromise(a)?[4,a]:[3,3]):[3,6];case 2:return u.sent(),[3,5];case 3:return[4,a(e)];case 4:u.sent(),u.label=5;case 5:return t++,[3,1];case 6:return s=_pipe(l(toNumber(new Date)),E),[2,n.request(e).then(s).catch(s)]}})})},E=function(e){return a.forEach(function(r){try{r(e)}catch(e){}}),e},l=_curry(function(e,r){var t=toNumber(new Date)-e,n=r instanceof Error||axios.isCancel(r),a=r,i=r,o=n?i.response:a,u=o&&o.status||null,R=n?getProblemFromError(r):getProblemFromStatus(u),_=n?i:null,c=in200s(u),E=r.config||null,l={duration:t,problem:R,originalError:_,ok:c,status:u,headers:o&&o.headers||null,config:E,data:o&&o.data||null};return s.length>0&&_forEach(function(e){return e(l)},s),l});return{axiosInstance:n,monitors:a,addMonitor:function(e){a.push(e)},requestTransforms:i,asyncRequestTransforms:o,responseTransforms:s,addRequestTransform:function(e){return i.push(e)},addAsyncRequestTransform:function(e){return o.push(e)},addResponseTransform:function(e){return s.push(e)},setHeader:u,setHeaders:function(e){return _forEach(function(r){return u(r,e[r])},_keys(e)),n},deleteHeader:function(e){return delete r[e],n},headers:r,setBaseURL:function(e){return n.defaults.baseURL=e,n},getBaseURL:function(){return n.defaults.baseURL},get:_partial(R,["get"]),delete:_partial(R,["delete"]),head:_partial(R,["head"]),post:_partial(_,["post"]),put:_partial(_,["put"]),patch:_partial(_,["patch"]),link:_partial(R,["link"]),unlink:_partial(R,["unlink"])}},isCancel=axios.isCancel,CancelToken=axios.CancelToken,apisauce={DEFAULT_HEADERS:DEFAULT_HEADERS,NONE:NONE,CLIENT_ERROR:CLIENT_ERROR,SERVER_ERROR:SERVER_ERROR,TIMEOUT_ERROR:TIMEOUT_ERROR,CONNECTION_ERROR:CONNECTION_ERROR,NETWORK_ERROR:NETWORK_ERROR,UNKNOWN_ERROR:UNKNOWN_ERROR,create:create,isCancel:isCancel,CancelToken:CancelToken};exports.DEFAULT_HEADERS=DEFAULT_HEADERS,exports.NONE=NONE,exports.CLIENT_ERROR=CLIENT_ERROR,exports.SERVER_ERROR=SERVER_ERROR,exports.TIMEOUT_ERROR=TIMEOUT_ERROR,exports.CONNECTION_ERROR=CONNECTION_ERROR,exports.NETWORK_ERROR=NETWORK_ERROR,exports.UNKNOWN_ERROR=UNKNOWN_ERROR,exports.CANCEL_ERROR=CANCEL_ERROR,exports.getProblemFromError=getProblemFromError,exports.getProblemFromStatus=getProblemFromStatus,exports.create=create,exports.isCancel=isCancel,exports.CancelToken=CancelToken,exports.default=apisauce;
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var _partial=_interopDefault(require("ramda/src/partial")),_curry=_interopDefault(require("ramda/src/curry")),_pipe=_interopDefault(require("ramda/src/pipe")),_keys=_interopDefault(require("ramda/src/keys")),_forEach=_interopDefault(require("ramda/src/forEach")),_dissoc=_interopDefault(require("ramda/src/dissoc")),_merge=_interopDefault(require("ramda/src/merge")),_prop=_interopDefault(require("ramda/src/prop")),_always=_interopDefault(require("ramda/src/always")),_ifElse=_interopDefault(require("ramda/src/ifElse")),_contains=_interopDefault(require("ramda/src/contains")),_gte=_interopDefault(require("ramda/src/gte")),_curryN=_interopDefault(require("ramda/src/curryN")),_T=_interopDefault(require("ramda/src/T")),_is=_interopDefault(require("ramda/src/is")),_identity=_interopDefault(require("ramda/src/identity")),_isNil=_interopDefault(require("ramda/src/isNil")),_cond=_interopDefault(require("ramda/src/cond")),axios=_interopDefault(require("axios")),__assign=function(){return(__assign=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var a in r=arguments[t])Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a]);return e}).apply(this,arguments)},__awaiter=function(e,r,t,n){return new(t||(t=Promise))(function(a,i){function o(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){e.done?a(e.value):new t(function(r){r(e.value)}).then(o,s)}u((n=n.apply(e,r||[])).next())})},__generator=function(e,r){var t,n,a,i,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;o;)try{if(t=1,n&&(a=2&i[0]?n.return:i[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,i[1])).done)return a;switch(n=0,a&&(i=[2&i[0],a.value]),i[0]){case 0:case 1:a=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,n=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!(a=(a=o.trys).length>0&&a[a.length-1])&&(6===i[0]||2===i[0])){o=0;continue}if(3===i[0]&&(!a||i[1]>a[0]&&i[1]<a[3])){o.label=i[1];break}if(6===i[0]&&o.label<a[1]){o.label=a[1],a=i;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(i);break}a[2]&&o.ops.pop(),o.trys.pop();continue}i=r.call(e,o)}catch(e){i=[6,e],n=0}finally{t=a=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}},_this=void 0,toNumber=_cond([[_isNil,_identity],[_is(Number),_identity],[_T,function(e){return Number(e)}]]),isWithin=_curryN(3,function(e,r,t){var n=_is(Number);return n(e)&&n(r)&&n(t)&&_gte(t,e)&&_gte(r,t)}),containsText=_curryN(2,function(e,r){return _contains(r,e)}),isPromise=function(e){return!!e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then},DEFAULT_HEADERS={Accept:"application/json","Content-Type":"application/json"},DEFAULT_CONFIG={timeout:0},NONE=null,CLIENT_ERROR="CLIENT_ERROR",SERVER_ERROR="SERVER_ERROR",TIMEOUT_ERROR="TIMEOUT_ERROR",CONNECTION_ERROR="CONNECTION_ERROR",NETWORK_ERROR="NETWORK_ERROR",UNKNOWN_ERROR="UNKNOWN_ERROR",CANCEL_ERROR="CANCEL_ERROR",TIMEOUT_ERROR_CODES=["ECONNABORTED"],NODEJS_CONNECTION_ERROR_CODES=["ENOTFOUND","ECONNREFUSED","ECONNRESET"],in200s=isWithin(200,299),in400s=isWithin(400,499),in500s=isWithin(500,599),statusNil=_ifElse(_isNil,_always(void 0),_prop("status")),getProblemFromError=function(e){return"Network Error"===e.message?NETWORK_ERROR:axios.isCancel(e)?CANCEL_ERROR:_cond([[_isNil,function(){return getProblemFromStatus(statusNil(e.response))}],[containsText(TIMEOUT_ERROR_CODES),_always(TIMEOUT_ERROR)],[containsText(NODEJS_CONNECTION_ERROR_CODES),_always(CONNECTION_ERROR)],[_T,_always(UNKNOWN_ERROR)]])(e.code)},getProblemFromStatus=function(e){return _cond([[_isNil,_always(UNKNOWN_ERROR)],[in200s,_always(NONE)],[in400s,_always(CLIENT_ERROR)],[in500s,_always(SERVER_ERROR)],[_T,_always(UNKNOWN_ERROR)]])(e)},create=function(e){var r,t=_merge(DEFAULT_HEADERS,e.headers||{});if(e.axiosInstance)r=e.axiosInstance;else{var n=_merge(DEFAULT_CONFIG,_dissoc("headers",e));r=axios.create(n)}var a=[],i=[],o=[],s=[],u=function(e,n){return t[e]=n,r},R=function(e,r,t,n){return void 0===t&&(t={}),void 0===n&&(n={}),c(_merge({url:r,params:t,method:e},n))},_=function(e,r,t,n){return void 0===t&&(t=null),void 0===n&&(n={}),c(_merge({url:r,method:e,data:t},n))},c=function(e){return __awaiter(_this,void 0,void 0,function(){var n,a,s;return __generator(this,function(u){switch(u.label){case 0:if(e.headers=__assign({},t,e.headers),i.length>0&&_forEach(function(r){return r(e)},i),!(o.length>0))return[3,6];n=0,u.label=1;case 1:return n<o.length?(a=o[n](e),isPromise(a)?[4,a]:[3,3]):[3,6];case 2:return u.sent(),[3,5];case 3:return[4,a(e)];case 4:u.sent(),u.label=5;case 5:return n++,[3,1];case 6:return s=_pipe(l(toNumber(new Date)),E),[2,r.request(e).then(s).catch(s)]}})})},E=function(e){return a.forEach(function(r){try{r(e)}catch(e){}}),e},l=_curry(function(e,r){var t=toNumber(new Date)-e,n=r instanceof Error||axios.isCancel(r),a=r,i=r,o=n?i.response:a,u=o&&o.status||null,R=n?getProblemFromError(r):getProblemFromStatus(u),_=n?i:null,c=in200s(u),E=r.config||null,l={duration:t,problem:R,originalError:_,ok:c,status:u,headers:o&&o.headers||null,config:E,data:o&&o.data||null};return s.length>0&&_forEach(function(e){return e(l)},s),l});return{axiosInstance:r,monitors:a,addMonitor:function(e){a.push(e)},requestTransforms:i,asyncRequestTransforms:o,responseTransforms:s,addRequestTransform:function(e){return i.push(e)},addAsyncRequestTransform:function(e){return o.push(e)},addResponseTransform:function(e){return s.push(e)},setHeader:u,setHeaders:function(e){return _forEach(function(r){return u(r,e[r])},_keys(e)),r},deleteHeader:function(e){return delete t[e],r},headers:t,setBaseURL:function(e){return r.defaults.baseURL=e,r},getBaseURL:function(){return r.defaults.baseURL},get:_partial(R,["get"]),delete:_partial(R,["delete"]),head:_partial(R,["head"]),post:_partial(_,["post"]),put:_partial(_,["put"]),patch:_partial(_,["patch"]),link:_partial(R,["link"]),unlink:_partial(R,["unlink"])}},isCancel=axios.isCancel,CancelToken=axios.CancelToken,apisauce={DEFAULT_HEADERS:DEFAULT_HEADERS,NONE:NONE,CLIENT_ERROR:CLIENT_ERROR,SERVER_ERROR:SERVER_ERROR,TIMEOUT_ERROR:TIMEOUT_ERROR,CONNECTION_ERROR:CONNECTION_ERROR,NETWORK_ERROR:NETWORK_ERROR,UNKNOWN_ERROR:UNKNOWN_ERROR,create:create,isCancel:isCancel,CancelToken:CancelToken};exports.DEFAULT_HEADERS=DEFAULT_HEADERS,exports.NONE=NONE,exports.CLIENT_ERROR=CLIENT_ERROR,exports.SERVER_ERROR=SERVER_ERROR,exports.TIMEOUT_ERROR=TIMEOUT_ERROR,exports.CONNECTION_ERROR=CONNECTION_ERROR,exports.NETWORK_ERROR=NETWORK_ERROR,exports.UNKNOWN_ERROR=UNKNOWN_ERROR,exports.CANCEL_ERROR=CANCEL_ERROR,exports.getProblemFromError=getProblemFromError,exports.getProblemFromStatus=getProblemFromStatus,exports.create=create,exports.isCancel=isCancel,exports.CancelToken=CancelToken,exports.default=apisauce;
{
"version": "1.0.3",
"version": "1.0.4",
"author": "Steve Kellock <steve@kellock.ca>",

@@ -10,3 +10,3 @@ "ava": {

"dependencies": {
"axios": "^0.18.1",
"axios": "^0.19.0",
"ramda": "^0.25.0"

@@ -13,0 +13,0 @@ },

@@ -95,2 +95,13 @@ # Apisauce

You can also pass an already created axios instance
```js
import axios from 'axios'
import { create } from 'apisauce'
const customAxiosInstance = axios.create({ baseURL: 'https://example.com/api/v3' })
const apisauceInstance = create({ axiosInstance: customAxiosInstance })
```
## Calling The API

@@ -97,0 +108,0 @@

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