{"_id":"@atek-cloud/node-fetch-cookies","_rev":"2-a7575c81562530d3605321485571de63","name":"@atek-cloud/node-fetch-cookies","dist-tags":{"latest":"2.0.4"},"versions":{"2.0.4":{"name":"@atek-cloud/node-fetch-cookies","version":"2.0.4","description":"node-fetch wrapper that adds support for cookie-jars","main":"src/index.mjs","engines":{"node":">=14.13.0"},"scripts":{"test":"npx eslint --ext mjs . && npx prettier --check package.json package-lock.json .travis.yml .prettierrc.json .eslintrc.json README.md && node --experimental-modules test/index.mjs"},"repository":{"type":"git","url":"git+https://github.com/jkhsjdhjs/node-fetch-cookies.git"},"keywords":["cookie","cookie-jar","node-fetch","fetch"],"author":{"name":"jkhsjdhjs"},"license":"MIT","bugs":{"url":"https://github.com/jkhsjdhjs/node-fetch-cookies/issues"},"homepage":"https://github.com/jkhsjdhjs/node-fetch-cookies#readme","dependencies":{"node-fetch":"^2.6.1"},"devDependencies":{"cookie-parser":"^1.4.5","eslint":"^7.12.1","eslint-config-prettier":"^6.15.0","eslint-plugin-prettier":"^3.1.4","express":"^4.17.1","prettier":"^2.1.2"},"gitHead":"b1c1bf88330380bf4717cd535f66865dfcb64b42","_id":"@atek-cloud/node-fetch-cookies@2.0.4","_nodeVersion":"16.1.0","_npmVersion":"7.11.2","dist":{"integrity":"sha512-/oc3g5GbFMH5aT04U/C9L/SLfTBqM3Bxm+Nh5+iMfX4Sa/GeafXwg0S/BM0ZEVcOh1SfYGi17LLuMeYeU1DfRw==","shasum":"aefcb23f58ef6e56453d31ee03d53a21e0164549","tarball":"https://registry.npmjs.org/@atek-cloud/node-fetch-cookies/-/node-fetch-cookies-2.0.4.tgz","fileCount":7,"unpackedSize":26267,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhzGbeCRA9TVsSAnZWagAAdl8P/3xOg5iGKfpD7Abg5GMA\niKCM/87oU5V/F1gzr9PK4uaFHe72rVXUs9J94MYAjEiq6HggkI+PFyFkQ2sp\nN9aFydl80jSRxFqsdr+PpGEk1x+whNuxaI9sC0ytSmWGQ+C9iSJKJWGBnENB\nnVYHrO7cRXTMvRVGy+Ih5QQWnVcVUqT5W6PgTBdH0Jl2GsvTpzO2u6cwYF9p\n83DvRf4sWaNK+BQJeOUIY9w2xonVX2myJ+mtTQ30kQhvUvePkBl9cirjY67+\nUST1338H9V/tfm9whXmW3qbjab9BQRSsSgHEZFjpvdFIAGMmaGegWWp2tlGn\nlSMNya7AVUfth/dLBbd49wzNPOO5smbE4vkpj/lHrzW+t74DUIouO2hI80WX\nyzAQOLT/IVp8ZpRuhgY2cbUUomWVl2UOkjORy/GJbw7c/sQ8Q6NCKjF/CRfS\nBhXYAw+B3MBA9k3ZUe29blH9gL/5RCvYaVMWL2n+xaJvq1goETI2BXPOYArY\nyLH/vAk+c2Xg3G8uo0TwRX+5gC/nILxwoIID3X3/qRd/P2KUHjeeqXPjHqJv\nlWuyddpCiyx7MJs4JO2AUeCtMdoOCs0lxeGwXMCNzoTAgWEvvzZHjeg3lq4+\neuKHBJB5KU7lwVMo8JGJsaCbSW8ocUInJQBy9MKGkK6NbWVnnigFqcCUJSBG\n8Tmb\r\n=/dWB\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFWRCS4J7kUKl4Fuzs51K36PPU92hlgV4I3CtxjqfVP/AiBatJJjlMmJd1o4KqQugWHcwVQaLzYDFbvHp1H/C4LMig=="}]},"_npmUser":{"name":"pfrazee","email":"pfrazee@gmail.com"},"directories":{},"maintainers":[{"name":"pfrazee","email":"pfrazee@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/node-fetch-cookies_2.0.4_1632341719837_0.15658974451875274"},"_hasShrinkwrap":false}},"time":{"created":"2021-09-22T20:15:19.785Z","2.0.4":"2021-09-22T20:15:19.983Z","modified":"2022-04-04T16:03:03.388Z"},"maintainers":[{"name":"pfrazee","email":"pfrazee@gmail.com"}],"description":"node-fetch wrapper that adds support for cookie-jars","homepage":"https://github.com/jkhsjdhjs/node-fetch-cookies#readme","keywords":["cookie","cookie-jar","node-fetch","fetch"],"repository":{"type":"git","url":"git+https://github.com/jkhsjdhjs/node-fetch-cookies.git"},"author":{"name":"jkhsjdhjs"},"bugs":{"url":"https://github.com/jkhsjdhjs/node-fetch-cookies/issues"},"license":"MIT","readme":"# node-fetch-cookies [![Build Status](https://travis-ci.com/jkhsjdhjs/node-fetch-cookies.svg?branch=master)](https://travis-ci.com/jkhsjdhjs/node-fetch-cookies)\n\nA [node-fetch](https://github.com/node-fetch/node-fetch) wrapper with support for cookies.\nIt supports reading/writing from/to a JSON cookie jar and keeps cookies in memory until you call `CookieJar.save()` to reduce disk I/O.\n\n### For upgrading from 1.2.x or below to 1.3.x or above, please read the [breaking API changes](#130-breaking-api-changes).\n\n## Usage Examples\n\n### with file...\n\n```javascript\nimport {fetch, CookieJar} from \"node-fetch-cookies\";\n\n(async () => {\n    // creates a CookieJar instance\n    const cookieJar = new CookieJar(\"jar.json\");\n\n    // load cookies from the cookie jar\n    await cookieJar.load();\n\n    // usual fetch usage, except with one or multiple cookie jars as first parameter\n    const response = await fetch(cookieJar, \"https://example.com\");\n\n    // save the received cookies to disk\n    await cookieJar.save();\n})();\n```\n\n### ...or without\n\n```javascript\nimport {fetch, CookieJar} from \"node-fetch-cookies\";\n\n(async () => {\n    const cookieJar = new CookieJar();\n\n    // log in to some api\n    let response = await fetch(cookieJar, \"https://example.com/api/login\", {\n        method: \"POST\",\n        body: \"credentials\"\n    });\n\n    // do some requests you require login for\n    response = await fetch(\n        cookieJar,\n        \"https://example.com/api/admin/drop-all-databases\"\n    );\n\n    // and optionally log out again\n    response = await fetch(cookieJar, \"https://example.com/api/logout\");\n})();\n```\n\n## Exports\n\nThis module exports the following classes/functions:\n\n-   [`fetch`](#async-fetchcookiejars-url-options) _(default)_\n-   [`CookieJar`](#class-cookiejar)\n-   [`Cookie`](#class-cookie)\n-   [`CookieParseError`](#class-cookieparseerror)\n-   [`nodeFetch`](https://github.com/node-fetch/node-fetch#fetchurl-options)\n-   [`Headers`](https://github.com/node-fetch/node-fetch#class-headers)\n-   [`Request`](https://github.com/node-fetch/node-fetch#class-request)\n-   [`Response`](https://github.com/node-fetch/node-fetch#class-response)\n-   [`FetchError`](https://github.com/node-fetch/node-fetch#class-fetcherror)\n-   `isRedirect`: A function that accepts a number, more precisely an http status code as input, and returns, whether the status code is a redirect status code as a boolean.  \n    It is implemented in `node-fetch` and used by `node-fetch-cookies`. It is also exported here, because `node-fetch` exports it.\n\n## Documentation\n\n### async fetch(cookieJars, url[, options])\n\n-   `cookieJars` A [CookieJar](#class-cookiejar) instance, an array of CookieJar instances or null, if you don't want to send or store cookies.\n-   `url` and `options` as in https://github.com/node-fetch/node-fetch#fetchurl-options\n\nReturns a Promise resolving to a [Response](https://github.com/node-fetch/node-fetch#class-response) instance on success.\n\n### Class: CookieJar\n\nA class that stores cookies.\n\n#### Properties\n\n-   `flags` The read/write flags as specified below.\n-   `file` The path of the cookie jar on the disk.\n-   `cookies` A [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) mapping hostnames to maps, which map cookie names to the respective [Cookie](#class-cookie) instance.\n-   `cookieIgnoreCallback` The callback function passed to `new CookieJar()`, that is called whenever a cookie couldn't be parsed.\n\n#### new CookieJar([file, flags = `rw`, cookies, cookieIgnoreCallback])\n\n-   `file` An optional string containing a relative or absolute path to the file on the disk to use.\n-   `flags` An optional string specifying whether cookies should be read and/or written from/to the jar when passing it as parameter to [fetch](#fetchcookiejar-url-options). Default: `rw`\n    -   `r`: only read from this jar\n    -   `w`: only write to this jar\n    -   `rw` or `wr`: read/write from/to this jar\n-   `cookies` An optional initializer for the cookie jar - either an array of [Cookie](#class-cookie) instances or a single Cookie instance.\n-   `cookieIgnoreCallback(cookie, reason)` An optional callback function which will be called when a cookie is ignored instead of added to the cookie jar.\n    -   `cookie` The cookie string\n    -   `reason` A string containing the reason why the cookie has been ignored\n\n#### addCookie(cookie[, fromURL])\n\nAdds a cookie to the jar.\n\n-   `cookie` A [Cookie](#class-cookie) instance to add to the cookie jar.\n    Alternatively this can also be a string, for example a serialized cookie received from a website.\n    In this case `fromURL` must be specified.\n-   `fromURL` The url a cookie has been received from.\n\nReturns `true` if the cookie has been added successfully. Returns `false` otherwise.  \nIf the parser throws a [CookieParseError](#class-cookieparseerror), it will be caught and `cookieIgnoreCallback` will be called with the respective cookie string and error message.\n\n#### domains()\n\nReturns an iterator over all domains currently stored cookies for.\n\n#### \\*cookiesDomain(domain)\n\nReturns an iterator over all cookies currently stored for `domain`.\n\n#### \\*cookiesValid(withSession)\n\nReturns an iterator over all valid (non-expired) cookies.\n\n-   `withSession`: A boolean. Iterator will include session cookies if set to `true`.\n\n#### \\*cookiesAll()\n\nReturns an iterator over all cookies currently stored.\n\n#### \\*cookiesValidForRequest(requestURL)\n\nReturns an iterator over all cookies valid for a request to `url`.\n\n#### deleteExpired(sessionEnded)\n\nRemoves all expired cookies from the jar.\n\n-   `sessionEnded`: A boolean. Also removes session cookies if set to `true`.\n\n#### async load([file = this.file])\n\nReads cookies from `file` on the disk and adds the contained cookies.\n\n-   `file`: Path to the file where the cookies should be saved. Default: `this.file`, the file that has been passed to the constructor.\n\n#### async save([file = this.file])\n\nSaves the cookie jar to `file` on the disk. Only non-expired non-session cookies are saved.\n\n-   `file`: Path to the file where the cookies should be saved. Default: `this.file`, the file that has been passed to the constructor.\n\n### Class: Cookie\n\nAn abstract representation of a cookie.\n\n#### Properties\n\n-   `name` The identifier of the cookie.\n-   `value` The value of the cookie.\n-   `expiry` A [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) object of the cookies expiry date or `null`, if the cookie expires with the session.\n-   `domain` The domain the cookie is valid for.\n-   `path` The path the cookie is valid for.\n-   `secure` A boolean value representing the cookie's secure attribute. If set the cookie will only be used for `https` requests.\n-   `subdomains` A boolean value specifying whether the cookie should be used for requests to subdomains of `domain` or not.\n\n#### new Cookie(str, requestURL)\n\nCreates a cookie instance from the string representation of a cookie as send by a webserver.\n\n-   `str` The string representation of a cookie.\n-   `url` The url the cookie has been received from.\n\nWill throw a `CookieParseError` if `str` couldn't be parsed.\n\n#### static fromObject(obj)\n\nCreates a cookie instance from an already existing object with the same properties.\n\n#### serialize()\n\nSerializes the cookie, transforming it to `name=value` so it can be used in requests.\n\n#### hasExpired(sessionEnded)\n\nReturns whether the cookie has expired or not.\n\n-   `sessionEnded`: A boolean that specifies whether the current session has ended, meaning if set to `true`, the function will return `true` for session cookies.\n\n#### isValidForRequest(requestURL)\n\nReturns whether the cookie is valid for a request to `url`.\n\n### Class: CookieParseError\n\nThe Error that is thrown when the cookie parser located in the constructor of the [Cookie](#class-cookie) class is unable to parse the input.\n\n## 1.3.0 Breaking API Changes\n\n-   `new CookieJar(flags, file, cookies)` has been changed to `new CookieJar(file, flags = \"rw\", cookies)`.  \n    `new CookieJar(\"rw\")` can now be written as `new CookieJar()`, `new CookieJar(\"rw\", \"jar.json\")` can now be written as `new CookieJar(\"jar.json\")`.  \n    This change has been introduced to simplify the usage of this library, since `rw` is used for `flags` in most cases anyways.\n-   `CookieJar.addFromFile(file)` has been renamed to the async function `async CookieJar.load([file = this.file])`, which uses the fsPromises API for non-blocking cookie loading.  \n    The default value for `file` is the file passed to the constructor.\n-   `CookieJar.save(file)` was moved to `async CookieJar.save([file = this.file])` now also uses the fsPromises API.\n-   `new CookieJar()` now doesn't load cookies from the specified file anymore. To do so, call `await CookieJar.load()` after creating the CookieJar.  \n    **NOTE: `CookieJar.load()` will throw an error if the cookie jar doesn't exist or doesn't contain valid JSON!**\n\n## License\n\nThis project is licensed under the MIT license, see [LICENSE](LICENSE).\n","readmeFilename":"README.md"}