@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.
- package/CHANGELOG.md +20 -0
- package/dist/index-react-bindings.browser.cjs +48 -18
- package/dist/index-react-bindings.browser.cjs.map +1 -1
- package/dist/index-react-bindings.browser.js +48 -18
- package/dist/index-react-bindings.browser.js.map +1 -1
- package/dist/index-react-bindings.node.cjs +48 -18
- package/dist/index-react-bindings.node.cjs.map +1 -1
- package/dist/index-react-bindings.node.js +48 -18
- package/dist/index-react-bindings.node.js.map +1 -1
- package/dist/index.browser.cjs +48 -18
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +48 -18
- package/dist/index.browser.js.map +1 -1
- package/dist/index.node.cjs +48 -18
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +48 -18
- package/dist/index.node.js.map +1 -1
- package/dist/src/common/real-time/StableWSConnection.d.ts +3 -3
- package/dist/src/common/real-time/event-models.d.ts +14 -0
- package/dist/src/feed/event-handlers/feed/handle-feed-updated.d.ts +2 -2
- package/dist/src/feeds-client/feeds-client.d.ts +3 -2
- package/dist/src/gen/feeds/FeedsApi.d.ts +2 -1
- package/dist/src/gen/models/index.d.ts +32 -5
- package/dist/src/types.d.ts +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/common/real-time/event-models.ts +16 -0
- package/src/feed/event-handlers/feed/handle-feed-updated.ts +2 -2
- package/src/feeds-client/feeds-client.ts +51 -20
- package/src/gen/feeds/FeedsApi.ts +26 -0
- package/src/gen/model-decoders/decoders.ts +7 -0
- package/src/gen/models/index.ts +52 -5
- package/src/types.ts +5 -2
|
@@ -1612,6 +1612,12 @@ decoders.UpsertConfigResponse = (input) => {
|
|
|
1612
1612
|
};
|
|
1613
1613
|
return decode(typeMappings, input);
|
|
1614
1614
|
};
|
|
1615
|
+
decoders.UpsertPushPreferencesResponse = (input) => {
|
|
1616
|
+
const typeMappings = {
|
|
1617
|
+
user_preferences: { type: 'PushPreferences', isSingle: false },
|
|
1618
|
+
};
|
|
1619
|
+
return decode(typeMappings, input);
|
|
1620
|
+
};
|
|
1615
1621
|
decoders.User = (input) => {
|
|
1616
1622
|
const typeMappings = {
|
|
1617
1623
|
ban_expires: { type: 'DatetimeType', isSingle: true },
|
|
@@ -1979,6 +1985,7 @@ class FeedsApi {
|
|
|
1979
1985
|
text: request?.text,
|
|
1980
1986
|
visibility: request?.visibility,
|
|
1981
1987
|
attachments: request?.attachments,
|
|
1988
|
+
feeds: request?.feeds,
|
|
1982
1989
|
filter_tags: request?.filter_tags,
|
|
1983
1990
|
interest_tags: request?.interest_tags,
|
|
1984
1991
|
custom: request?.custom,
|
|
@@ -2608,6 +2615,14 @@ class FeedsApi {
|
|
|
2608
2615
|
decoders.PollVotesResponse?.(response.body);
|
|
2609
2616
|
return { ...response.body, metadata: response.metadata };
|
|
2610
2617
|
}
|
|
2618
|
+
async updatePushNotificationPreferences(request) {
|
|
2619
|
+
const body = {
|
|
2620
|
+
preferences: request?.preferences,
|
|
2621
|
+
};
|
|
2622
|
+
const response = await this.apiClient.sendRequest('POST', '/api/v2/push_preferences', undefined, undefined, body, 'application/json');
|
|
2623
|
+
decoders.UpsertPushPreferencesResponse?.(response.body);
|
|
2624
|
+
return { ...response.body, metadata: response.metadata };
|
|
2625
|
+
}
|
|
2611
2626
|
async deleteFile(request) {
|
|
2612
2627
|
const queryParams = {
|
|
2613
2628
|
url: request?.url,
|
|
@@ -5715,6 +5730,11 @@ function handleUserUpdated(event) {
|
|
|
5715
5730
|
});
|
|
5716
5731
|
}
|
|
5717
5732
|
|
|
5733
|
+
var UnhandledErrorType;
|
|
5734
|
+
(function (UnhandledErrorType) {
|
|
5735
|
+
UnhandledErrorType["ReconnectionReconciliation"] = "reconnection-reconciliation";
|
|
5736
|
+
})(UnhandledErrorType || (UnhandledErrorType = {}));
|
|
5737
|
+
|
|
5718
5738
|
class FeedsClient extends FeedsApi {
|
|
5719
5739
|
constructor(apiKey, options) {
|
|
5720
5740
|
const tokenManager = new TokenManager();
|
|
@@ -5724,6 +5744,22 @@ class FeedsClient extends FeedsApi {
|
|
|
5724
5744
|
this.eventDispatcher = new EventDispatcher();
|
|
5725
5745
|
this.activeFeeds = {};
|
|
5726
5746
|
this.healthyConnectionChangedEventCount = 0;
|
|
5747
|
+
this.recoverOnReconnect = async () => {
|
|
5748
|
+
this.healthyConnectionChangedEventCount++;
|
|
5749
|
+
// we skip the first event as we could potentially be querying twice
|
|
5750
|
+
if (this.healthyConnectionChangedEventCount > 1) {
|
|
5751
|
+
const entries = Object.entries(this.activeFeeds);
|
|
5752
|
+
const results = await Promise.allSettled(entries.map(([, feed]) => feed.synchronize()));
|
|
5753
|
+
const failures = results.flatMap((result, index) => result.status === 'rejected'
|
|
5754
|
+
? [{ feed: entries[index][0], reason: result.reason }]
|
|
5755
|
+
: []);
|
|
5756
|
+
this.eventDispatcher.dispatch({
|
|
5757
|
+
type: 'errors.unhandled',
|
|
5758
|
+
error_type: UnhandledErrorType.ReconnectionReconciliation,
|
|
5759
|
+
failures,
|
|
5760
|
+
});
|
|
5761
|
+
}
|
|
5762
|
+
};
|
|
5727
5763
|
this.pollFromState = (id) => this.polls_by_id.get(id);
|
|
5728
5764
|
this.connectUser = async (user, tokenProvider) => {
|
|
5729
5765
|
if (this.state.getLatestValue().connected_user !== undefined ||
|
|
@@ -5819,18 +5855,18 @@ class FeedsClient extends FeedsApi {
|
|
|
5819
5855
|
};
|
|
5820
5856
|
this.getOrCreateActiveFeed = (group, id, data, watch) => {
|
|
5821
5857
|
const fid = `${group}:${id}`;
|
|
5822
|
-
if (this.activeFeeds[fid]) {
|
|
5823
|
-
|
|
5824
|
-
if (watch && !feed.currentState.watch) {
|
|
5825
|
-
handleWatchStarted.bind(feed)();
|
|
5826
|
-
}
|
|
5827
|
-
return feed;
|
|
5858
|
+
if (!this.activeFeeds[fid]) {
|
|
5859
|
+
this.activeFeeds[fid] = new Feed(this, group, id, data, watch);
|
|
5828
5860
|
}
|
|
5829
|
-
|
|
5830
|
-
|
|
5831
|
-
|
|
5832
|
-
|
|
5861
|
+
const feed = this.activeFeeds[fid];
|
|
5862
|
+
if (!feed.currentState.watch) {
|
|
5863
|
+
// feed isn't watched and may be stale, update it
|
|
5864
|
+
if (data)
|
|
5865
|
+
handleFeedUpdated.call(feed, { feed: data });
|
|
5866
|
+
if (watch)
|
|
5867
|
+
handleWatchStarted.call(feed);
|
|
5833
5868
|
}
|
|
5869
|
+
return feed;
|
|
5834
5870
|
};
|
|
5835
5871
|
this.state = new StateStore({
|
|
5836
5872
|
connected_user: undefined,
|
|
@@ -5848,13 +5884,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5848
5884
|
const { online } = event;
|
|
5849
5885
|
this.state.partialNext({ is_ws_connection_healthy: online });
|
|
5850
5886
|
if (online) {
|
|
5851
|
-
this.
|
|
5852
|
-
// we skip the first event as we could potentially be querying twice
|
|
5853
|
-
if (this.healthyConnectionChangedEventCount > 1) {
|
|
5854
|
-
for (const activeFeed of Object.values(this.activeFeeds)) {
|
|
5855
|
-
activeFeed.synchronize();
|
|
5856
|
-
}
|
|
5857
|
-
}
|
|
5887
|
+
this.recoverOnReconnect();
|
|
5858
5888
|
}
|
|
5859
5889
|
else {
|
|
5860
5890
|
for (const activeFeed of Object.values(this.activeFeeds)) {
|
|
@@ -5968,7 +5998,7 @@ class FeedsClient extends FeedsApi {
|
|
|
5968
5998
|
}
|
|
5969
5999
|
async queryFeeds(request) {
|
|
5970
6000
|
const response = await this._queryFeeds(request);
|
|
5971
|
-
const feeds = response.feeds.map((
|
|
6001
|
+
const feeds = response.feeds.map((feedResponse) => this.getOrCreateActiveFeed(feedResponse.group_id, feedResponse.id, feedResponse, request?.watch));
|
|
5972
6002
|
return {
|
|
5973
6003
|
feeds,
|
|
5974
6004
|
next: response.next,
|