@stream-io/feeds-client 0.2.4 → 0.2.6

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 +20 -0
  2. package/dist/index-react-bindings.browser.cjs +48 -18
  3. package/dist/index-react-bindings.browser.cjs.map +1 -1
  4. package/dist/index-react-bindings.browser.js +48 -18
  5. package/dist/index-react-bindings.browser.js.map +1 -1
  6. package/dist/index-react-bindings.node.cjs +48 -18
  7. package/dist/index-react-bindings.node.cjs.map +1 -1
  8. package/dist/index-react-bindings.node.js +48 -18
  9. package/dist/index-react-bindings.node.js.map +1 -1
  10. package/dist/index.browser.cjs +48 -18
  11. package/dist/index.browser.cjs.map +1 -1
  12. package/dist/index.browser.js +48 -18
  13. package/dist/index.browser.js.map +1 -1
  14. package/dist/index.node.cjs +48 -18
  15. package/dist/index.node.cjs.map +1 -1
  16. package/dist/index.node.js +48 -18
  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/feed/event-handlers/feed/handle-feed-updated.d.ts +2 -2
  21. package/dist/src/feeds-client/feeds-client.d.ts +3 -2
  22. package/dist/src/gen/feeds/FeedsApi.d.ts +2 -1
  23. package/dist/src/gen/models/index.d.ts +32 -5
  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/feed/event-handlers/feed/handle-feed-updated.ts +2 -2
  29. package/src/feeds-client/feeds-client.ts +51 -20
  30. package/src/gen/feeds/FeedsApi.ts +26 -0
  31. package/src/gen/model-decoders/decoders.ts +7 -0
  32. package/src/gen/models/index.ts +52 -5
  33. package/src/types.ts +5 -2
@@ -1341,6 +1341,12 @@ decoders.UpsertConfigResponse = (input) => {
1341
1341
  };
1342
1342
  return decode(typeMappings, input);
1343
1343
  };
1344
+ decoders.UpsertPushPreferencesResponse = (input) => {
1345
+ const typeMappings = {
1346
+ user_preferences: { type: 'PushPreferences', isSingle: false },
1347
+ };
1348
+ return decode(typeMappings, input);
1349
+ };
1344
1350
  decoders.User = (input) => {
1345
1351
  const typeMappings = {
1346
1352
  ban_expires: { type: 'DatetimeType', isSingle: true },
@@ -1708,6 +1714,7 @@ class FeedsApi {
1708
1714
  text: request?.text,
1709
1715
  visibility: request?.visibility,
1710
1716
  attachments: request?.attachments,
1717
+ feeds: request?.feeds,
1711
1718
  filter_tags: request?.filter_tags,
1712
1719
  interest_tags: request?.interest_tags,
1713
1720
  custom: request?.custom,
@@ -2337,6 +2344,14 @@ class FeedsApi {
2337
2344
  decoders.PollVotesResponse?.(response.body);
2338
2345
  return { ...response.body, metadata: response.metadata };
2339
2346
  }
2347
+ async updatePushNotificationPreferences(request) {
2348
+ const body = {
2349
+ preferences: request?.preferences,
2350
+ };
2351
+ const response = await this.apiClient.sendRequest('POST', '/api/v2/push_preferences', undefined, undefined, body, 'application/json');
2352
+ decoders.UpsertPushPreferencesResponse?.(response.body);
2353
+ return { ...response.body, metadata: response.metadata };
2354
+ }
2340
2355
  async deleteFile(request) {
2341
2356
  const queryParams = {
2342
2357
  url: request?.url,
@@ -5732,6 +5747,11 @@ function handleUserUpdated(event) {
5732
5747
  });
5733
5748
  }
5734
5749
 
5750
+ var UnhandledErrorType;
5751
+ (function (UnhandledErrorType) {
5752
+ UnhandledErrorType["ReconnectionReconciliation"] = "reconnection-reconciliation";
5753
+ })(UnhandledErrorType || (UnhandledErrorType = {}));
5754
+
5735
5755
  class FeedsClient extends FeedsApi {
5736
5756
  constructor(apiKey, options) {
5737
5757
  const tokenManager = new TokenManager();
@@ -5741,6 +5761,22 @@ class FeedsClient extends FeedsApi {
5741
5761
  this.eventDispatcher = new EventDispatcher();
5742
5762
  this.activeFeeds = {};
5743
5763
  this.healthyConnectionChangedEventCount = 0;
5764
+ this.recoverOnReconnect = async () => {
5765
+ this.healthyConnectionChangedEventCount++;
5766
+ // we skip the first event as we could potentially be querying twice
5767
+ if (this.healthyConnectionChangedEventCount > 1) {
5768
+ const entries = Object.entries(this.activeFeeds);
5769
+ const results = await Promise.allSettled(entries.map(([, feed]) => feed.synchronize()));
5770
+ const failures = results.flatMap((result, index) => result.status === 'rejected'
5771
+ ? [{ feed: entries[index][0], reason: result.reason }]
5772
+ : []);
5773
+ this.eventDispatcher.dispatch({
5774
+ type: 'errors.unhandled',
5775
+ error_type: UnhandledErrorType.ReconnectionReconciliation,
5776
+ failures,
5777
+ });
5778
+ }
5779
+ };
5744
5780
  this.pollFromState = (id) => this.polls_by_id.get(id);
5745
5781
  this.connectUser = async (user, tokenProvider) => {
5746
5782
  if (this.state.getLatestValue().connected_user !== undefined ||
@@ -5836,18 +5872,18 @@ class FeedsClient extends FeedsApi {
5836
5872
  };
5837
5873
  this.getOrCreateActiveFeed = (group, id, data, watch) => {
5838
5874
  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;
5875
+ if (!this.activeFeeds[fid]) {
5876
+ this.activeFeeds[fid] = new Feed(this, group, id, data, watch);
5845
5877
  }
5846
- else {
5847
- const feed = new Feed(this, group, id, data, watch);
5848
- this.activeFeeds[fid] = feed;
5849
- return feed;
5878
+ const feed = this.activeFeeds[fid];
5879
+ if (!feed.currentState.watch) {
5880
+ // feed isn't watched and may be stale, update it
5881
+ if (data)
5882
+ handleFeedUpdated.call(feed, { feed: data });
5883
+ if (watch)
5884
+ handleWatchStarted.call(feed);
5850
5885
  }
5886
+ return feed;
5851
5887
  };
5852
5888
  this.state = new StateStore({
5853
5889
  connected_user: undefined,
@@ -5865,13 +5901,7 @@ class FeedsClient extends FeedsApi {
5865
5901
  const { online } = event;
5866
5902
  this.state.partialNext({ is_ws_connection_healthy: online });
5867
5903
  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
- }
5904
+ this.recoverOnReconnect();
5875
5905
  }
5876
5906
  else {
5877
5907
  for (const activeFeed of Object.values(this.activeFeeds)) {
@@ -5985,7 +6015,7 @@ class FeedsClient extends FeedsApi {
5985
6015
  }
5986
6016
  async queryFeeds(request) {
5987
6017
  const response = await this._queryFeeds(request);
5988
- const feeds = response.feeds.map((f) => this.getOrCreateActiveFeed(f.group_id, f.id, f, request?.watch));
6018
+ const feeds = response.feeds.map((feedResponse) => this.getOrCreateActiveFeed(feedResponse.group_id, feedResponse.id, feedResponse, request?.watch));
5989
6019
  return {
5990
6020
  feeds,
5991
6021
  next: response.next,