@3846masa/axios-cookiejar-support
Advanced tools
Comparing version 1.0.1 to 2.0.0
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function noopEnableCookieJarSupport (instance) { | ||
return instance; | ||
function noop(axios) { | ||
return axios; | ||
} | ||
module.exports = noopEnableCookieJarSupport; | ||
exports.wrapper = noop; |
{ | ||
"name": "@3846masa/axios-cookiejar-support", | ||
"version": "2.0.0", | ||
"description": "Add tough-cookie support to axios.", | ||
"license": "MIT", | ||
"author": "3846masa", | ||
"author": "3846masa <3846masahiro+git@gmail.com>", | ||
"homepage": "https://github.com/3846masa/axios-cookiejar-support#readme", | ||
@@ -14,45 +15,36 @@ "repository": { | ||
}, | ||
"version": "1.0.1", | ||
"main": "./lib/index", | ||
"browser": { | ||
"./lib/index": "./noop.js" | ||
}, | ||
"main": "dist/index.js", | ||
"browser": "noop.js", | ||
"files": [ | ||
"index.d.ts", | ||
"lib", | ||
"noop.js" | ||
"dist", | ||
"noop.js", | ||
"!**/__tests__" | ||
], | ||
"scripts": { | ||
"prebuild": "yarn clean", | ||
"build": "babel lib -x .mjs --out-dir lib", | ||
"clean": "rimraf lib/**/*.js", | ||
"test": "mocha test.spec.js --require intelli-espower-loader" | ||
"prebuild": "rimraf dist", | ||
"build": "tsc", | ||
"semantic-release": "semantic-release", | ||
"pretest": "npm run build", | ||
"test": "ava" | ||
}, | ||
"types": "./index.d.ts", | ||
"types": "dist/index.d.ts", | ||
"dependencies": { | ||
"is-redirect": "^1.0.0", | ||
"pify": "^5.0.0" | ||
"http-cookie-agent": "^1.0.0" | ||
}, | ||
"peerDependencies": { | ||
"@types/tough-cookie": ">=2.3.3", | ||
"axios": ">=0.16.2", | ||
"tough-cookie": ">=2.3.3" | ||
"axios": "^0.20.0", | ||
"tough-cookie": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "7.12.1", | ||
"@babel/core": "7.12.3", | ||
"@babel/plugin-transform-modules-commonjs": "7.12.1", | ||
"@types/tough-cookie": "^4.0.0", | ||
"axios--0.16.x": "./axios/0.16.x", | ||
"axios--0.17.x": "./axios/0.17.x", | ||
"axios--0.18.x": "./axios/0.18.x", | ||
"axios--0.19.x": "./axios/0.19.x", | ||
"cookie": "^0.4.1", | ||
"decache": "^4.6.0", | ||
"intelli-espower-loader": "^1.0.1", | ||
"mocha": "^8.2.0", | ||
"nock": "^13.0.4", | ||
"power-assert": "^1.6.1", | ||
"rimraf": "3.0.2", | ||
"tough-cookie": "^4.0.0" | ||
"@ava/typescript": "2.0.0", | ||
"@semantic-release/changelog": "5.0.1", | ||
"@semantic-release/exec": "5.0.0", | ||
"@semantic-release/git": "9.0.1", | ||
"@types/node": "12.20.24", | ||
"@types/tough-cookie": "4.0.1", | ||
"ava": "3.15.0", | ||
"axios": "0.21.4", | ||
"semantic-release": "17.4.7", | ||
"tough-cookie": "4.0.0", | ||
"typescript": "4.4.3" | ||
}, | ||
@@ -67,4 +59,18 @@ "keywords": [ | ||
"engines": { | ||
"node": ">= 10.0.0" | ||
"node": ">=12.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"ava": { | ||
"files": [ | ||
"**/__tests__/*.spec.ts" | ||
], | ||
"typescript": { | ||
"rewritePaths": { | ||
"src/": "dist/" | ||
}, | ||
"compile": false | ||
} | ||
} | ||
} |
143
README.md
# axios-cookiejar-support | ||
Add [``tough-cookie``] support to [``axios``]. | ||
![axios-cookiejar-support](./docs/assets/ogp.jpg) | ||
[``axios``]: https://github.com/mzabriskie/axios | ||
[``tough-cookie``]: https://github.com/SalesforceEng/tough-cookie | ||
[![npm](https://flat.badgen.net/npm/v/axios-cookiejar-support)](https://www.npmjs.com/package/axios-cookiejar-support) | ||
[![license](https://flat.badgen.net/badge/license/MIT/blue)](LICENSE) | ||
[![standard-readme compliant](https://flat.badgen.net/badge/readme%20style/standard/green)](https://github.com/RichardLitt/standard-readme) | ||
--- | ||
Add `tough-cookie` support to axios. | ||
[![NPM][npm-badge]][npm] | ||
[![LICENSE][license-badge]][license] | ||
[![CircleCI][circleci-badge]][circleci] | ||
## Table of Contents | ||
[![dependencies][dependencies-badge]][dependencies-david] | ||
[![peerdependencies][peerdependencies-badge]][peerdependencies-david] | ||
[![devdependencies][devdependencies-badge]][devdependencies-david] | ||
- [Install](#install) | ||
- [Usage](#usage) | ||
- [Extended Request Config](#extended-request-config) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
[npm]: https://www.npmjs.com/package/axios-cookiejar-support | ||
[license]: https://3846masa.mit-license.org | ||
[circleci]: https://circleci.com/gh/3846masa/axios-cookiejar-support | ||
[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 | ||
[peerdependencies-badge]: https://flat.badgen.net/david/peer/3846masa/axios-cookiejar-support | ||
[devdependencies-badge]: https://flat.badgen.net/david/dev/3846masa/axios-cookiejar-support | ||
## Install | ||
```sh | ||
$ npm i axios tough-cookie axios-cookiejar-support | ||
``` | ||
**-- OR --** | ||
```sh | ||
$ npm i axios tough-cookie @3846masa/axios-cookiejar-support # Same as above | ||
npm install axios tough-cookie axios-cookiejar-support | ||
``` | ||
### TypeScript | ||
If you want to use it with TypeScript, add `@types/tough-cookie`. | ||
```sh | ||
npm i @types/tough-cookie | ||
``` | ||
## Usage | ||
```js | ||
const axios = require('axios').default; | ||
const axiosCookieJarSupport = require('axios-cookiejar-support').default; | ||
const tough = require('tough-cookie'); | ||
import axios from 'axios'; | ||
import { wrapper } from 'axios-cookiejar-support'; | ||
import { CookieJar } from 'tough-cookie'; | ||
axiosCookieJarSupport(axios); | ||
const jar = new CookieJar(); | ||
const client = wrapper(axios.create({ jar })); | ||
const cookieJar = new tough.CookieJar(); | ||
axios | ||
.get('https://google.com', { | ||
jar: cookieJar, // tough.CookieJar or boolean | ||
withCredentials: true, // If true, send cookie stored in jar | ||
}) | ||
.then(() => { | ||
console.log(cookieJar); | ||
}); | ||
await client.get('https://example.com'); | ||
``` | ||
See [examples](./example). | ||
See [examples](./examples) for more details. | ||
### Notice: Set default cookiejar | ||
`axios@>=0.19.0` cannot assign `defaults.jar` via `axios.create()` before wrapping instance. | ||
When you want to set `defaults.jar`, please set directly after wrapping instance. | ||
```js | ||
const axios = require('axios').default; | ||
const axiosCookieJarSupport = require('axios-cookiejar-support').default; | ||
const tough = require('tough-cookie'); | ||
const instance = axios.create({ | ||
// WARNING: This value will be ignored. | ||
jar: new tough.CookieJar(), | ||
}); | ||
// Set directly after wrapping instance. | ||
axiosCookieJarSupport(instance); | ||
instance.defaults.jar = new tough.CookieJar(); | ||
``` | ||
### Extended Request Config | ||
c.f.) https://github.com/mzabriskie/axios#request-config | ||
```ts | ||
import type { CookieJar } from 'tough-cookie'; | ||
```js | ||
{ | ||
// `jar` is tough.CookieJar instance or boolean. | ||
// If true, axios create CookieJar automatically. | ||
jar: undefined, // default | ||
// Silently ignore things like parse cookie errors and invalid domains. | ||
// See also https://github.com/salesforce/tough-cookie | ||
ignoreCookieErrors: false // default | ||
// **IMPORTANT** | ||
// If false, axios DONOT send cookies from cookiejar. | ||
withCredentials: false // default | ||
declare module 'axios' { | ||
interface AxiosRequestConfig { | ||
jar?: CookieJar; | ||
} | ||
} | ||
``` | ||
### Browser | ||
See also https://github.com/axios/axios#request-config . | ||
Running on browser, this library becomes noop (`config.jar` might be ignored). | ||
## Contributing | ||
## Contribution | ||
PRs accepted. | ||
1. [Fork it] | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
3. Commit your changes (`git commit -am 'Add some feature'`) | ||
4. Push to the branch (`git push origin my-new-feature`) | ||
5. Create new Pull Request | ||
## License | ||
[fork it]: http://github.com/3846masa/axios-cookiejar-support/fork | ||
## LICENSE | ||
[MIT License](https://3846masa.mit-license.org) | ||
## Author | ||
![3846masa icon][3846masa-icon] | ||
[3846masa](https://github.com/3846masa) | ||
[3846masa-icon]: https://www.gravatar.com/avatar/cfeae69aae4f4fc102960f01d35d2d86?s=50 | ||
--- | ||
## Donate | ||
[Paypal.me](https://www.paypal.me/3846masa) (Onetime donate) | ||
[MIT (c) 3846masa](./LICENSE) |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
3
11
0
5823
6
50
61
2
+ Addedhttp-cookie-agent@^1.0.0
+ Addedagent-base@6.0.2(transitive)
+ Addedaxios@0.20.0(transitive)
+ Addeddebug@4.4.0(transitive)
+ Addedhttp-cookie-agent@1.0.6(transitive)
+ Addedms@2.1.3(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedquerystringify@2.2.0(transitive)
+ Addedrequires-port@1.0.0(transitive)
+ Addedtough-cookie@4.1.4(transitive)
+ Addeduniversalify@0.2.0(transitive)
+ Addedurl-parse@1.5.10(transitive)
- Removedis-redirect@^1.0.0
- Removedpify@^5.0.0
- Removed@types/tough-cookie@4.0.5(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaxios@1.7.9(transitive)
- Removedcall-bind-apply-helpers@1.0.2(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removeddunder-proto@1.0.1(transitive)
- Removedes-define-property@1.0.1(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.1.1(transitive)
- Removedes-set-tostringtag@2.1.0(transitive)
- Removedform-data@4.0.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.7(transitive)
- Removedget-proto@1.0.1(transitive)
- Removedgopd@1.2.0(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedhasown@2.0.2(transitive)
- Removedis-redirect@1.0.0(transitive)
- Removedmath-intrinsics@1.1.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedpify@5.0.0(transitive)
- Removedproxy-from-env@1.1.0(transitive)
- Removedtldts@6.1.77(transitive)
- Removedtldts-core@6.1.77(transitive)
- Removedtough-cookie@5.1.1(transitive)