@stream-io/feeds-client 0.3.23 → 0.3.25
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 +14 -0
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/react-bindings.js +1 -1
- package/dist/es/index.mjs +3 -2
- package/dist/es/react-bindings.mjs +1 -1
- package/dist/{feeds-client-BJQdmCB4.mjs → feeds-client-BULS-w1O.mjs} +114 -48
- package/dist/feeds-client-BULS-w1O.mjs.map +1 -0
- package/dist/{feeds-client-BUZVIyHd.js → feeds-client-DUD5wy6N.js} +114 -48
- package/dist/feeds-client-DUD5wy6N.js.map +1 -0
- package/dist/types/common/Poll.d.ts +6 -6
- package/dist/types/common/Poll.d.ts.map +1 -1
- package/dist/types/feed/event-handlers/activity/handle-activity-added.d.ts +3 -1
- package/dist/types/feed/event-handlers/activity/handle-activity-added.d.ts.map +1 -1
- package/dist/types/feed/feed.d.ts +4 -1
- package/dist/types/feed/feed.d.ts.map +1 -1
- package/dist/types/feeds-client/feeds-client.d.ts +10 -3
- package/dist/types/feeds-client/feeds-client.d.ts.map +1 -1
- package/dist/types/feeds-client/get-or-create-active-feed.d.ts +1 -2
- package/dist/types/feeds-client/get-or-create-active-feed.d.ts.map +1 -1
- package/dist/types/utils/check-own-fields-equality.d.ts +5 -0
- package/dist/types/utils/check-own-fields-equality.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/own-feed-fields.d.ts +3 -0
- package/dist/types/utils/own-feed-fields.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/common/Poll.ts +13 -30
- package/src/feed/event-handlers/activity/handle-activity-added.ts +3 -1
- package/src/feed/feed.ts +49 -16
- package/src/feeds-client/feeds-client.ts +69 -32
- package/src/feeds-client/get-or-create-active-feed.ts +2 -6
- package/src/test-utils/response-generators.ts +2 -1
- package/src/utils/check-own-fields-equality.ts +40 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/own-feed-fields.ts +6 -0
- package/dist/feeds-client-BJQdmCB4.mjs.map +0 -1
- package/dist/feeds-client-BUZVIyHd.js.map +0 -1
|
@@ -3936,7 +3936,7 @@ const getRateLimitFromResponseHeader = (response_headers) => {
|
|
|
3936
3936
|
};
|
|
3937
3937
|
return result;
|
|
3938
3938
|
};
|
|
3939
|
-
const version = "0.3.
|
|
3939
|
+
const version = "0.3.25";
|
|
3940
3940
|
const axios = axiosImport.default ?? axiosImport;
|
|
3941
3941
|
class ApiClient {
|
|
3942
3942
|
constructor(apiKey, tokenManager, connectionIdManager, options) {
|
|
@@ -4439,7 +4439,6 @@ class StreamPoll {
|
|
|
4439
4439
|
} = event.poll;
|
|
4440
4440
|
this.state.partialNext({
|
|
4441
4441
|
answers_count,
|
|
4442
|
-
// @ts-expect-error Incompatibility between PollResponseData and Poll due to teams_role, remove when OpenAPI spec is fixed
|
|
4443
4442
|
latest_votes_by_option,
|
|
4444
4443
|
vote_count,
|
|
4445
4444
|
vote_counts_by_option,
|
|
@@ -4462,7 +4461,6 @@ class StreamPoll {
|
|
|
4462
4461
|
if (isOwnVote) {
|
|
4463
4462
|
if (isVoteAnswer(event.poll_vote)) {
|
|
4464
4463
|
latestAnswers = [
|
|
4465
|
-
// @ts-expect-error Incompatibility between PollResponseData and Poll due to teams_role, remove when OpenAPI spec is fixed
|
|
4466
4464
|
event.poll_vote,
|
|
4467
4465
|
...latestAnswers.filter((answer) => answer.id !== event.poll_vote.id)
|
|
4468
4466
|
];
|
|
@@ -4502,7 +4500,6 @@ class StreamPoll {
|
|
|
4502
4500
|
} = event.poll;
|
|
4503
4501
|
this.state.partialNext({
|
|
4504
4502
|
answers_count,
|
|
4505
|
-
// @ts-expect-error Incompatibility between PollResponseData and Poll due to teams_role, remove when OpenAPI spec is fixed
|
|
4506
4503
|
latest_votes_by_option,
|
|
4507
4504
|
vote_count,
|
|
4508
4505
|
vote_counts_by_option,
|
|
@@ -4545,7 +4542,6 @@ class StreamPoll {
|
|
|
4545
4542
|
} = event.poll;
|
|
4546
4543
|
this.state.partialNext({
|
|
4547
4544
|
answers_count,
|
|
4548
|
-
// @ts-expect-error Incompatibility between PollResponseData and Poll due to teams_role, remove when OpenAPI spec is fixed
|
|
4549
4545
|
latest_votes_by_option,
|
|
4550
4546
|
vote_count,
|
|
4551
4547
|
vote_counts_by_option,
|
|
@@ -4802,6 +4798,7 @@ function updateEntityInArray({
|
|
|
4802
4798
|
updatedEntities[index] = newEntity;
|
|
4803
4799
|
return { changed: true, entities: updatedEntities };
|
|
4804
4800
|
}
|
|
4801
|
+
const ownFeedFields = ["own_capabilities", "own_follows", "own_membership"];
|
|
4805
4802
|
const updateStateFollowCreated = (follow, currentState, currentFeedId, connectedUserId) => {
|
|
4806
4803
|
if (follow.status !== "accepted") {
|
|
4807
4804
|
return { changed: false, data: currentState };
|
|
@@ -5508,7 +5505,7 @@ function handleBookmarkUpdated(event) {
|
|
|
5508
5505
|
});
|
|
5509
5506
|
}
|
|
5510
5507
|
}
|
|
5511
|
-
function addActivitiesToState(newActivities, activities, position) {
|
|
5508
|
+
function addActivitiesToState(newActivities, activities, position, { fromWebSocket } = { fromWebSocket: false }) {
|
|
5512
5509
|
if (activities === void 0) {
|
|
5513
5510
|
return {
|
|
5514
5511
|
changed: false,
|
|
@@ -5531,7 +5528,7 @@ function addActivitiesToState(newActivities, activities, position) {
|
|
|
5531
5528
|
...activities,
|
|
5532
5529
|
...position === "end" ? newActivitiesDeduplicated : []
|
|
5533
5530
|
];
|
|
5534
|
-
this.newActivitiesAdded(newActivitiesDeduplicated);
|
|
5531
|
+
this.newActivitiesAdded(newActivitiesDeduplicated, { fromWebSocket });
|
|
5535
5532
|
result = { changed: true, activities: updatedActivities };
|
|
5536
5533
|
}
|
|
5537
5534
|
return result;
|
|
@@ -5546,7 +5543,8 @@ function handleActivityAdded(event) {
|
|
|
5546
5543
|
const result = addActivitiesToState.bind(this)(
|
|
5547
5544
|
[event.activity],
|
|
5548
5545
|
currentActivities,
|
|
5549
|
-
this.currentState.addNewActivitiesTo
|
|
5546
|
+
this.currentState.addNewActivitiesTo,
|
|
5547
|
+
{ fromWebSocket: true }
|
|
5550
5548
|
);
|
|
5551
5549
|
if (result.changed) {
|
|
5552
5550
|
const activity = event.activity;
|
|
@@ -6250,8 +6248,8 @@ const deepEqual = (x, y) => {
|
|
|
6250
6248
|
return false;
|
|
6251
6249
|
}
|
|
6252
6250
|
};
|
|
6253
|
-
function getOrCreateActiveFeed(
|
|
6254
|
-
return this.getOrCreateActiveFeed(
|
|
6251
|
+
function getOrCreateActiveFeed(...args) {
|
|
6252
|
+
return this.getOrCreateActiveFeed(...args);
|
|
6255
6253
|
}
|
|
6256
6254
|
const _Feed = class _Feed extends FeedApi {
|
|
6257
6255
|
constructor(client, groupId, id, data, watch = false, addNewActivitiesTo = "start", activityAddedEventFilter) {
|
|
@@ -6834,9 +6832,11 @@ const _Feed = class _Feed extends FeedApi {
|
|
|
6834
6832
|
event.activity.current_feed = currentActivity.current_feed;
|
|
6835
6833
|
}
|
|
6836
6834
|
if (event.activity.feeds.length === 1 && event.activity.current_feed && currentActivity?.current_feed) {
|
|
6837
|
-
|
|
6838
|
-
|
|
6839
|
-
|
|
6835
|
+
ownFeedFields.forEach((field) => {
|
|
6836
|
+
if (field in currentActivity.current_feed) {
|
|
6837
|
+
event.activity.current_feed[field] = currentActivity.current_feed[field];
|
|
6838
|
+
}
|
|
6839
|
+
});
|
|
6840
6840
|
}
|
|
6841
6841
|
}
|
|
6842
6842
|
eventHandler?.(event);
|
|
@@ -6846,17 +6846,31 @@ const _Feed = class _Feed extends FeedApi {
|
|
|
6846
6846
|
}
|
|
6847
6847
|
this.eventDispatcher.dispatch(event);
|
|
6848
6848
|
}
|
|
6849
|
-
newActivitiesAdded(activities) {
|
|
6849
|
+
newActivitiesAdded(activities, options = { fromWebSocket: false }) {
|
|
6850
6850
|
this.client.hydratePollCache(activities);
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6851
|
+
this.getOrCreateFeeds(activities, options);
|
|
6852
|
+
}
|
|
6853
|
+
getOrCreateFeeds(activities, options) {
|
|
6854
|
+
const enrichmentOptions = this.currentState.last_get_or_create_request_config?.enrichment_options;
|
|
6855
|
+
if (!enrichmentOptions?.skip_activity_current_feed && !enrichmentOptions?.skip_all) {
|
|
6856
|
+
const feedsToGetOrCreate = /* @__PURE__ */ new Map();
|
|
6857
|
+
activities.forEach((activity) => {
|
|
6858
|
+
if (activity.current_feed && !feedsToGetOrCreate.has(activity.current_feed.feed)) {
|
|
6859
|
+
feedsToGetOrCreate.set(
|
|
6860
|
+
activity.current_feed.feed,
|
|
6861
|
+
activity.current_feed
|
|
6862
|
+
);
|
|
6863
|
+
}
|
|
6864
|
+
});
|
|
6865
|
+
feedsToGetOrCreate.values().forEach((feed) => {
|
|
6866
|
+
getOrCreateActiveFeed.bind(this.client)({
|
|
6867
|
+
group: feed.group_id,
|
|
6868
|
+
id: feed.id,
|
|
6869
|
+
data: feed,
|
|
6870
|
+
fromWebSocket: options.fromWebSocket
|
|
6871
|
+
});
|
|
6872
|
+
});
|
|
6873
|
+
}
|
|
6860
6874
|
}
|
|
6861
6875
|
};
|
|
6862
6876
|
_Feed.noop = () => {
|
|
@@ -7146,6 +7160,30 @@ class ActivityWithStateUpdates {
|
|
|
7146
7160
|
function getFeed() {
|
|
7147
7161
|
return this.feed;
|
|
7148
7162
|
}
|
|
7163
|
+
const isOwnFollowsEqual = (currentState, newState) => {
|
|
7164
|
+
const existingFollows = new Set(
|
|
7165
|
+
currentState.own_follows?.map(
|
|
7166
|
+
(f) => `${f.source_feed.feed}:${f.target_feed.feed}:${f.updated_at.getTime()}`
|
|
7167
|
+
)
|
|
7168
|
+
);
|
|
7169
|
+
const newFollows = new Set(
|
|
7170
|
+
newState.own_follows?.map(
|
|
7171
|
+
(f) => `${f.source_feed.feed}:${f.target_feed.feed}:${f.updated_at.getTime()}`
|
|
7172
|
+
)
|
|
7173
|
+
);
|
|
7174
|
+
if (existingFollows.size === newFollows.size) {
|
|
7175
|
+
const areEqual = Array.from(existingFollows).every(
|
|
7176
|
+
(f) => newFollows.has(f)
|
|
7177
|
+
);
|
|
7178
|
+
if (areEqual) {
|
|
7179
|
+
return true;
|
|
7180
|
+
}
|
|
7181
|
+
}
|
|
7182
|
+
return false;
|
|
7183
|
+
};
|
|
7184
|
+
const isOwnMembershipEqual = (currentState, newState) => {
|
|
7185
|
+
return (currentState.own_membership?.updated_at.getTime() ?? 0) === (newState.own_membership?.updated_at.getTime() ?? 0);
|
|
7186
|
+
};
|
|
7149
7187
|
class FeedsClient extends FeedsApi {
|
|
7150
7188
|
constructor(apiKey, options) {
|
|
7151
7189
|
const tokenManager = new TokenManager();
|
|
@@ -7397,13 +7435,11 @@ class FeedsClient extends FeedsApi {
|
|
|
7397
7435
|
this.on = this.eventDispatcher.on;
|
|
7398
7436
|
this.off = this.eventDispatcher.off;
|
|
7399
7437
|
this.feed = (groupId, id, options2) => {
|
|
7400
|
-
return this.getOrCreateActiveFeed(
|
|
7401
|
-
groupId,
|
|
7438
|
+
return this.getOrCreateActiveFeed({
|
|
7439
|
+
group: groupId,
|
|
7402
7440
|
id,
|
|
7403
|
-
|
|
7404
|
-
|
|
7405
|
-
options2
|
|
7406
|
-
);
|
|
7441
|
+
options: options2
|
|
7442
|
+
});
|
|
7407
7443
|
};
|
|
7408
7444
|
this.activityWithStateUpdates = (id) => {
|
|
7409
7445
|
let activity = this.activeActivities[id];
|
|
@@ -7420,7 +7456,14 @@ class FeedsClient extends FeedsApi {
|
|
|
7420
7456
|
};
|
|
7421
7457
|
this.eventDispatcher.dispatch(networkEvent);
|
|
7422
7458
|
};
|
|
7423
|
-
this.getOrCreateActiveFeed = (
|
|
7459
|
+
this.getOrCreateActiveFeed = ({
|
|
7460
|
+
group,
|
|
7461
|
+
id,
|
|
7462
|
+
data,
|
|
7463
|
+
watch,
|
|
7464
|
+
options: options2,
|
|
7465
|
+
fromWebSocket = false
|
|
7466
|
+
}) => {
|
|
7424
7467
|
const fid = `${group}:${id}`;
|
|
7425
7468
|
let isCreated = false;
|
|
7426
7469
|
if (!this.activeFeeds[fid]) {
|
|
@@ -7445,7 +7488,29 @@ class FeedsClient extends FeedsApi {
|
|
|
7445
7488
|
}
|
|
7446
7489
|
}
|
|
7447
7490
|
if (!feed.currentState.watch) {
|
|
7448
|
-
if (data)
|
|
7491
|
+
if (!isCreated && data) {
|
|
7492
|
+
if ((feed.currentState.updated_at?.getTime() ?? 0) < data.updated_at.getTime()) {
|
|
7493
|
+
handleFeedUpdated.call(feed, { feed: data });
|
|
7494
|
+
} else if ((feed.currentState.updated_at?.getTime() ?? 0) === data.updated_at.getTime() && !fromWebSocket) {
|
|
7495
|
+
const fieldsToUpdate = [];
|
|
7496
|
+
if (!isOwnFollowsEqual(feed.currentState, data)) {
|
|
7497
|
+
fieldsToUpdate.push("own_follows");
|
|
7498
|
+
}
|
|
7499
|
+
if (!isOwnMembershipEqual(feed.currentState, data)) {
|
|
7500
|
+
fieldsToUpdate.push("own_membership");
|
|
7501
|
+
}
|
|
7502
|
+
if (fieldsToUpdate.length > 0) {
|
|
7503
|
+
const fieldsToUpdateData = fieldsToUpdate.reduce(
|
|
7504
|
+
(acc, field) => {
|
|
7505
|
+
acc[field] = data[field];
|
|
7506
|
+
return acc;
|
|
7507
|
+
},
|
|
7508
|
+
{}
|
|
7509
|
+
);
|
|
7510
|
+
feed.state.partialNext(fieldsToUpdateData);
|
|
7511
|
+
}
|
|
7512
|
+
}
|
|
7513
|
+
}
|
|
7449
7514
|
if (watch) handleWatchStarted.call(feed);
|
|
7450
7515
|
}
|
|
7451
7516
|
return feed;
|
|
@@ -7479,11 +7544,11 @@ class FeedsClient extends FeedsApi {
|
|
|
7479
7544
|
}
|
|
7480
7545
|
case "feeds.feed.created": {
|
|
7481
7546
|
if (this.activeFeeds[event.feed.id]) break;
|
|
7482
|
-
this.getOrCreateActiveFeed(
|
|
7483
|
-
event.feed.group_id,
|
|
7484
|
-
event.feed.id,
|
|
7485
|
-
event.feed
|
|
7486
|
-
);
|
|
7547
|
+
this.getOrCreateActiveFeed({
|
|
7548
|
+
group: event.feed.group_id,
|
|
7549
|
+
id: event.feed.id,
|
|
7550
|
+
data: event.feed
|
|
7551
|
+
});
|
|
7487
7552
|
break;
|
|
7488
7553
|
}
|
|
7489
7554
|
case "feeds.feed.deleted": {
|
|
@@ -7623,12 +7688,12 @@ class FeedsClient extends FeedsApi {
|
|
|
7623
7688
|
const response = await this._queryFeeds(request);
|
|
7624
7689
|
const feedResponses = response.feeds;
|
|
7625
7690
|
const feeds = feedResponses.map(
|
|
7626
|
-
(feedResponse) => this.getOrCreateActiveFeed(
|
|
7627
|
-
feedResponse.group_id,
|
|
7628
|
-
feedResponse.id,
|
|
7629
|
-
feedResponse,
|
|
7630
|
-
request?.watch
|
|
7631
|
-
)
|
|
7691
|
+
(feedResponse) => this.getOrCreateActiveFeed({
|
|
7692
|
+
group: feedResponse.group_id,
|
|
7693
|
+
id: feedResponse.id,
|
|
7694
|
+
data: feedResponse,
|
|
7695
|
+
watch: request?.watch
|
|
7696
|
+
})
|
|
7632
7697
|
);
|
|
7633
7698
|
this.hydrateCapabilitiesCache(feedResponses);
|
|
7634
7699
|
return {
|
|
@@ -7718,11 +7783,11 @@ class FeedsClient extends FeedsApi {
|
|
|
7718
7783
|
async getFollowSuggestions(...params) {
|
|
7719
7784
|
const response = await super.getFollowSuggestions(...params);
|
|
7720
7785
|
response.suggestions.forEach((suggestion) => {
|
|
7721
|
-
this.getOrCreateActiveFeed(
|
|
7722
|
-
suggestion.group_id,
|
|
7723
|
-
suggestion.id,
|
|
7724
|
-
suggestion
|
|
7725
|
-
);
|
|
7786
|
+
this.getOrCreateActiveFeed({
|
|
7787
|
+
group: suggestion.group_id,
|
|
7788
|
+
id: suggestion.id,
|
|
7789
|
+
data: suggestion
|
|
7790
|
+
});
|
|
7726
7791
|
});
|
|
7727
7792
|
return response;
|
|
7728
7793
|
}
|
|
@@ -7801,8 +7866,9 @@ exports.isImageFile = isImageFile;
|
|
|
7801
7866
|
exports.isReactionResponse = isReactionResponse;
|
|
7802
7867
|
exports.isVideoFile = isVideoFile;
|
|
7803
7868
|
exports.isVoteAnswer = isVoteAnswer;
|
|
7869
|
+
exports.ownFeedFields = ownFeedFields;
|
|
7804
7870
|
exports.replaceUniqueArrayMerge = replaceUniqueArrayMerge;
|
|
7805
7871
|
exports.shouldUpdateState = shouldUpdateState;
|
|
7806
7872
|
exports.uniqueArrayMerge = uniqueArrayMerge;
|
|
7807
7873
|
exports.updateEntityInArray = updateEntityInArray;
|
|
7808
|
-
//# sourceMappingURL=feeds-client-
|
|
7874
|
+
//# sourceMappingURL=feeds-client-DUD5wy6N.js.map
|