@stream-io/feeds-client 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/index-react-bindings.browser.cjs +36 -19
  3. package/dist/index-react-bindings.browser.cjs.map +1 -1
  4. package/dist/index-react-bindings.browser.js +36 -19
  5. package/dist/index-react-bindings.browser.js.map +1 -1
  6. package/dist/index-react-bindings.node.cjs +36 -19
  7. package/dist/index-react-bindings.node.cjs.map +1 -1
  8. package/dist/index-react-bindings.node.js +36 -19
  9. package/dist/index-react-bindings.node.js.map +1 -1
  10. package/dist/index.browser.cjs +35 -20
  11. package/dist/index.browser.cjs.map +1 -1
  12. package/dist/index.browser.js +35 -20
  13. package/dist/index.browser.js.map +1 -1
  14. package/dist/index.node.cjs +35 -20
  15. package/dist/index.node.cjs.map +1 -1
  16. package/dist/index.node.js +35 -20
  17. package/dist/index.node.js.map +1 -1
  18. package/dist/src/common/real-time/StableWSConnection.d.ts +3 -3
  19. package/dist/src/common/real-time/event-models.d.ts +14 -0
  20. package/dist/src/common/search/FeedSearchSource.d.ts +2 -2
  21. package/dist/src/feed/event-handlers/feed/handle-feed-updated.d.ts +2 -2
  22. package/dist/src/feeds-client/feeds-client.d.ts +3 -2
  23. package/dist/src/gen/models/index.d.ts +18 -8
  24. package/dist/src/types.d.ts +2 -2
  25. package/dist/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +1 -1
  27. package/src/common/real-time/event-models.ts +16 -0
  28. package/src/common/search/BaseSearchSource.ts +1 -1
  29. package/src/common/search/FeedSearchSource.ts +3 -2
  30. package/src/feed/event-handlers/feed/handle-feed-updated.ts +2 -2
  31. package/src/feeds-client/feeds-client.ts +51 -20
  32. package/src/gen/models/index.ts +26 -8
  33. package/src/types.ts +5 -2
@@ -5732,6 +5732,11 @@ function handleUserUpdated(event) {
5732
5732
  });
5733
5733
  }
5734
5734
 
