@stream-io/feeds-client 0.3.37 → 0.3.39

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 (49) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/index.js +1 -1
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/react-bindings.js +30 -8
  5. package/dist/cjs/react-bindings.js.map +1 -1
  6. package/dist/es/index.mjs +2 -2
  7. package/dist/es/index.mjs.map +1 -1
  8. package/dist/es/react-bindings.mjs +30 -8
  9. package/dist/es/react-bindings.mjs.map +1 -1
  10. package/dist/{feeds-client-DEV6_pkH.js → feeds-client-CT1eKizN.js} +73 -22
  11. package/dist/feeds-client-CT1eKizN.js.map +1 -0
  12. package/dist/{feeds-client-CExHb6GS.mjs → feeds-client-DnryJ-rf.mjs} +73 -22
  13. package/dist/feeds-client-DnryJ-rf.mjs.map +1 -0
  14. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  15. package/dist/types/bindings/react/contexts/StreamActivityWithStateUpdatesContext.d.ts +13 -0
  16. package/dist/types/bindings/react/contexts/StreamActivityWithStateUpdatesContext.d.ts.map +1 -0
  17. package/dist/types/bindings/react/hooks/feed-state-hooks/useActivityComments.d.ts +1 -1
  18. package/dist/types/bindings/react/hooks/feed-state-hooks/useActivityComments.d.ts.map +1 -1
  19. package/dist/types/bindings/react/hooks/useCreateFeedsClient.d.ts +3 -3
  20. package/dist/types/bindings/react/hooks/useCreateFeedsClient.d.ts.map +1 -1
  21. package/dist/types/bindings/react/index.d.ts +2 -0
  22. package/dist/types/bindings/react/index.d.ts.map +1 -1
  23. package/dist/types/bindings/react/wrappers/StreamActivityWithStateUpdates.d.ts +13 -0
  24. package/dist/types/bindings/react/wrappers/StreamActivityWithStateUpdates.d.ts.map +1 -0
  25. package/dist/types/common/real-time/StableWSConnection.d.ts +3 -3
  26. package/dist/types/common/real-time/StableWSConnection.d.ts.map +1 -1
  27. package/dist/types/feed/feed.d.ts +3 -3
  28. package/dist/types/feed/feed.d.ts.map +1 -1
  29. package/dist/types/feeds-client/feeds-client.d.ts +10 -15
  30. package/dist/types/feeds-client/feeds-client.d.ts.map +1 -1
  31. package/dist/types/gen/feeds/FeedsApi.d.ts +4 -1
  32. package/dist/types/gen/feeds/FeedsApi.d.ts.map +1 -1
  33. package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts.map +1 -1
  34. package/dist/types/gen/models/index.d.ts +20 -0
  35. package/dist/types/gen/models/index.d.ts.map +1 -1
  36. package/package.json +1 -1
  37. package/src/bindings/react/contexts/StreamActivityWithStateUpdatesContext.tsx +19 -0
  38. package/src/bindings/react/hooks/feed-state-hooks/useActivityComments.ts +6 -3
  39. package/src/bindings/react/hooks/useCreateFeedsClient.ts +23 -12
  40. package/src/bindings/react/index.ts +2 -0
  41. package/src/bindings/react/wrappers/StreamActivityWithStateUpdates.tsx +24 -0
  42. package/src/feed/feed.ts +9 -1
  43. package/src/feeds-client/feeds-client.ts +52 -30
  44. package/src/gen/feeds/FeedsApi.ts +26 -0
  45. package/src/gen/model-decoders/decoders.ts +18 -0
  46. package/src/gen/model-decoders/event-decoder-mapping.ts +3 -0
  47. package/src/gen/models/index.ts +28 -0
  48. package/dist/feeds-client-CExHb6GS.mjs.map +0 -1
  49. package/dist/feeds-client-DEV6_pkH.js.map +0 -1
@@ -11,6 +11,7 @@ export * from './hooks/search-state-hooks';
11
11
 
12
12
  export * from './contexts/StreamFeedsContext';
13
13
  export * from './contexts/StreamFeedContext';
14
+ export * from './contexts/StreamActivityWithStateUpdatesContext';
14
15
  export * from './contexts/StreamSearchContext';
15
16
  export * from './contexts/StreamSearchResultsContext';
16
17
 
@@ -18,5 +19,6 @@ export * from './contexts/StreamSearchResultsContext';
18
19
 
19
20
  export * from './wrappers/StreamFeeds';
20
21
  export * from './wrappers/StreamFeed';
22
+ export * from './wrappers/StreamActivityWithStateUpdates';
21
23
  export * from './wrappers/StreamSearch';
22
24
  export * from './wrappers/StreamSearchResults';
