{"_id":"@code.tieumomo/vue-sse","name":"@code.tieumomo/vue-sse","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@code.tieumomo/vue-sse","version":"0.1.0","description":"Vue 3 plugin and composables for Server-Sent Events (EventSource)","type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/code-tieumomo/vue-sse.git"},"homepage":"https://github.com/code-tieumomo/vue-sse#readme","bugs":{"url":"https://github.com/code-tieumomo/vue-sse/issues"},"engines":{"node":">=18"},"sideEffects":false,"scripts":{"build":"tsup src/index.ts --format esm,cjs --dts","dev":"tsup src/index.ts --format esm,cjs --dts --watch","check":"vue-tsc --noEmit","test:smoke":"tsx examples/smoke.ts","changeset":"changeset","version-packages":"changeset version","prepublish:registry":"tsx scripts/check-publish-readiness.ts","release":"npm run prepublish:registry && changeset publish","prepublishOnly":"npm run check && npm run build && npm run test:smoke"},"keywords":["vue","vue3","sse","eventsource","server-sent-events","plugin","composable"],"author":{"name":"code.tieumomo"},"license":"MIT","peerDependencies":{"vue":"^3.4.0"},"devDependencies":{"@types/node":"^24.5.2","@changesets/changelog-github":"^0.5.1","@changesets/cli":"^2.29.7","tsup":"^8.5.0","tsx":"^4.20.6","typescript":"^5.9.2","vue":"^3.5.13","vue-tsc":"^3.0.7"},"gitHead":"83d0581d5258b307d4435b959a755b49a5f45ff4","_id":"@code.tieumomo/vue-sse@0.1.0","_nodeVersion":"24.14.0","_npmVersion":"11.11.0","dist":{"integrity":"sha512-amyRWv2FL7E1fcDP2VQ/Zz8jF2KOZsFlrpGoKAvm3MaV5zNP3Y/37NkTxfJAZXLMpotpSFBiPIKgMEW6SgFHXw==","shasum":"06d46e0e03577a05ed99d744cfc718698013dfd9","tarball":"https://registry.npmjs.org/@code.tieumomo/vue-sse/-/vue-sse-0.1.0.tgz","fileCount":6,"unpackedSize":20751,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCXZOPLdmipW06kC+IBEsLxobLJBmCvdbxuF5/11eyBMQIgfkiWge3xqIHP6daTn46gN4WzNGSdb0mAPk0DOKHGmZM="}]},"_npmUser":{"name":"code.tieumomo","email":"code.tieumomo@gmail.com"},"directories":{},"maintainers":[{"name":"code.tieumomo","email":"code.tieumomo@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/vue-sse_0.1.0_1773513757704_0.5978641018053792"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-14T18:42:37.645Z","0.1.0":"2026-03-14T18:42:37.872Z","modified":"2026-03-14T18:42:38.037Z"},"maintainers":[{"name":"code.tieumomo","email":"code.tieumomo@gmail.com"}],"description":"Vue 3 plugin and composables for Server-Sent Events (EventSource)","homepage":"https://github.com/code-tieumomo/vue-sse#readme","keywords":["vue","vue3","sse","eventsource","server-sent-events","plugin","composable"],"repository":{"type":"git","url":"git+https://github.com/code-tieumomo/vue-sse.git"},"author":{"name":"code.tieumomo"},"bugs":{"url":"https://github.com/code-tieumomo/vue-sse/issues"},"license":"MIT","readme":"# vue-sse\n\n[![npm version](https://img.shields.io/npm/v/%40code-tieumomo%2Fvue-sse)](https://www.npmjs.com/package/@code.tieumomo/vue-sse)\n[![license](https://img.shields.io/npm/l/%40code-tieumomo%2Fvue-sse)](./LICENSE)\n[![CI](https://github.com/code-tieumomo/vue-sse/actions/workflows/ci.yml/badge.svg)](https://github.com/code-tieumomo/vue-sse/actions/workflows/ci.yml)\n[![publish](https://github.com/code-tieumomo/vue-sse/actions/workflows/publish.yml/badge.svg)](https://github.com/code-tieumomo/vue-sse/actions/workflows/publish.yml)\n\nA small Vue 3 plugin and composable set for consuming Server-Sent Events with the native `EventSource` API.\n\n## Features\n\n- Vue 3 plugin install helper via `createSsePlugin()`\n- Low-level composable via `useEventSource()`\n- Injection helper via `useSse()`\n- Typed payload deserialization\n- Named event listeners beyond the default `message` event\n- Auto reconnect when the URL ref changes\n- Works with native `EventSource` or a custom/polyfilled implementation\n\n## Install\n\n```bash\nnpm install @code.tieumomo/vue-sse\n```\n\n## Quick start\n\n```ts\nimport { createApp } from 'vue';\nimport App from './App.vue';\nimport { createSsePlugin } from '@code.tieumomo/vue-sse';\n\nconst app = createApp(App);\n\napp.use(\n  createSsePlugin({\n    url: 'https://example.com/events',\n    withCredentials: true,\n    deserialize: (payload) => JSON.parse(payload),\n  }),\n);\n\napp.mount('#app');\n```\n\nInside components:\n\n```ts\n<script setup lang=\"ts\">\nimport { useSse } from '@code.tieumomo/vue-sse';\n\nconst { data, error, isOpen, close } = useSse<{ message: string }>();\n</script>\n```\n\nOr use the composable directly:\n\n```ts\nimport { ref } from 'vue';\nimport { useEventSource } from '@code.tieumomo/vue-sse';\n\nconst endpoint = ref('https://example.com/events');\nconst { data, lastEvent, connect, close } = useEventSource(endpoint, {\n  events: ['notification', 'heartbeat'],\n  deserialize: (payload, event) => ({\n    type: event.type,\n    body: JSON.parse(payload),\n  }),\n});\n```\n\n## API\n\n### `createSsePlugin(options)`\n\nCreates a Vue plugin that opens an SSE connection once installed and exposes it through both DI and `this.$sse`.\n\n### `useEventSource(url, options)`\n\nReturns:\n\n- `source`: current `EventSource` instance\n- `data`: latest typed payload\n- `lastEvent`: latest full message object\n- `error`: latest error event\n- `readyState`: current EventSource ready state\n- `isConnecting`, `isOpen`, `isClosed`: convenience state refs\n- `connect()`: open or reopen the stream\n- `close()`: close the stream and detach listeners\n\nOptions:\n\n- `events?: string[]`\n- `immediate?: boolean`\n- `autoClose?: boolean`\n- `withCredentials?: boolean`\n- `deserialize?: (payload, event) => T`\n- `eventSource?: EventSource constructor override`\n- `onMessage?`, `onOpen?`, `onError?`\n\n### `useSse()`\n\nReturns the plugin-provided SSE API. Throws if the plugin was not installed.\n\n## Notes\n\n- Native `EventSource` is browser-only. For SSR, create the stream on the client or provide a compatible polyfill.\n- The browser controls retry behavior. If you need custom retry logic, configure it on the server or supply a custom EventSource implementation.\n\n## Development\n\n```bash\nnpm install\nnpm run build\nnpm run check\nnpm run test:smoke\n```\n\n## Releases\n\nThis package uses [Changesets](https://github.com/changesets/changesets) for automated versioning and changelog generation.\n\nTo add a release note for a change:\n\n```bash\nnpm run changeset\n```\n\nThat creates a file in `.changeset/` describing the version bump.\n\nRelease flow:\n\n- merge changesets into `release`\n- GitHub Actions opens or updates a version PR\n- merging that PR updates `package.json` and `CHANGELOG.md`\n- the same workflow publishes the package to npm\n\nRepository secrets required:\n\n- `NPM_TOKEN`\n\nFor local manual publishing, run `npm publish` from your shell. Provenance attestation is only available in supported CI providers, so it should be enabled there rather than forced in `package.json`.\n","readmeFilename":"README.md","_rev":"1-a50b72d7b1b0745a4e98f50da3946e4c"}