{"_id":"@andyfischer/fetch-sse-stream","_rev":"2-869694e59e02d7b303aa64df429e47fd","name":"@andyfischer/fetch-sse-stream","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.0":{"name":"@andyfischer/fetch-sse-stream","version":"0.1.0","license":"MIT","_id":"@andyfischer/fetch-sse-stream@0.1.0","maintainers":[{"name":"andy_fischer","email":"andy.fischer@gmail.com"}],"homepage":"https://github.com/andyfischer/node-libraries#readme","bugs":{"url":"https://github.com/andyfischer/node-libraries/issues"},"dist":{"shasum":"f563f943681caea835fbc627f0a42506423bec26","tarball":"https://registry.npmjs.org/@andyfischer/fetch-sse-stream/-/fetch-sse-stream-0.1.0.tgz","fileCount":12,"integrity":"sha512-0DOzv4rnUBzT/heaRiDZkvFf+CEy/7i6Ch2bXNPE92yddkQYm+dBp5tZ4Kf8rFglsrmtP8qcNn6Jl9yZ1WSX1A==","signatures":[{"sig":"MEYCIQCNQyAOJYiTIeOxmZIZz69aSirmcQwoC4Ud68TqV0TjfAIhAP4nxAN8YBJRBZADVVUoVrxZTDvGcJ0IQMbwWxqX893E","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":32896},"main":"dist/index.js","types":"./dist/index.d.ts","gitHead":"b5ee6f21ce68eb9937e43c222145093440e476b3","scripts":{"tsc":"tsc","test":"vitest run","build":"tsc -p .","prepare":"yarn build","test:watch":"vitest"},"_npmUser":{"name":"andy_fischer","email":"andy.fischer@gmail.com"},"repository":{"url":"git+https://github.com/andyfischer/node-libraries.git","type":"git"},"_npmVersion":"10.9.2","description":"HTTP client using fetch with Server-Sent Events parsing, using @andyfischer/streams","directories":{},"sideEffects":false,"_nodeVersion":"22.16.0","dependencies":{"@andyfischer/streams":"^0.3.1"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"1.6.0","typescript":"^5.2.0","@types/node":"^20.0.0"},"_npmOperationalInternal":{"tmp":"tmp/fetch-sse-stream_0.1.0_1754361633720_0.6892714929986028","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@andyfischer/fetch-sse-stream","version":"0.2.0","license":"MIT","description":"HTTP client using fetch with Server-Sent Events parsing, using @andyfischer/streams","main":"dist/index.js","sideEffects":false,"scripts":{"build":"tsc -p .","tsc":"tsc","test":"vitest run","test:watch":"vitest","prepare":"yarn build"},"dependencies":{"@andyfischer/streams":"^0.3.2"},"devDependencies":{"@types/node":"^20.0.0","typescript":"^5.2.0","vitest":"1.6.0"},"repository":{"type":"git","url":"git+https://github.com/andyfischer/node-libraries.git"},"_id":"@andyfischer/fetch-sse-stream@0.2.0","gitHead":"8504da605d2b675324886fdf5cdcfaccaa03e108","types":"./dist/index.d.ts","bugs":{"url":"https://github.com/andyfischer/node-libraries/issues"},"homepage":"https://github.com/andyfischer/node-libraries#readme","_nodeVersion":"22.16.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-YGXVoz3AeTCr/4OCNcPuCv4ZKOce5tGcJDiX9pph4gR2PMgiBOTRAZbK+daY3w9cUhNbijOOcMQbkrLgLLQ2/g==","shasum":"413dfa7b17b98f3e7174f81bd7226a88c3a4f25b","tarball":"https://registry.npmjs.org/@andyfischer/fetch-sse-stream/-/fetch-sse-stream-0.2.0.tgz","fileCount":21,"unpackedSize":71036,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCtmOE0fTD9LQZZJvEEiOmTdyfwOtdZ0AYnzSeQC3LvwAIgTgp3Eog3AXkgADSmpFXMkpS/6v9knCVcKFWrOEb3jJo="}]},"_npmUser":{"name":"andy_fischer","email":"andy.fischer@gmail.com"},"directories":{},"maintainers":[{"name":"andy_fischer","email":"andy.fischer@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/fetch-sse-stream_0.2.0_1755230143118_0.5408678773303845"},"_hasShrinkwrap":false}},"time":{"created":"2025-08-05T02:40:33.616Z","modified":"2025-08-15T03:55:43.519Z","0.1.0":"2025-08-05T02:40:33.909Z","0.2.0":"2025-08-15T03:55:43.293Z"},"bugs":{"url":"https://github.com/andyfischer/node-libraries/issues"},"license":"MIT","homepage":"https://github.com/andyfischer/node-libraries#readme","repository":{"type":"git","url":"git+https://github.com/andyfischer/node-libraries.git"},"description":"HTTP client using fetch with Server-Sent Events parsing, using @andyfischer/streams","maintainers":[{"name":"andy_fischer","email":"andy.fischer@gmail.com"}],"readme":"# @andyfischer/fetch-sse-stream\n\nHTTP client using `fetch` with Server-Sent Events (SSE) parsing.\n\nOne fetch call will return a `Stream` object from @andyfischer/streams.\n\n## Installation\n\n```bash\nnpm install @andyfischer/fetch-sse-stream\n```\n\n## Usage\n\n### Basic Usage\n\n```typescript\nimport { fetchStream } from '@andyfischer/fetch-sse-stream';\nimport { c_item, c_fail, c_done } from '@andyfischer/streams';\n\nconst stream = fetchStream<ResponseType>('https://example.com/events');\n\n// Process events as they arrive\nstream.pipe(evt => {\n    switch (evt.t) {\n    case c_item:\n        const item: ResponseType = evt.item;\n        // ...\n        break;\n    case c_fail:\n        // ...\n        break;\n    case c_done:\n        // ...\n        break;\n    }\n});\n```\n\n### Advanced Usage\n\nSet custom headers in the request.\n\n```typescript\nimport { fetchStream } from '@andyfischer/fetch-sse-stream';\n\nconst stream = fetchStream('https://example.com/events', {\n    headers: {\n        'Authorization': 'Bearer your-token'\n    },\n    onOpen: () => console.log('Connected'),\n    onError: (error) => console.error('Connection error:', error)\n});\n\n// Process the stream\nstream.pipe(evt => {\n    // Handle events...\n});\n```\n\n### Using a Custom Fetch Function\n\nYou can provide your own fetch implementation (useful for testing, proxies, or custom authentication):\n\n```typescript\nimport { fetchStream } from '@andyfischer/fetch-sse-stream';\nimport nodeFetch from 'node-fetch';\n\nconst stream = fetchStream('https://example.com/events', {\n    fetch: nodeFetch as any, // Use node-fetch instead of built-in fetch\n    headers: {\n        'User-Agent': 'MyApp/1.0'\n    }\n});\n```\n\n## API\n\n### `fetchStream(url, options?)`\n\nCreates and connects to an SSE stream immediately.\n\n- `url`: The endpoint URL\n- `options`: Optional configuration (extends `RequestInit`)\n\nReturns a `Stream<SSEEventData>` from `@andyfischer/streams`.\n\n### `FetchSSEStream`\n\nClass for more control over the connection lifecycle.\n\n#### Constructor Options\n\n- `onOpen`: Callback when connection opens\n- `onError`: Callback for connection errors\n- `fetch`: Custom fetch function to use instead of global fetch\n- Plus all standard `RequestInit` options (headers, method, etc.)\n\n#### Methods\n\n- `connect()`: Start the connection and return the Stream\n- `close()`: Close the connection and cleanup resources\n","readmeFilename":"README.md"}