5735
+ var UnhandledErrorType;
5736
+ (function (UnhandledErrorType) {
5737
+ UnhandledErrorType["ReconnectionReconciliation"] = "reconnection-reconciliation";
5738
+ })(UnhandledErrorType || (UnhandledErrorType = {}));
5739
+
5735
5740
  class FeedsClient extends FeedsApi {
5736
5741
  constructor(apiKey, options) {
5737
5742
  const tokenManager = new TokenManager();
@@ -5741,6 +5746,22 @@ class FeedsClient extends FeedsApi {
5741
5746
  this.eventDispatcher = new EventDispatcher();
5742
5747
  this.activeFeeds = {};
5743
5748
  this.healthyConnectionChangedEventCount = 0;
5749
+ this.recoverOnReconnect = async () => {
5750
+ this.healthyConnectionChangedEventCount++;
5751
+ // we skip the first event as we could potentially be querying twice
5752
+ if (this.healthyConnectionChangedEventCount > 1) {
5753
+ const entries = Object.entries(this.activeFeeds);
5754
+ const results = await Promise.allSettled(entries.map(([, feed]) => feed.synchronize()));
5755
+ const failures = results.flatMap((result, index) => result.status === 'rejected'
5756
+ ? [{ feed: entries[index][0], reason: result.reason }]
5757
+ : []);
5758
+ this.eventDispatcher.dispatch({
5759
+ type: 'errors.unhandled',
5760
+ error_type: UnhandledErrorType.ReconnectionReconciliation,
5761
+ failures,
5762
+ });
5763
+ }
5764
+ };
5744
5765
  this.pollFromState = (id) => this.polls_by_id.get(id);
5745
5766
  this.connectUser = async (user, tokenProvider) => {
5746
5767
  if (this.state.getLatestValue().connected_user !== undefined ||
@@ -5836,18 +5857,18 @@ class FeedsClient extends FeedsApi {
5836
5857
  };
5837
5858
  this.getOrCreateActiveFeed = (group, id, data, watch) => {
5838
5859
  const fid = `${group}:${id}`;
5839
- if (this.activeFeeds[fid]) {
5840
- const feed = this.activeFeeds[fid];
5841
- if (watch && !feed.currentState.watch) {
5842
- handleWatchStarted.bind(feed)();
5843
- }
5844
- return feed;
5860
+ if (!this.activeFeeds[fid]) {
5861
+ this.activeFeeds[fid] = new Feed(this, group, id, data, watch);
5845
5862
  }
5846
- else {
5847
- const feed = new Feed(this, group, id, data, watch);
5848
- this.activeFeeds[fid] = feed;
5849
- return feed;
5863
+ const feed = this.activeFeeds[fid];
5864
+ if (!feed.currentState.watch) {
5865
+ // feed isn't watched and may be stale, update it
5866
+ if (data)
5867
+ handleFeedUpdated.call(feed, { feed: data });
5868
+ if (watch)
5869
+ handleWatchStarted.call(feed);
5850
5870
  }
5871
+ return feed;
5851
5872
  };
5852
5873
  this.state = new StateStore({
5853
5874
  connected_user: undefined,
@@ -5865,13 +5886,7 @@ class FeedsClient extends FeedsApi {
5865
5886
  const { online } = event;
5866
5887
  this.state.partialNext({ is_ws_connection_healthy: online });
5867
5888
  if (online) {
5868
- this.healthyConnectionChangedEventCount++;
5869
- // we skip the first event as we could potentially be querying twice
5870
- if (this.healthyConnectionChangedEventCount > 1) {
5871
- for (const activeFeed of Object.values(this.activeFeeds)) {
5872
- activeFeed.synchronize();
5873
- }
5874
- }
5889
+ this.recoverOnReconnect();
5875
5890
  }
5876
5891
  else {
5877
5892
  for (const activeFeed of Object.values(this.activeFeeds)) {
@@ -5985,7 +6000,7 @@ class FeedsClient extends FeedsApi {
5985
6000
  }
5986
6001
  async queryFeeds(request) {
5987
6002
  const response = await this._queryFeeds(request);
5988
- const feeds = response.feeds.map((f) => this.getOrCreateActiveFeed(f.group_id, f.id, f, request?.watch));
6003
+ const feeds = response.feeds.map((feedResponse) => this.getOrCreateActiveFeed(feedResponse.group_id, feedResponse.id, feedResponse, request?.watch));
5989
6004
  return {
5990
6005
  feeds,
5991
6006
  next: response.next,
@@ -6344,7 +6359,7 @@ class BaseSearchSourceBase {
6344
6359
  updatePaginationStateFromQuery(result) {
6345
6360
  const { items, next } = result;
6346
6361
  const stateUpdate = {};
6347
- if (next || next === null) {
6362
+ if (Object.prototype.hasOwnProperty.call(result, 'next')) {
6348
6363
  stateUpdate.next = next;
6349
6364
  stateUpdate.hasNext = !!next;
6350
6365
  }
@@ -6459,9 +6474,9 @@ class ActivitySearchSource extends BaseSearchSource {
6459
6474
  class FeedSearchSource extends BaseSearchSource {
6460
6475
  constructor(client, options) {
6461
6476
  super(options);
6462
- this.type = 'feed';
6463
6477
  this.client = client;
6464
6478
  this.feedGroupId = options?.groupId;
6479
+ this.type = `${this.feedGroupId}-feed`;
6465
6480
  }
6466
6481
  async query(searchQuery) {
6467
6482
  const { connected_user: connectedUser } = this.client.state.getLatestValue();