Skip to content

Commit

Permalink
Make eventsource an optional dependency for streamers
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Nov 3, 2023
1 parent f1a53d3 commit 94e3dac
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ A breaking change will get clearly marked in this log.

## Unreleased

### Breaking Changes
* Downstream consumers must now polyfill an `EventSource` provider if they do not have native support or must opt-out of Horizon streaming support. This can be done via the [`eventsource`](https://www.npmjs.com/package/eventsource) package ([TODO]()).


## [v11.0.0-beta.6](https://github.com/stellar/js-stellar-sdk/compare/v11.0.0-beta.5...v11.0.0-beta.6)

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"@stellar/tsconfig": "^1.0.2",
"@types/chai": "^4.3.6",
"@types/detect-node": "^2.0.0",
"@types/eventsource": "^1.1.12",
"@types/eventsource": "^1.1.14",
"@types/lodash": "^4.14.199",
"@types/mocha": "^10.0.2",
"@types/node": "^20.8.10",
Expand All @@ -112,6 +112,7 @@
"eslint-plugin-prefer-import": "^0.0.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint-webpack-plugin": "^4.0.1",
"eventsource": "^2.0.2",
"ghooks": "^2.0.4",
"husky": "^8.0.3",
"jsdoc": "^4.0.2",
Expand Down Expand Up @@ -144,7 +145,6 @@
"dependencies": {
"axios": "^1.6.0",
"bignumber.js": "^9.1.2",
"eventsource": "^2.0.2",
"randombytes": "^2.1.0",
"stellar-base": "10.0.0-beta.4",
"toml": "^3.0.0",
Expand Down
7 changes: 6 additions & 1 deletion src/horizon/call_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ export interface EventSourceOptions<T> {
const anyGlobal = global as any;
type Constructable<T> = new (e: string) => T;
// require("eventsource") for Node and React Native environment
let EventSource: Constructable<EventSource> = anyGlobal.EventSource ??
const EventSource: Constructable<EventSource> = anyGlobal.EventSource ??
anyGlobal.window?.EventSource ??
require("eventsource");
if (!EventSource) {
console.warn(
'⚠️ No EventSource provider found: either polyfill it (e.g. `npm i eventsource`) or you will not have streaming support.'
);
}

/**
* Creates a new {@link CallBuilder} pointed to server defined by serverUrl.
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.4.tgz#d9748f5742171b26218516cf1828b8eafaf8a9fa"
integrity sha512-2JwWnHK9H+wUZNorf2Zr6ves96WHoWDJIftkcxPKsS7Djta6Zu519LarhRNljPXkpsZR2ZMwNCPeW7omW07BJw==

"@types/eventsource@^1.1.12":
"@types/eventsource@^1.1.14":
version "1.1.14"
resolved "https://registry.yarnpkg.com/@types/eventsource/-/eventsource-1.1.14.tgz#b5b115b19f3a392a6c29331486bc88dcb4e8a4e2"
integrity sha512-WiPIkZ5fuhTkeaVaPKbaP6vHuTX9FHnFNTrkSbm+Uf6g4TH3YNbdfw5/1oLzKIWsQRbrvSiByO2nPSxjr5/cgQ==
Expand Down

0 comments on commit 94e3dac

Please sign in to comment.