{"name":"http-cookie-agent","version":"2.1.2","description":"Allows cookies with every Node.js HTTP clients.","keywords":["agent","axios","cookies","fetch","got","http","https","needle","node-fetch","phin","request","superagent","tough-cookie","urllib","undici"],"homepage":"https://github.com/3846masa/http-cookie-agent#readme","bugs":{"url":"https://github.com/3846masa/http-cookie-agent/issues"},"repository":{"type":"git","url":"git+https://github.com/3846masa/http-cookie-agent.git"},"license":"MIT","author":{"name":"3846masa","email":"3846masahiro+git@gmail.com"},"exports":{".":"./dist/index.js","./undici":"./undici/index.js"},"main":"dist/index.js","types":"index.d.ts","scripts":{"prebuild":"rimraf dist","build":"npm-run-all build:*","build:cjs":"babel src --out-dir dist --extensions .ts --out-file-extension .js","build:mjs":"babel src --out-dir dist --extensions .mts --out-file-extension .mjs","semantic-release":"semantic-release","pretest":"npm run build","test":"ava","lint":"npm-run-all lint:*","lint:tsc":"tsc --noEmit","lint:eslint":"eslint --ext .js,.ts,.mjs,.mts .","lint:prettier":"prettier --check .","format":"npm-run-all format:*","format:eslint":"eslint --fix --ext .js,.ts,.mjs,.mts .","format:prettier":"prettier --write ."},"ava":{"files":["dist/**/__tests__/*.spec.js","dist/**/__tests__/*.spec.mjs"],"workerThreads":false},"dependencies":{"agent-base":"^6.0.2"},"devDependencies":{"@3846masa/configs":"github:3846masa/configs#a45bbd3e20a59f0c83aef18648144d8f04884f9b","@babel/cli":"^7.17.10","@babel/core":"7.17.10","@babel/preset-env":"^7.17.10","@babel/preset-typescript":"^7.16.7","@hapi/wreck":"17.2.0","@semantic-release/changelog":"6.0.1","@semantic-release/git":"10.0.1","@types/deasync":"0.1.2","@types/http-proxy":"1.17.9","@types/needle":"2.5.3","@types/node":"14.18.16","@types/request":"2.48.8","@types/semver":"^7.3.9","@types/superagent":"4.1.15","@types/tough-cookie":"4.0.2","agentkeepalive":"4.2.1","ava":"4.2.0","axios":"0.27.2","deasync":"0.1.26","got":"12.0.4","http-proxy":"1.18.1","http-proxy-agent":"5.0.0","needle":"3.1.0","node-fetch":"3.2.4","npm-run-all":"4.1.5","phin":"3.6.1","request":"2.88.2","rimraf":"^3.0.2","semantic-release":"19.0.2","semver":"^7.3.7","superagent":"7.1.3","tough-cookie":"4.0.0","typescript":"4.6.4","undici":"5.1.1","urllib":"2.38.0"},"peerDependencies":{"deasync":"^0.1.26","tough-cookie":"^4.0.0","undici":"^5.1.1"},"peerDependenciesMeta":{"deasync":{"optional":true},"undici":{"optional":true}},"engines":{"node":">=14.18.0 <15.0.0 || >=16.0.0"},"gitHead":"e4d7d4ff89af735334e57695536ea9b488d34ae0","_id":"http-cookie-agent@2.1.2","_nodeVersion":"16.15.0","_npmVersion":"8.8.0","dist":{"integrity":"sha512-JW4vAM0mx8fG49Kz0Lg5rj+k9uGH0/qXLguo+axyBUZ5bOpKrSkIpb2UaV3i4agqkD2zC5vLZMYEjSGSlErhwA==","shasum":"b39aab0f79dd1cb9b68f6017b03ea12b8dc09478","tarball":"http://registry-npm.ywwl.com/http-cookie-agent/download/http-cookie-agent-2.1.2.tgz","fileCount":22,"unpackedSize":31004,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD0WFL37Lh+BgIt9en9osYrtqsuGpj7LXP0a+eRK/hAgQIgKr0HZLsFX9MiGvUopvgyhIecydOgGAF46UADV25w9gU="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJidpAxACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmo/2Q/+NtOSAJr1wLbmvmdJf+vTkz5Ny2wQt/lJ5m5gD4EBe2vl7P4t\r\nBidRywq3VGB2ZaedVT2C0844mzh2FEQe4pdITPyemPy2momfC1HC0AGiq1n9\r\nlOKBozDSalWNHHX4VG48M375Lmb9LBAikJZvs2ZnqlIiaRK9hgAZeEa9oNIp\r\nlCEvxNjdy+mGvzo3TDeH1j1B5keQzw3j96YoVE9kwpVAO1zVZ+KhU2swRr8z\r\nEy+WiiWU5gaDg8fErYGcjmh3nmYRNpTPbAIw1xkamT5j/Oo9s4ZGx2uQ4jE1\r\nYVM3hQCf5FcMAMGSjzH5LQUAWNPEnQ7kWE9r30X50U2PhE2LBizD3b3dt1lq\r\ntxMwN6IQY9DWBHQgchLBtI+hmh0S9DwHdNgXmfuononiF5GJaddDz5UmD8qL\r\nTWOvHz0xwaflshTPdyiVTqnakVoKSd0iJdrx8MB6okO026MjiKvHPr1N35lr\r\nC7RukCrgR+AibUK1PtekIMbz3GqyZ2nQgMym1WaYsptl12gB5UUr7z4bArG5\r\nlNc/xGgawyMLPTbzp67u9q/2lEsl8HUdrLl5bSqk8Om9tIeTogRNXPndnXBH\r\nO95dYen0rdKEin/23E9qRYS9P/viv4Ib3KFnSIpUC6N5YmomE9syvH81iI7Y\r\n1BLSoy5q7IHwBbnJZcB+F4I08m3DMEKsF8E=\r\n=kNfO\r\n-----END PGP SIGNATURE-----\r\n","size":8055,"noattachment":false,"key":"/http-cookie-agent/-/http-cookie-agent-2.1.2.tgz"},"_npmUser":{"name":"3846masa","email":"3846masahiro+git@gmail.com"},"directories":{},"maintainers":[{"name":"3846masa","email":"3846masahiro+git@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/http-cookie-agent_2.1.2_1651937329078_0.4557209711851036"},"_hasShrinkwrap":false,"readme":"# HTTP Cookie Agent\n\n![HTTP Cookie Agent](./docs/assets/ogp.jpg)\n\n[![github sponsors](https://flat.badgen.net/badge/GitHub%20Sponsors/Support%20me%20%E2%9D%A4/ff69b4?icon=github)](https://github.com/sponsors/3846masa)\n[![npm](https://flat.badgen.net/npm/v/http-cookie-agent)](https://www.npmjs.com/package/http-cookie-agent)\n[![license](https://flat.badgen.net/badge/license/MIT/blue)](LICENSE)\n[![standard-readme compliant](https://flat.badgen.net/badge/readme%20style/standard/green)](https://github.com/RichardLitt/standard-readme)\n\nAllows cookies with every Node.js HTTP clients (e.g. Node.js global fetch, undici, axios, node-fetch).\n\n## Table of Contents\n\n- [Install](#install)\n- [Usage](#usage)\n  - [Supported libraries](#supported-libraries)\n  - [Using with an asynchronous Cookie store](#using-with-an-asynchronous-cookie-store)\n  - [Using with another Agent library](#using-with-another-agent-library)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Install\n\n```bash\nnpm install http-cookie-agent tough-cookie\n```\n\nWhen you want to use Node.js global fetch (aka. `undici`), you should install `undici` additionally.\n\n```bash\nnpm install undici\n```\n\n## Usage\n\nSee also [examples](./examples) for more details.\n\n### Supported libraries\n\n| Library              | Supported?        |\n| -------------------- | ----------------- |\n| Node.js global fetch | ✅                |\n| `undici`             | ✅                |\n| `node:http`          | ✅                |\n| `node:https`         | ✅                |\n| `axios`              | ✅                |\n| `node-fetch`         | ✅                |\n| `got`                | ✅ <sup>\\*1</sup> |\n| `superagent`         | ✅ <sup>\\*1</sup> |\n| `request`            | ✅ <sup>\\*1</sup> |\n| `needle`             | ✅                |\n| `phin`               | ✅                |\n| `@hapi/wrech`        | ✅                |\n| `urllib`             | ✅                |\n| Bun global fetch     | ❌ <sup>\\*2</sup> |\n| Deno global fetch    | ❌ <sup>\\*2</sup> |\n\n\\*1: This library supports cookies by default. You may not need `http-cookie-agent`.\n\n\\*2: There have proprietary fetch implementation and is [not currently supported](https://github.com/3846masa/http-cookie-agent/issues/692).\n\n#### Node.js global fetch\n\n`http-cookie-agent` supports global fetch since Node.js v18.2.0.\n\n```js\nimport { CookieJar } from 'tough-cookie';\nimport { CookieAgent } from 'http-cookie-agent/undici';\n\nconst jar = new CookieJar();\nconst agent = new CookieAgent({ cookies: { jar } });\n\nawait fetch('https://example.com', { dispatcher: agent });\n```\n\n#### `undici`\n\n```js\nimport { fetch } from 'undici';\nimport { CookieJar } from 'tough-cookie';\nimport { CookieAgent } from 'http-cookie-agent/undici';\n\nconst jar = new CookieJar();\nconst agent = new CookieAgent({ cookies: { jar } });\n\nawait fetch('https://example.com', { dispatcher: agent });\n```\n\n#### `node:http` / `node:https`\n\n```js\nimport https from 'node:https';\n\nimport { CookieJar } from 'tough-cookie';\nimport { HttpsCookieAgent } from 'http-cookie-agent/http';\n\nconst jar = new CookieJar();\nconst agent = new HttpsCookieAgent({ cookies: { jar } });\n\nhttps.get('https://example.com', { agent }, (res) => {\n  // ...\n});\n```\n\n#### `axios`\n\n```js\nimport axios from 'axios';\nimport { CookieJar } from 'tough-cookie';\nimport { HttpCookieAgent, HttpsCookieAgent } from 'http-cookie-agent/http';\n\nconst jar = new CookieJar();\n\nconst client = axios.create({\n  httpAgent: new HttpCookieAgent({ cookies: { jar } }),\n  httpsAgent: new HttpsCookieAgent({ cookies: { jar } }),\n});\n\nawait client.get('https://example.com');\n```\n\n#### `node-fetch`\n\n```js\nimport fetch from 'node-fetch';\nimport { CookieJar } from 'tough-cookie';\nimport { HttpCookieAgent, HttpsCookieAgent } from 'http-cookie-agent/http';\n\nconst jar = new CookieJar();\n\nconst httpAgent = new HttpCookieAgent({ cookies: { jar } });\nconst httpsAgent = new HttpsCookieAgent({ cookies: { jar } });\n\nawait fetch('https://example.com', {\n  agent: ({ protocol }) => {\n    return protocol === 'https:' ? httpsAgent : httpAgent;\n  },\n});\n```\n\n#### `got`\n\n:warning: `got` supports cookies by default. You may not need `http-cookie-agent`.\n\nSee https://github.com/sindresorhus/got/tree/v11.8.2#cookies.\n\n```js\nimport got from 'got';\nimport { CookieJar } from 'tough-cookie';\nimport { HttpCookieAgent, HttpsCookieAgent } from 'http-cookie-agent/http';\n\nconst jar = new CookieJar();\n\nconst client = got.extend({\n  agent: {\n    http: new HttpCookieAgent({ cookies: { jar } }),\n    https: new HttpsCookieAgent({ cookies: { jar } }),\n  },\n});\n\nawait client('https://example.com');\n```\n\n#### `superagent`\n\n:warning: `superagent` supports cookies by default. You may not need `http-cookie-agent`.\n\nSee https://github.com/visionmedia/superagent/blob/v6.1.0/docs/index.md#saving-cookies.\n\n```js\nimport superagent from 'superagent';\nimport { CookieJar } from 'tough-cookie';\nimport { MixedCookieAgent } from 'http-cookie-agent/http';\n\nconst jar = new CookieJar();\nconst mixedAgent = new MixedCookieAgent({ cookies: { jar } });\n\nconst client = superagent.agent().use((req) => req.agent(mixedAgent));\n\nawait client.get('https://example.com');\n```\n\n#### `request`\n\n:warning: `request` supports cookies by default. You may not need `http-cookie-agent`.\n\nSee https://github.com/request/request/tree/v2.88.1#examples.\n\n```js\nimport request from 'request';\nimport { CookieJar } from 'tough-cookie';\nimport { MixedCookieAgent } from 'http-cookie-agent/http';\n\nconst jar = new CookieJar();\n\nconst client = request.defaults({\n  agent: new MixedCookieAgent({ cookies: { jar } }),\n});\n\nclient.get('https://example.com', (_err, _res) => {\n  // ...\n});\n```\n\n#### `needle`\n\n```js\nimport needle from 'needle';\nimport { CookieJar } from 'tough-cookie';\nimport { MixedCookieAgent } from 'http-cookie-agent/http';\n\nconst jar = new CookieJar();\n\nawait needle('get', 'https://example.com', {\n  agent: new MixedCookieAgent({ cookies: { jar } }),\n});\n```\n\n#### `phin`\n\n```js\nimport phin from 'phin';\nimport { CookieJar } from 'tough-cookie';\nimport { MixedCookieAgent } from 'http-cookie-agent/http';\n\nconst jar = new CookieJar();\n\nawait phin({\n  url: 'https://example.com',\n  core: {\n    agent: new MixedCookieAgent({ cookies: { jar } }),\n  },\n});\n```\n\n#### `@hapi/wreck`\n\n```js\nimport Wreck from '@hapi/wreck';\nimport { CookieJar } from 'tough-cookie';\nimport { HttpCookieAgent, HttpsCookieAgent } from 'http-cookie-agent/http';\n\nconst jar = new CookieJar();\n\nconst client = Wreck.defaults({\n  agents: {\n    http: new HttpCookieAgent({ cookies: { jar } }),\n    https: new HttpsCookieAgent({ cookies: { jar } }),\n    httpsAllowUnauthorized: new HttpsCookieAgent({ cookies: { jar } }),\n  },\n});\n\nawait client.get('https://example.com');\n```\n\n#### `urllib`\n\n```js\nimport { request, setGlobalDispatcher } from 'urllib';\nimport { CookieJar } from 'tough-cookie';\nimport { CookieClient } from 'http-cookie-agent/undici';\n\nconst jar = new CookieJar();\nconst agent = new CookieAgent({ cookies: { jar } });\nsetGlobalDispatcher(agent);\n\nawait request('https://example.com');\n```\n\n### Using with another Agent library\n\nIf you want to use another Agent library, wrap the agent in `createCookieAgent`.\n\n```js\nimport https from 'node:https';\n\nimport { HttpsAgent as KeepAliveAgent } from 'agentkeepalive';\nimport { CookieJar } from 'tough-cookie';\nimport { createCookieAgent } from 'http-cookie-agent/http';\n\nconst Agent = createCookieAgent(KeepAliveAgent);\n\nconst jar = new CookieJar();\nconst agent = new Agent({ cookies: { jar } });\n\nhttps.get('https://example.com', { agent }, (res) => {\n  // ...\n});\n```\n\n#### `undici`\n\nIf you want to use another undici Agent library, use `CookieClient` via factory function.\n\n```js\nimport { fetch, ProxyAgent } from 'undici';\nimport { CookieJar } from 'tough-cookie';\nimport { CookieClient } from 'http-cookie-agent/undici';\n\nconst jar = new CookieJar();\nconst agent = new ProxyAgent({\n  factory: (origin, opts) => {\n    return new CookieClient(origin, {\n      ...opts,\n      cookies: { jar },\n    });\n  },\n});\n\nawait fetch('https://example.com', { dispatcher: agent });\n```\n\nIf you want to use another undici Client library, wrap the client in `createCookieClient`.\n\n```js\nimport { fetch, Agent, MockClient } from 'undici';\nimport { CookieJar } from 'tough-cookie';\nimport { createCookieClient } from 'http-cookie-agent/undici';\n\nconst CookieClient = createCookieClient(MockClient);\n\nconst jar = new CookieJar();\nconst agent = new Agent({\n  factory: (origin, opts) => {\n    return new CookieClient(origin, {\n      ...opts,\n      cookies: { jar },\n    });\n  },\n});\n\nawait fetch('https://example.com', { dispatcher: agent });\n```\n\n## Contributing\n\nPRs accepted.\n\n## License\n\n[MIT (c) 3846masa](../LICENSE)\n","publish_time":1651937329308,"_cnpm_publish_time":1651937329308,"dist-tags":{"latest":"8.0.0"}}