@@ -0,0 +1,24 @@
1
+ import type { PropsWithChildren } from 'react';
2
+
3
+ import { StreamActivityWithStateUpdatesContext } from '../contexts/StreamActivityWithStateUpdatesContext';
4
+ import type { ActivityWithStateUpdates } from '../../../activity-with-state-updates/activity-with-state-updates';
5
+
6
+ /**
7
+ * The props for the StreamActivityWithStateUpdates component. It accepts an `ActivityWithStateUpdates` instance.
8
+ */
9
+ export type StreamActivityWithStateUpdatesProps = {
10
+ activityWithStateUpdates: ActivityWithStateUpdates;
11
+ };
12
+
13
+ export const StreamActivityWithStateUpdates = ({
14
+ activityWithStateUpdates,
15
+ children,
16
+ }: PropsWithChildren<StreamActivityWithStateUpdatesProps>) => {
17
+ return (
18
+ <StreamActivityWithStateUpdatesContext.Provider value={activityWithStateUpdates}>
19
+ {children}
20
+ </StreamActivityWithStateUpdatesContext.Provider>
21
+ );
22
+ };
23
+
24
+ StreamActivityWithStateUpdates.displayName = 'StreamActivityWithStateUpdates';
package/src/feed/feed.ts CHANGED
@@ -219,6 +219,7 @@ export class Feed extends FeedApi {
219
219
  'user.reactivated': Feed.noop,
220
220
  'user.updated': Feed.noop,
221
221
  'feeds.activity.feedback': handleActivityFeedback.bind(this),
222
+ 'feeds.activity.restored': Feed.noop,
222
223
  };
223
224
 
224
225
  protected eventDispatcher: EventDispatcher<WSEvent['type'], WSEvent> =
@@ -872,12 +873,19 @@ export class Feed extends FeedApi {
872
873
  return response;
873
874
  }
874
875
 
