ladjs / superagent

Ajax for Node.js and browsers (JS HTTP client). Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.
https://ladjs.github.io/superagent/
MIT License
16.56k stars 1.33k forks source link

[Feature request] Expose CookieAccessInfo from cookiejar in Node #1683

Open noinkling opened 2 years ago

noinkling commented 2 years ago

In Node, we have access to an Agent's cookie jar on the .jar property, but in order to retrieve cookies from it (useful in certain cases including testing) we also need access to CookieAccessInfo, which currently isn't exposed by Superagent.

Currently, the way to work around this would be to import cookiejar in our own code, however:

  1. Having an implicit dependency is a bad idea, not least because there's no guarantee that we'll get the version of cookiejar that Superagent is using. A different version is not guaranteed to be compatible, and at the very least it would break CookieAccessInfo.All because it's used like a symbol.

  2. If we make the dependency explicit in package.json we have to take care to match the version that Superagent uses, which is annoying and brittle - even then there may not be a strong guarantee that Superagent uses the version we import.

For these reasons, could CookieAccessInfo (or alternatively, the whole cookiejar module) be exposed somewhere? Maybe as a static property of Agent? Then we could do superagent.agent.CookieAccessInfo. Or maybe as a prototype property? Another option is to expose it on the main import, but I'm not sure if that makes sense or not. Or even just a separate file we could import like 'superagent/cookiejar'. If we can work out which one is preferred I'd be happy to throw up a PR myself. I'd also like it to be exposed from Supertest, if that makes any difference.

Previous request from a long time ago that was closed without explanation: #192