{"_id":"@c4312/eventsource-umd","name":"@c4312/eventsource-umd","dist-tags":{"latest":"3.0.5"},"versions":{"3.0.5":{"name":"@c4312/eventsource-umd","version":"3.0.5","description":"WhatWG/W3C compliant EventSource client for Node.js and browsers","sideEffects":false,"type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"deno":"./dist/index.js","bun":"./dist/index.js","source":"./src/index.ts","umd":"./dist/index.umd.js","import":"./dist/index.js","require":"./dist/index.cjs","default":"./dist/index.js"},"./package.json":"./package.json"},"scripts":{"build":"pkg-utils build && pkg-utils --strict && npm run build:umd","build:umd":"rollup -c","build:watch":"pkg-utils watch","clean":"rimraf dist coverage","lint":"eslint . && tsc --noEmit","posttest":"npm run lint","prebuild":"npm run clean","prepare":"npm run build","test":"npm run test:node && npm run test:browser","test:browser":"tsx test/browser/client.browser.test.ts","test:bun":"bun run test/bun/client.bun.test.ts","test:deno":"deno run --allow-net --allow-read --allow-env --unstable-sloppy-imports test/deno/client.deno.test.ts","test:node":"tsx test/node/client.node.test.ts"},"repository":{"type":"git","url":"git://git@github.com/EventSource/eventsource.git"},"keywords":["sse","eventsource","server-sent-events"],"author":{"name":"Espen Hovlandsdal","email":"espen@hovlandsdal.com"},"contributors":[{"name":"Aslak Hellesøy","email":"aslak.hellesoy@gmail.com"},{"name":"Einar Otto Stangvik","email":"einaro.s@gmail.com"}],"license":"MIT","engines":{"node":">=18.0.0"},"browserslist":["node >= 18","chrome >= 71","safari >= 14.1","firefox >= 105","edge >= 79"],"dependencies":{"eventsource-parser":"^3.0.0"},"devDependencies":{"@rollup/plugin-node-resolve":"^16.0.1","@rollup/plugin-typescript":"^12.1.2","@sanity/pkg-utils":"^7.1.0","@sanity/semantic-release-preset":"^5.0.0","@tsconfig/strictest":"^2.0.5","@types/sinon":"^17.0.3","@typescript-eslint/eslint-plugin":"^6.11.0","@typescript-eslint/parser":"^6.11.0","esbuild":"^0.25.1","eslint":"^8.57.0","eslint-config-prettier":"^9.1.0","eslint-config-sanity":"^7.1.3","eventsource-encoder":"^1.0.0","playwright":"^1.48.2","prettier":"^3.5.3","rimraf":"^5.0.5","rollup":"^4.35.0","rollup-plugin-visualizer":"^5.12.0","semantic-release":"^24.2.0","sinon":"^17.0.1","tsx":"^4.19.2","typescript":"^5.8.2","undici":"^6.20.1"},"overrides":{"cross-spawn":"7.0.6"},"bugs":{"url":"https://github.com/EventSource/eventsource/issues"},"homepage":"https://github.com/EventSource/eventsource#readme","prettier":{"semi":false,"printWidth":100,"bracketSpacing":false,"singleQuote":true},"eslintConfig":{"parserOptions":{"ecmaVersion":9,"sourceType":"module","ecmaFeatures":{"modules":true}},"extends":["sanity","sanity/typescript","prettier"],"ignorePatterns":["lib/**/"],"globals":{"globalThis":false},"rules":{"no-undef":"off","no-empty":"off"}},"_id":"@c4312/eventsource-umd@3.0.5","gitHead":"3efd3f1227001c57c60e999dc45779a15fd71428","_nodeVersion":"20.12.1","_npmVersion":"10.5.0","dist":{"integrity":"sha512-0QhLg51eFB+SS/a4Pv5tHaRSnjJBpdFsjT3WN/Vfh6qzeFXqvaE+evVIIToYvr2lRBLg1NIB635ip8ML+/84Sg==","shasum":"36db01ae83ac5a9a781074b0ade1d2afcbe706a4","tarball":"https://registry.npmjs.org/@c4312/eventsource-umd/-/eventsource-umd-3.0.5.tgz","fileCount":14,"unpackedSize":183337,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQD1JhxHk9HkbY/6hbZmcWSHe9eRU/jrZcYThj5mUkpbgwIhAM1njPONAw/aDocYYRZHzg6c1NpPoOqlgTcV65N+FO0I"}]},"_npmUser":{"name":"connor.peet","email":"connor@peet.io"},"directories":{},"maintainers":[{"name":"connor.peet","email":"connor@peet.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/eventsource-umd_3.0.5_1742009842054_0.3643395881435627"},"_hasShrinkwrap":false}},"time":{"created":"2025-03-15T03:37:21.945Z","3.0.5":"2025-03-15T03:37:22.228Z","modified":"2025-03-15T03:37:22.519Z"},"maintainers":[{"name":"connor.peet","email":"connor@peet.io"}],"description":"WhatWG/W3C compliant EventSource client for Node.js and browsers","homepage":"https://github.com/EventSource/eventsource#readme","keywords":["sse","eventsource","server-sent-events"],"repository":{"type":"git","url":"git://git@github.com/EventSource/eventsource.git"},"contributors":[{"name":"Aslak Hellesøy","email":"aslak.hellesoy@gmail.com"},{"name":"Einar Otto Stangvik","email":"einaro.s@gmail.com"}],"author":{"name":"Espen Hovlandsdal","email":"espen@hovlandsdal.com"},"bugs":{"url":"https://github.com/EventSource/eventsource/issues"},"license":"MIT","readme":"# eventsource\n\n[![npm version](https://img.shields.io/npm/v/eventsource.svg?style=flat-square)](https://www.npmjs.com/package/eventsource)[![npm bundle size](https://img.shields.io/bundlephobia/minzip/eventsource?style=flat-square)](https://bundlephobia.com/result?p=eventsource)[![npm weekly downloads](https://img.shields.io/npm/dw/eventsource.svg?style=flat-square)](https://www.npmjs.com/package/eventsource)\n\nWhatWG/W3C-compatible [server-sent events/eventsource](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events) client. The module attempts to implement an absolute minimal amount of features/changes beyond the specification.\n\nIf you're looking for a modern alternative with a less constrained API, check out the [`eventsource-client` package](https://www.npmjs.com/package/eventsource-client).\n\n## Installation\n\n```bash\nnpm install --save eventsource\n```\n\n## Supported engines\n\n- Node.js >= 18\n- Chrome >= 63\n- Safari >= 11.3\n- Firefox >= 65\n- Edge >= 79\n- Deno >= 1.30\n- Bun >= 1.1.23\n\nBasically, any environment that supports:\n\n- [fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch)\n- [ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream)\n- [TextDecoderStream](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoderStream)\n- [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL)\n- [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event), [MessageEvent](https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent), [EventTarget](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget)\n\nIf you need to support older runtimes, try the `2.x` branch/version range (note: 2.x branch is primarily targetted at Node.js, not browsers).\n\n## Usage\n\n```ts\nimport {EventSource} from 'eventsource'\n\nconst es = new EventSource('https://my-server.com/sse')\n\n/*\n * This will listen for events with the field `event: notice`.\n */\nes.addEventListener('notice', (event) => {\n  console.log(event.data)\n})\n\n/*\n * This will listen for events with the field `event: update`.\n */\nes.addEventListener('update', (event) => {\n  console.log(event.data)\n})\n\n/*\n * The event \"message\" is a special case, as it will capture events _without_ an\n * event field, as well as events that have the specific type `event: message`.\n * It will not trigger on any other event type.\n */\nes.addEventListener('message', (event) => {\n  console.log(event.data)\n})\n\n/**\n * To explicitly close the connection, call the `close` method.\n * This will prevent any reconnection from happening.\n */\nsetTimeout(() => {\n  es.close()\n}, 10_000)\n```\n\n### TypeScript\n\nMake sure you have configured your TSConfig so it matches the environment you are targetting. If you are targetting browsers, this would be `dom`:\n\n```jsonc\n{\n  \"compilerOptions\": {\n    \"lib\": [\"dom\"],\n  },\n}\n```\n\nIf you're using Node.js, ensure you have `@types/node` installed (and it is version 18 or higher). Cloudflare workers have `@cloudflare/workers-types` etc.\n\nThe following errors are caused by targetting an environment that does not have the necessary types available:\n\n```\nerror TS2304: Cannot find name 'Event'.\nerror TS2304: Cannot find name 'EventTarget'.\nerror TS2304: Cannot find name 'MessageEvent'.\n```\n\n## Migrating from v1 / v2\n\nSee [MIGRATION.md](MIGRATION.md#v2-to-v3) for a detailed migration guide.\n\n## Extensions to the WhatWG/W3C API\n\n### Message and code properties on errors\n\nThe `error` event has a `message` and `code` property that can be used to get more information about the error. In the specification, the Event\n\n```ts\nes.addEventListener('error', (err) => {\n  if (err.code === 401 || err.code === 403) {\n    console.log('not authorized')\n  }\n})\n```\n\n### Specify `fetch` implementation\n\nThe `EventSource` constructor accepts an optional `fetch` property in the second argument that can be used to specify the `fetch` implementation to use.\n\nThis can be useful in environments where the global `fetch` function is not available - but it can also be used to alter the request/response behaviour.\n\n#### Setting HTTP request headers\n\n```ts\nconst es = new EventSource('https://my-server.com/sse', {\n  fetch: (input, init) =>\n    fetch(input, {\n      ...init,\n      headers: {\n        ...init.headers,\n        Authorization: 'Bearer myToken',\n      },\n    }),\n})\n```\n\n#### HTTP/HTTPS proxy\n\nUse a package like [`node-fetch-native`](https://github.com/unjs/node-fetch-native) to add proxy support, either through environment variables or explicit configuration.\n\n```ts\n// npm install node-fetch-native --save\nimport {fetch} from 'node-fetch-native/proxy'\n\nconst es = new EventSource('https://my-server.com/sse', {\n  fetch: (input, init) => fetch(input, init),\n})\n```\n\n#### Allow unauthorized HTTPS requests\n\nUse a package like [`undici`](https://github.com/nodejs/undici) for more control of fetch options through the use of an [`Agent`](https://undici.nodejs.org/#/docs/api/Agent.md).\n\n```ts\n// npm install undici --save\nimport {fetch, Agent} from 'undici'\n\nawait fetch('https://my-server.com/sse', {\n  dispatcher: new Agent({\n    connect: {\n      rejectUnauthorized: false,\n    },\n  }),\n})\n```\n\n## License\n\nMIT-licensed. See [LICENSE](LICENSE).\n","readmeFilename":"README.md","_rev":"1-14ac1d7b6c34c5d5b8f63e66fd4920f7"}