875
- async unfollow(feedOrFid: Feed | string) {
876
+ async unfollow(
877
+ feedOrFid: Feed | string,
878
+ options?: Omit<
879
+ Parameters<typeof this.client.unfollow>[0],
880
+ 'source' | 'target'
881
+ >,
882
+ ) {
876
883
  const fid = typeof feedOrFid === 'string' ? feedOrFid : feedOrFid.feed;
877
884
 
878
885
  const response = await this.client.unfollow({
879
886
  source: this.feed,
880
887
  target: fid,
888
+ ...options,
881
889
  });
882
890
 
883
891
  return response;
@@ -103,6 +103,7 @@ import {
103
103
 
104
104
  export type FeedsClientState = {
105
105
  connected_user: ConnectedUser | undefined;
106
+ is_anonymous: boolean;
106
107
  is_ws_connection_healthy: boolean;
107
108
  };
108
109
 
@@ -143,10 +144,7 @@ export class FeedsClient extends FeedsApi {
143
144
  options,
144
145
  );
145
146
  super(apiClient);
146
- this.state = new StateStore<FeedsClientState>({
147
- connected_user: undefined,
148
- is_ws_connection_healthy: false,
149
- });
147
+ this.state = new StateStore<FeedsClientState>(this.initialState);
150
148
  this.moderation = new ModerationClient(apiClient);
151
149
  this.tokenManager = tokenManager;
152
150
  this.connectionIdManager = connectionIdManager;
@@ -365,13 +363,25 @@ export class FeedsClient extends FeedsApi {
365
363
  }
366
364
  }
367
365
 
368
- connectUser = async (user: UserRequest, tokenProvider?: TokenOrProvider) => {
369
- if (
370
- this.state.getLatestValue().connected_user !== undefined ||
371
- this.wsConnection
372
- ) {
373
- throw new Error(`Can't connect a new user, call "disconnectUser" first`);
374
- }
366
+ connectAnonymous = () => {
367
+ this.checkIfUserIsConnected();
368
+
369
+ this.connectionIdManager.resolveConnectionidPromise();
370
+ this.tokenManager.setTokenOrProvider(undefined);
371
+ this.setGetBatchOwnFieldsThrottlingInterval(
372
+ this.query_batch_own_fields_throttling_interval,
373
+ );
374
+ this.state.partialNext({
375
+ connected_user: undefined,
376
+ is_anonymous: true,
377
+ is_ws_connection_healthy: false,
378
+ });
379
+
380
+ return Promise.resolve();
381
+ };
382
+
383
+ connectUser = async (user: UserRequest, tokenProvider: TokenOrProvider) => {
384
+ this.checkIfUserIsConnected();
375
385
 
376
386
  this.tokenManager.setTokenOrProvider(tokenProvider);
377
387
 
@@ -487,11 +497,10 @@ export class FeedsClient extends FeedsApi {
487
497
  return response;
488
498
  };
489
499
 
490
- deleteComment = async (request: {
491
- id: string;
492
- hard_delete?: boolean;
493
- }): Promise<StreamResponse<DeleteCommentResponse>> => {
494
- const response = await super.deleteComment(request);
500
+ deleteComment = async (
501
+ ...args: Parameters<FeedsApi['deleteComment']>
502
+ ): Promise<StreamResponse<DeleteCommentResponse>> => {
503
+ const response = await super.deleteComment(...args);
495
504
  const { activity, comment } = response;
496
505
  for (const feed of this.allActiveFeeds) {
497
506
  handleCommentDeleted.bind(feed)({ comment }, false);
@@ -532,11 +541,10 @@ export class FeedsClient extends FeedsApi {
532
541
  return this.addActivityReaction(request);
533
542
  };
534
543
 
535
- deleteActivityReaction = async (request: {
536
- activity_id: string;
537
- type: string;
538
- }): Promise<StreamResponse<DeleteActivityReactionResponse>> => {
539
- const response = await super.deleteActivityReaction(request);
544
+ deleteActivityReaction = async (
545
+ ...args: Parameters<FeedsApi['deleteActivityReaction']>
546
+ ): Promise<StreamResponse<DeleteActivityReactionResponse>> => {
547
+ const response = await super.deleteActivityReaction(...args);
540
548
  for (const feed of this.allActiveFeeds) {
541
549
  handleActivityReactionDeleted.bind(feed)(response, false);
542
550
  }
@@ -558,11 +566,10 @@ export class FeedsClient extends FeedsApi {
558
566
  return response;
559
567
  };
560
568
 
561
- deleteCommentReaction = async (request: {
562
- id: string;
563
- type: string;
564
- }): Promise<StreamResponse<DeleteCommentReactionResponse>> => {
565
- const response = await super.deleteCommentReaction(request);
569
+ deleteCommentReaction = async (
570
+ ...args: Parameters<FeedsApi['deleteCommentReaction']>
571
+ ): Promise<StreamResponse<DeleteCommentReactionResponse>> => {
572
+ const response = await super.deleteCommentReaction(...args);
566
573
  for (const feed of this.allActiveFeeds) {
567
574
  handleCommentReactionDeleted.bind(feed)(response, false);
568
575
  }
@@ -614,10 +621,7 @@ export class FeedsClient extends FeedsApi {
614
621
  this.activeActivities = [];
615
622
  this.activeFeeds = {};
616
623
 
617
- this.state.partialNext({
618
- connected_user: undefined,
619
- is_ws_connection_healthy: false,
620
- });
624
+ this.state.partialNext(this.initialState);
621
625
 
622
626
  this.cancelGetBatchOwnFieldsTimer();
623
627
  clearQueuedFeeds();
@@ -1010,4 +1014,22 @@ export class FeedsClient extends FeedsApi {
1010
1014
  feeds.forEach((f) => handleFollowDeleted.bind(f)({ follow }, false));
1011
1015
  });
1012
1016
  }
1017
+
1018
+ private get initialState() {
1019
+ return {
1020
+ connected_user: undefined,
1021
+ is_anonymous: false,
1022
+ is_ws_connection_healthy: false,
1023
+ };
1024
+ }
1025
+
1026
+ private checkIfUserIsConnected() {
1027
+ if (
1028
+ this.state.getLatestValue().connected_user !== undefined ||
1029
+ this.wsConnection ||
1030
+ this.state.getLatestValue().is_anonymous
1031
+ ) {
1032
+ throw new Error(`Can't connect a new user, call "disconnectUser" first`);
1033
+ }
1034
+ }
1013
1035
  }
@@ -99,6 +99,8 @@ import type {
99
99
  RejectFollowRequest,
100
100
  RejectFollowResponse,
101
101
  Response,
102
+ RestoreActivityRequest,
103
+ RestoreActivityResponse,
102
104
  SharedLocationResponse,
103
105
  SharedLocationsResponse,
104
106
  SingleFollowResponse,
@@ -783,6 +785,30 @@ export class FeedsApi {
783
785
  return { ...response.body, metadata: response.metadata };
784
786
  }
785
787
 
788
+ async restoreActivity(
789
+ request: RestoreActivityRequest & { id: string },
790
+ ): Promise<StreamResponse<RestoreActivityResponse>> {
791
+ const pathParams = {
792
+ id: request?.id,
793
+ };
794
+ const body = {};
795
+
796
+ const response = await this.apiClient.sendRequest<
797
+ StreamResponse<RestoreActivityResponse>
798
+ >(
799
+ 'PUT',
800
+ '/api/v2/feeds/activities/{id}/restore',
801
+ pathParams,
802
+ undefined,
803
+ body,
804
+ 'application/json',
805
+ );
806
+
807
+ decoders.RestoreActivityResponse?.(response.body);
808
+
809
+ return { ...response.body, metadata: response.metadata };
810
+ }
811
+
786
812
  async queryBookmarkFolders(
787
813
  request?: QueryBookmarkFoldersRequest,
788
814
  ): Promise<StreamResponse<QueryBookmarkFoldersResponse>> {
@@ -212,6 +212,17 @@ decoders.ActivityResponse = (input?: Record<string, any>) => {
212
212
  return decode(typeMappings, input);
213
213
  };
214
214
 
215
+ decoders.ActivityRestoredEvent = (input?: Record<string, any>) => {
216
+ const typeMappings: TypeMapping = {
217
+ created_at: { type: 'DatetimeType', isSingle: true },
218
+
219
+ activity: { type: 'ActivityResponse', isSingle: true },
220
+
221
+ received_at: { type: 'DatetimeType', isSingle: true },
222
+ };
223
+ return decode(typeMappings, input);
224
+ };
225
+
215
226
  decoders.ActivityUnpinnedEvent = (input?: Record<string, any>) => {
216
227
  const typeMappings: TypeMapping = {
217
228
  created_at: { type: 'DatetimeType', isSingle: true },
@@ -1785,6 +1796,13 @@ decoders.ReminderResponseData = (input?: Record<string, any>) => {
1785
1796
  return decode(typeMappings, input);
1786
1797
  };
1787
1798
 
1799
+ decoders.RestoreActivityResponse = (input?: Record<string, any>) => {
1800
+ const typeMappings: TypeMapping = {
1801
+ activity: { type: 'ActivityResponse', isSingle: true },
1802
+ };
1803
+ return decode(typeMappings, input);
1804
+ };
1805
+
1788
1806
  decoders.ReviewQueueItemResponse = (input?: Record<string, any>) => {
1789
1807
  const typeMappings: TypeMapping = {
1790
1808
  created_at: { type: 'DatetimeType', isSingle: true },
@@ -34,6 +34,9 @@ const eventDecoderMapping: Record<
34
34
  'feeds.activity.removed_from_feed': (data: Record<string, any>) =>
35
35
  decoders.ActivityRemovedFromFeedEvent(data),
36
36
 
37
+ 'feeds.activity.restored': (data: Record<string, any>) =>
38
+ decoders.ActivityRestoredEvent(data),
39
+
37
40
  'feeds.activity.unpinned': (data: Record<string, any>) =>
38
41
  decoders.ActivityUnpinnedEvent(data),
39
42
 
@@ -490,6 +490,24 @@ export interface ActivityResponse {
490
490
  poll?: PollResponseData;
491
491
  }
492
492
 
493
+ export interface ActivityRestoredEvent {
494
+ created_at: Date;
495
+
496
+ fid: string;
497
+
498
+ activity: ActivityResponse;
499
+
500
+ custom: Record<string, any>;
501
+
502
+ type: string;
503
+
504
+ feed_visibility?: string;
505
+
506
+ received_at?: Date;
507
+
508
+ user?: UserResponseCommonFields;
509
+ }
510
+
493
511
  export interface ActivitySelectorConfig {
494
512
  cutoff_time: Date;
495
513
 
@@ -5138,6 +5156,14 @@ export interface RestoreActionRequest {
5138
5156
  decision_reason?: string;
5139
5157
  }
5140
5158
 
5159
+ export interface RestoreActivityRequest {}
5160
+
5161
+ export interface RestoreActivityResponse {
5162
+ duration: string;
5163
+
5164
+ activity: ActivityResponse;
5165
+ }
5166
+
5141
5167
  export interface ReviewQueueItemResponse {
5142
5168
  ai_text_severity: string;
5143
5169
 
@@ -6472,6 +6498,7 @@ export type WSClientEvent =
6472
6498
  | ({
6473
6499
  type: 'feeds.activity.removed_from_feed';
6474
6500
  } & ActivityRemovedFromFeedEvent)
6501
+ | ({ type: 'feeds.activity.restored' } & ActivityRestoredEvent)
6475
6502
  | ({ type: 'feeds.activity.unpinned' } & ActivityUnpinnedEvent)
6476
6503
  | ({ type: 'feeds.activity.updated' } & ActivityUpdatedEvent)
6477
6504
  | ({ type: 'feeds.bookmark.added' } & BookmarkAddedEvent)
@@ -6522,6 +6549,7 @@ export type WSEvent =
6522
6549
  | ({
6523
6550
  type: 'feeds.activity.removed_from_feed';
6524
6551
  } & ActivityRemovedFromFeedEvent)
6552
+ | ({ type: 'feeds.activity.restored' } & ActivityRestoredEvent)
6525
6553
  | ({ type: 'feeds.activity.unpinned' } & ActivityUnpinnedEvent)
6526
6554
  | ({ type: 'feeds.activity.updated' } & ActivityUpdatedEvent)
6527
6555
  | ({ type: 'feeds.bookmark.added' } & BookmarkAddedEvent)