{"library":"popsicle-cookie-jar","title":"Popsicle Cookie Jar Middleware","description":"popsicle-cookie-jar is a middleware designed for the Popsicle HTTP client library, enabling cookie management in Node.js environments. It integrates with Popsicle's request lifecycle to automatically handle `Set-Cookie` headers from responses and attach `Cookie` headers to outgoing requests, mimicking browser-like cookie behavior. The current stable version is 1.0.1, which primarily features an update to the underlying `tough-cookie` library for security patches. Given its single-purpose nature and recent release history, its release cadence appears to be driven by bug fixes or critical dependency updates rather than frequent feature additions. Key differentiators include its tight integration with the Popsicle ecosystem and its reliance on `tough-cookie` for robust cookie specification adherence, providing a reliable, in-memory cookie store by default, with options for custom `CookieJar` instances.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install popsicle-cookie-jar"],"cli":null},"imports":["import { cookies } from 'popsicle-cookie-jar';","import { CookieJar } from 'popsicle-cookie-jar';","import { compose } from 'servie';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { cookies, CookieJar } from \"popsicle-cookie-jar\";\nimport { compose } from 'servie';\n// Assume 'transport' is another middleware, e.g., from 'popsicle-transport-http'\n// For demonstration, we'll create a dummy transport and Popsicle client.\n\ninterface Context {\n  request: { url: string; headers?: Record<string, string>; };\n  response?: { status: number; headers: Record<string, string>; body?: any; };\n}\n\nasync function dummyTransport(ctx: Context, next: () => Promise<void>) {\n  console.log(`Sending request to: ${ctx.request.url}`);\n  ctx.response = {\n    status: 200,\n    headers: { 'Set-Cookie': 'session=abc; Path=/; HttpOnly' },\n    body: 'Hello World'\n  };\n  await next();\n}\n\n// Create an in-memory cookie jar\nconst myCookieJar = new CookieJar();\n\n// Compose the middleware with a custom cookie jar\nconst middlewareWithJar = compose([cookies(myCookieJar), dummyTransport]);\n\n// Or let it create a default in-memory jar\nconst middlewareDefault = compose([cookies(), dummyTransport]);\n\nasync function makeRequest(middleware: (ctx: Context, next: () => Promise<void>) => Promise<void>) {\n  const ctx: Context = { request: { url: 'http://example.com/login' } };\n  await middleware(ctx, async () => {}); // No further middleware after transport\n  console.log('Response headers:', ctx.response?.headers);\n  console.log('Cookies in jar (after request):', myCookieJar.getCookiesSync('http://example.com/login'));\n}\n\nconsole.log('--- Using custom CookieJar ---');\nawait makeRequest(middlewareWithJar);\n\nconsole.log('\\n--- Using default (new) CookieJar instance for separate calls ---');\n// Each call to cookies() without an argument creates a new jar\nawait makeRequest(compose([cookies(), dummyTransport]));\n","lang":"typescript","description":"This quickstart demonstrates how to apply `popsicle-cookie-jar` middleware to a Popsicle client to enable automatic cookie handling, showing both default in-memory and custom `CookieJar` usage.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}