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

axios-cookiejar-support

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axios-cookiejar-support - npm Package Compare versions

Comparing version 0.5.1 to 1.0.0

108

lib/interceptors/request.js

@@ -20,73 +20,57 @@ "use strict";

function requestInterceptor(config, instance) {
return new Promise(function ($return, $error) {
let local;
local = config[_symbol.COOKIEJAR_SUPPORT_LOCAL] || {};
Object.defineProperty(config, _symbol.COOKIEJAR_SUPPORT_LOCAL, {
writable: true,
configurable: true,
enumerable: true,
value: local
});
local.backupOptions = local.backupOptions || {};
async function requestInterceptor(config, instance) {
const local = config[_symbol.COOKIEJAR_SUPPORT_LOCAL] || {};
Object.defineProperty(config, _symbol.COOKIEJAR_SUPPORT_LOCAL, {
writable: true,
configurable: true,
enumerable: true,
value: local
});
local.backupOptions = local.backupOptions || {};
if (instance.defaults.jar === true) {
instance.defaults.jar = new _toughCookie.default.CookieJar();
if (instance.defaults.jar === true) {
instance.defaults.jar = new _toughCookie.default.CookieJar();
}
if (!local.jar) {
if (config.jar === true) {
local.jar = instance.defaults.jar || new _toughCookie.default.CookieJar();
} else if (config.jar === false) {
local.jar = false;
} else {
local.jar = config.jar || instance.defaults.jar;
}
} // Redirect Setup
if (!local.jar) {
if (config.jar === true) {
local.jar = instance.defaults.jar || new _toughCookie.default.CookieJar();
} else if (config.jar === false) {
local.jar = false;
} else {
local.jar = config.jar || instance.defaults.jar;
}
} // Redirect Setup
Object.assign(local, {
redirectCount: isFinite(config.maxRedirects) ? config.maxRedirects : 5
});
Object.assign(local.backupOptions, config, local.backupOptions);
Object.assign(config, {
maxRedirects: 0
});
delete config.validateStatus; // Cookies Setup
Object.assign(local, {
redirectCount: isFinite(config.maxRedirects) ? config.maxRedirects : 5
});
Object.assign(local.backupOptions, config, local.backupOptions);
Object.assign(config, {
maxRedirects: 0
});
delete config.validateStatus; // Cookies Setup
Object.assign(local, {
cookieHeader: local.cookieHeader != null ? local.cookieHeader : (config.headers || {})['Cookie'] || ''
});
Object.assign(local, {
cookieHeader: local.cookieHeader != null ? local.cookieHeader : (config.headers || {})['Cookie'] || ''
});
if (local.jar && config.withCredentials) {
const getCookieString = (0, _pify.default)(local.jar.getCookieString.bind(local.jar));
const requestUrl = config.baseURL && !(0, _isAbsoluteURL.default)(config.url) ? (0, _combineURLs.default)(config.baseURL, config.url) : config.url;
const cookieString = await getCookieString(requestUrl);
if (local.jar && config.withCredentials) {
let getCookieString, requestUrl, cookieString;
getCookieString = (0, _pify.default)(local.jar.getCookieString.bind(local.jar));
requestUrl = config.baseURL && !(0, _isAbsoluteURL.default)(config.url) ? (0, _combineURLs.default)(config.baseURL, config.url) : config.url;
return Promise.resolve(getCookieString(requestUrl)).then(function ($await_2) {
try {
cookieString = $await_2;
if (cookieString) {
if (config.headers) {
config.headers['Cookie'] = [local.cookieHeader, cookieString].filter(c => !!c).join(';\x20');
} else {
config.headers = {
Cookie: cookieString
};
}
}
return $If_1.call(this);
} catch ($boundEx) {
return $error($boundEx);
}
}.bind(this), $error);
if (cookieString) {
if (config.headers) {
config.headers['Cookie'] = [local.cookieHeader, cookieString].filter(c => !!c).join(';\x20');
} else {
config.headers = {
Cookie: cookieString
};
}
}
}
function $If_1() {
return $return(config);
}
return $If_1.call(this);
});
return config;
}

@@ -93,0 +77,0 @@

@@ -20,81 +20,64 @@ "use strict";

function responseInterceptor(response, instance) {
return new Promise(function ($return, $error) {
var config, headers, statusCode, local, setCookie, setCookiePromiseList, cookies, cookie;
config = response.config;
headers = response.headers;
statusCode = response.status;
local = config[_symbol.COOKIEJAR_SUPPORT_LOCAL];
async function responseInterceptor(response, instance) {
// Set Cookies
const config = response.config;
const headers = response.headers;
const statusCode = response.status;
const local = config[_symbol.COOKIEJAR_SUPPORT_LOCAL];
if (!local) {
return $return(response);
}
if (!local) {
return response;
}
if (local.jar && headers['set-cookie']) {
setCookie = (0, _pify.default)(local.jar.setCookie.bind(local.jar));
setCookiePromiseList = [];
if (local.jar && headers['set-cookie']) {
const setCookie = (0, _pify.default)(local.jar.setCookie.bind(local.jar));
const setCookiePromiseList = [];
if (Array.isArray(headers['set-cookie'])) {
cookies = headers['set-cookie'];
cookies.forEach(function (cookie) {
setCookiePromiseList.push(setCookie(cookie, config.url));
});
} else {
cookie = headers['set-cookie'];
if (Array.isArray(headers['set-cookie'])) {
const cookies = headers['set-cookie'];
cookies.forEach(function (cookie) {
setCookiePromiseList.push(setCookie(cookie, config.url));
}
});
} else {
const cookie = headers['set-cookie'];
setCookiePromiseList.push(setCookie(cookie, config.url));
}
return Promise.resolve(Promise.all(setCookiePromiseList)).then(function ($await_2) {
try {
return $If_1.call(this);
} catch ($boundEx) {
return $error($boundEx);
}
}.bind(this), $error);
} // Redirect
await Promise.all(setCookiePromiseList);
} // Redirect
function $If_1() {
Object.assign(local.backupOptions, config, local.backupOptions);
delete config.baseURL;
config.url = _url.default.resolve(config.url, headers['location'] || '');
local.redirectCount--;
Object.assign(local.backupOptions, config, local.backupOptions);
delete config.baseURL;
config.url = _url.default.resolve(config.url, headers['location'] || '');
local.redirectCount--;
if (local.redirectCount >= 0 && (0, _isRedirect.default)(statusCode) && !!headers['location']) {
if (response.status !== 307) {
config.method = 'get';
}
if (local.redirectCount >= 0 && (0, _isRedirect.default)(statusCode) && !!headers['location']) {
if (response.status !== 307) {
config.method = 'get';
}
config.maxRedirects = local.redirectCount;
return $return(instance.request(config));
} // Restore
config.maxRedirects = local.redirectCount;
return instance.request(config);
} // Restore
if (local.backupOptions) {
Object.assign(config, local.backupOptions);
}
if (local.backupOptions) {
Object.assign(config, local.backupOptions);
}
if (local.jar) {
if (instance.defaults.jar && (!config.jar || config.jar === true)) {
instance.defaults.jar = local.jar;
}
if (local.jar) {
if (instance.defaults.jar && (!config.jar || config.jar === true)) {
instance.defaults.jar = local.jar;
}
config.jar = local.jar;
}
config.jar = local.jar;
}
delete config[_symbol.COOKIEJAR_SUPPORT_LOCAL]; // Validate
delete config[_symbol.COOKIEJAR_SUPPORT_LOCAL]; // Validate
return Promise.resolve(new Promise(function (resolve, reject) {
(0, _settle.default)(resolve, reject, response);
})).then(function ($await_3) {
try {
return $return(response);
} catch ($boundEx) {
return $error($boundEx);
}
}, $error);
}
return $If_1.call(this);
await new Promise(function (resolve, reject) {
(0, _settle.default)(resolve, reject, response);
});
return response;
}

@@ -101,0 +84,0 @@

@@ -14,3 +14,3 @@ {

},
"version": "0.5.1",
"version": "1.0.0",
"main": "./lib/index",

@@ -33,14 +33,15 @@ "browser": {

"dependencies": {
"@types/tough-cookie": "^2.3.3",
"is-redirect": "^1.0.0",
"pify": "^4.0.0",
"tough-cookie": "^3.0.1"
"pify": "^5.0.0"
},
"peerDependencies": {
"axios": ">=0.16.2"
"@types/tough-cookie": ">=2.3.3",
"axios": ">=0.16.2",
"tough-cookie": ">=2.3.3"
},
"devDependencies": {
"@babel/cli": "7.5.0",
"@babel/core": "7.5.4",
"@babel/plugin-transform-modules-commonjs": "7.5.0",
"@babel/cli": "7.8.4",
"@babel/core": "7.9.0",
"@babel/plugin-transform-modules-commonjs": "7.9.0",
"@types/tough-cookie": "^4.0.0",
"axios--0.16.x": "./axios/0.16.x",

@@ -52,8 +53,8 @@ "axios--0.17.x": "./axios/0.17.x",

"decache": "^4.5.1",
"fast-async": "7.0.6",
"intelli-espower-loader": "^1.0.1",
"mocha": "^6.2.0",
"nock": "^10.0.6",
"mocha": "^7.1.1",
"nock": "^12.0.3",
"power-assert": "^1.6.1",
"rimraf": "3.0.0"
"rimraf": "3.0.2",
"tough-cookie": "^4.0.0"
},

@@ -66,3 +67,6 @@ "keywords": [

"tough-cookie"
]
],
"engines": {
"node": ">= 10.0.0"
}
}

@@ -21,11 +21,11 @@ # axios-cookiejar-support

[circleci]: https://circleci.com/gh/3846masa/axios-cookiejar-support
[dependencies-david]: https://david-dm.org/3846masa/axios-cookiejar-support?path=workspaces%2Faxios-cookiejar-support&view=list
[peerdependencies-david]: https://david-dm.org/3846masa/axios-cookiejar-support?path=workspaces%2Faxios-cookiejar-support&type=peer&view=list
[devdependencies-david]: https://david-dm.org/3846masa/axios-cookiejar-support?path=workspaces%2Faxios-cookiejar-support&type=dev&view=list
[dependencies-david]: https://david-dm.org/3846masa/axios-cookiejar-support
[peerdependencies-david]: https://david-dm.org/3846masa/axios-cookiejar-support
[devdependencies-david]: https://david-dm.org/3846masa/axios-cookiejar-support
[npm-badge]: https://flat.badgen.net/npm/v/axios-cookiejar-support?icon=npm
[license-badge]: https://flat.badgen.net/badge/license/MIT/blue
[circleci-badge]: https://flat.badgen.net/circleci/github/3846masa/axios-cookiejar-support?icon=circleci
[dependencies-badge]: https://flat.badgen.net/david/dep/3846masa/axios-cookiejar-support/workspaces/axios-cookiejar-support
[peerdependencies-badge]: https://flat.badgen.net/david/peer/3846masa/axios-cookiejar-support/workspaces/axios-cookiejar-support
[devdependencies-badge]: https://flat.badgen.net/david/dev/3846masa/axios-cookiejar-support/workspaces/axios-cookiejar-support
[dependencies-badge]: https://flat.badgen.net/david/dep/3846masa/axios-cookiejar-support
[peerdependencies-badge]: https://flat.badgen.net/david/peer/3846masa/axios-cookiejar-support
[devdependencies-badge]: https://flat.badgen.net/david/dev/3846masa/axios-cookiejar-support

@@ -35,3 +35,3 @@ ## Install

```sh
$ npm i axios axios-cookiejar-support
$ npm i axios tough-cookie axios-cookiejar-support
```

@@ -42,5 +42,13 @@

```sh
$ npm i axios @3846masa/axios-cookiejar-support # Same as above
$ npm i axios tough-cookie @3846masa/axios-cookiejar-support # Same as above
```
### TypeScript
If you want to use it with TypeScript, add `@types/tough-cookie`.
```sh
npm i @types/tough-cookie
```
## Usage

@@ -47,0 +55,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