@stream-io/feeds-client 0.1.2 → 0.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stream-io/feeds-client",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "packageManager": "yarn@3.2.4",
5
5
  "main": "./dist/index.node.js",
6
6
  "exports": {
package/src/Feed.ts CHANGED
@@ -106,6 +106,8 @@ export type FeedState = Omit<
106
106
  followers_pagination?: LoadingStates & { sort?: string };
107
107
 
108
108
  following_pagination?: LoadingStates & { sort?: string };
109
+
110
+ last_get_or_create_request_config?: GetOrCreateFeedRequest;
109
111
  };
110
112
 
111
113
  const END_OF_LIST = 'eol' as const;
@@ -555,6 +557,13 @@ export class Feed extends FeedApi {
555
557
  });
556
558
  }
557
559
 
560
+ async synchronize() {
561
+ const { last_get_or_create_request_config } = this.state.getLatestValue();
562
+ if (last_get_or_create_request_config?.watch) {
563
+ await this.getOrCreate(last_get_or_create_request_config);
564
+ }
565
+ }
566
+
558
567
  async getOrCreate(request?: GetOrCreateFeedRequest) {
559
568
  if (this.currentState.is_loading_activities) {
560
569
  throw new Error('Only one getOrCreate call is allowed at a time');
@@ -644,6 +653,8 @@ export class Feed extends FeedApi {
644
653
  delete nextState.following;
645
654
  }
646
655
 
656
+ nextState.last_get_or_create_request_config = request;
657
+
647
658
  return nextState;
648
659
  });
649
660
  }
@@ -1036,7 +1047,8 @@ export class Feed extends FeedApi {
1036
1047
 
1037
1048
  async getNextPage() {
1038
1049
  const currentState = this.currentState;
1039
- const response = await this.getOrCreate({
1050
+
1051
+ return await this.getOrCreate({
1040
1052
  member_pagination: {
1041
1053
  limit: 0,
1042
1054
  },
@@ -1047,9 +1059,8 @@ export class Feed extends FeedApi {
1047
1059
  limit: 0,
1048
1060
  },
1049
1061
  next: currentState.next,
1062
+ limit: currentState.last_get_or_create_request_config?.limit ?? 20,
1050
1063
  });
1051
-
1052
- return response;
1053
1064
  }
1054
1065
 
1055
1066
  addActivity(request: Omit<ActivityRequest, 'fids'>) {
@@ -56,6 +56,8 @@ export class FeedsClient extends FeedsApi {
56
56
 
57
57
  private activeFeeds: Record<FID, Feed> = {};
58
58
 
59
+ private healthyConnectionChangedEventCount = 0;
60
+
59
61
  constructor(apiKey: string, options?: FeedsClientOptions) {
60
62
  const tokenManager = new TokenManager();
61
63
  const connectionIdManager = new ConnectionIdManager();
@@ -84,6 +86,17 @@ export class FeedsClient extends FeedsApi {
84
86
  case 'connection.changed': {
85
87
  const { online } = event;
86
88
  this.state.partialNext({ isWsConnectionHealthy: online });
89
+
90
+ if (online) {
91
+ this.healthyConnectionChangedEventCount++;
92
+
93
+ // we skip the first event as we could potentially be querying twice
94
+ if (this.healthyConnectionChangedEventCount > 1) {
95
+ for (const activeFeed of Object.values(this.activeFeeds)) {
96
+ activeFeed.synchronize();
97
+ }
98
+ }
99
+ }
87
100
  break;
88
101
  }
89
102
  case 'feeds.feed.created': {
@@ -13,6 +13,7 @@ import { ConnectionIdManager } from './ConnectionIdManager';
13
13
  export class ApiClient {
14
14
  public readonly baseUrl: string;
15
15
  private readonly axiosInstance: AxiosInstance;
16
+ private timeout: number;
16
17
 
17
18
  constructor(
18
19
  public readonly apiKey: string,
@@ -21,9 +22,9 @@ export class ApiClient {
21
22
  options?: FeedsClientOptions,
22
23
  ) {
23
24
  this.baseUrl = options?.base_url ?? 'https://video.stream-io-api.com';
25
+ this.timeout = options?.timeout ?? 3000;
24
26
  this.axiosInstance = axios.create({
25
27
  baseURL: this.baseUrl,
26
- timeout: options?.timeout ?? 3000,
27
28
  });
28
29
  }
29
30
 
@@ -74,7 +75,10 @@ export class ApiClient {
74
75
  requestContentType === 'multipart/form-data' ? new FormData() : body;
75
76
  if (requestContentType === 'multipart/form-data') {
76
77
  Object.keys(body).forEach((key) => {
77
- encodedBody.append(key, body[key]);
78
+ const value = body[key];
79
+ if (value != null) {
80
+ encodedBody.append(key, value);
81
+ }
78
82
  });
79
83
  }
80
84
 
@@ -84,8 +88,11 @@ export class ApiClient {
84
88
  method,
85
89
  headers,
86
90
  params: queryParams,
87
- paramsSerializer: params => this.queryParamsStringify(params),
91
+ paramsSerializer: (params) => this.queryParamsStringify(params),
88
92
  data: encodedBody,
93
+ timeout:
94
+ // multipart/form-data requests should not have a timeout allowing ample time for file uploads
95
+ requestContentType === 'multipart/form-data' ? 0 : this.timeout,
89
96
  });
90
97
 
91
98
  const metadata: RequestMetadata = this.getRequestMetadata(
@@ -647,6 +647,7 @@ export class FeedsApi {
647
647
  };
648
648
  const body = {
649
649
  type: request?.type,
650
+ create_notification_activity: request?.create_notification_activity,
650
651
  custom: request?.custom,
651
652
  };
652
653
 
@@ -858,6 +859,7 @@ export class FeedsApi {
858
859
  comment: request?.comment,
859
860
  object_id: request?.object_id,
860
861
  object_type: request?.object_type,
862
+ create_notification_activity: request?.create_notification_activity,
861
863
  parent_id: request?.parent_id,
862
864
  attachments: request?.attachments,
863
865
  mentioned_user_ids: request?.mentioned_user_ids,
@@ -997,6 +999,7 @@ export class FeedsApi {
997
999
  };
998
1000
  const body = {
999
1001
  type: request?.type,
1002
+ create_notification_activity: request?.create_notification_activity,
1000
1003
  custom: request?.custom,
1001
1004
  };
1002
1005
 
@@ -1497,6 +1500,7 @@ export class FeedsApi {
1497
1500
  const body = {
1498
1501
  source: request?.source,
1499
1502
  target: request?.target,
1503
+ create_notification_activity: request?.create_notification_activity,
1500
1504
  follower_role: request?.follower_role,
1501
1505
  push_preference: request?.push_preference,
1502
1506
  custom: request?.custom,
@@ -1524,6 +1528,7 @@ export class FeedsApi {
1524
1528
  const body = {
1525
1529
  source: request?.source,
1526
1530
  target: request?.target,
1531
+ create_notification_activity: request?.create_notification_activity,
1527
1532
  push_preference: request?.push_preference,
1528
1533
  custom: request?.custom,
1529
1534
  };
@@ -430,6 +430,8 @@ export interface ActivityResponse {
430
430
  parent?: ActivityResponse;
431
431
 
432
432
  poll?: PollResponseData;
433
+
434
+ target?: Record<string, any>;
433
435
  }
434
436
 
435
437
  export interface ActivityUnpinnedEvent {
@@ -521,6 +523,8 @@ export interface AddBookmarkResponse {
521
523
  export interface AddCommentReactionRequest {
522
524
  type: string;
523
525
 
526
+ create_notification_activity?: boolean;
527
+
524
528
  custom?: Record<string, any>;
525
529
  }
526
530
 
@@ -539,6 +543,8 @@ export interface AddCommentRequest {
539
543
 
540
544
  object_type: string;
541
545
 
546
+ create_notification_activity?: boolean;
547
+
542
548
  parent_id?: string;
543
549
 
544
550
  attachments?: Attachment[];
@@ -573,6 +579,8 @@ export interface AddFolderRequest {
573
579
  export interface AddReactionRequest {
574
580
  type: string;
575
581
 
582
+ create_notification_activity?: boolean;
583
+
576
584
  custom?: Record<string, any>;
577
585
  }
578
586
 
@@ -802,6 +810,16 @@ export interface BanActionRequest {
802
810
  timeout?: number;
803
811
  }
804
812
 
813
+ export interface BanOptions {
814
+ duration: number;
815
+
816
+ ip_ban: boolean;
817
+
818
+ reason: string;
819
+
820
+ shadow_ban: boolean;
821
+ }
822
+
805
823
  export interface BanRequest {
806
824
  target_user_id: string;
807
825
 
@@ -826,6 +844,10 @@ export interface BanResponse {
826
844
  duration: string;
827
845
  }
828
846
 
847
+ export interface BlockContentOptions {
848
+ reason: string;
849
+ }
850
+
829
851
  export interface BlockListConfig {
830
852
  enabled: boolean;
831
853
 
@@ -1944,6 +1966,8 @@ export interface ConfigResponse {
1944
1966
 
1945
1967
  block_list_config?: BlockListConfig;
1946
1968
 
1969
+ rule_builder_config?: RuleBuilderConfig;
1970
+
1947
1971
  velocity_filter_config?: VelocityFilterConfig;
1948
1972
 
1949
1973
  video_call_rule_config?: VideoCallRuleConfig;
@@ -1965,6 +1989,12 @@ export interface ConnectUserDetailsRequest {
1965
1989
  privacy_settings?: PrivacySettingsResponse;
1966
1990
  }
1967
1991
 
1992
+ export interface ContentCountRuleParameters {
1993
+ threshold: number;
1994
+
1995
+ time_window: string;
1996
+ }
1997
+
1968
1998
  export interface CreateBlockListRequest {
1969
1999
  name: string;
1970
2000
 
@@ -2797,6 +2827,10 @@ export interface Flag {
2797
2827
  user?: User;
2798
2828
  }
2799
2829
 
2830
+ export interface FlagContentOptions {
2831
+ reason: string;
2832
+ }
2833
+
2800
2834
  export interface FlagRequest {
2801
2835
  entity_id: string;
2802
2836
 
@@ -2817,6 +2851,10 @@ export interface FlagResponse {
2817
2851
  item_id: string;
2818
2852
  }
2819
2853
 
2854
+ export interface FlagUserOptions {
2855
+ reason: string;
2856
+ }
2857
+
2820
2858
  export interface FollowBatchRequest {
2821
2859
  follows: FollowRequest[];
2822
2860
  }
@@ -2860,6 +2898,8 @@ export interface FollowRequest {
2860
2898
 
2861
2899
  target: string;
2862
2900
 
2901
+ create_notification_activity?: boolean;
2902
+
2863
2903
  push_preference?: 'all' | 'none';
2864
2904
 
2865
2905
  custom?: Record<string, any>;
@@ -3223,6 +3263,10 @@ export interface HealthCheckEvent {
3223
3263
  me?: OwnUserResponse;
3224
3264
  }
3225
3265
 
3266
+ export interface ImageContentParameters {
3267
+ harm_labels?: string[];
3268
+ }
3269
+
3226
3270
  export interface ImageData {
3227
3271
  frames: string;
3228
3272
 
@@ -3235,6 +3279,14 @@ export interface ImageData {
3235
3279
  width: string;
3236
3280
  }
3237
3281
 
3282
+ export interface ImageRuleParameters {
3283
+ threshold: number;
3284
+
3285
+ time_window: string;
3286
+
3287
+ harm_labels?: string[];
3288
+ }
3289
+
3238
3290
  export interface ImageSize {
3239
3291
  crop?: 'top' | 'bottom' | 'left' | 'right' | 'center';
3240
3292
 
@@ -4776,45 +4828,71 @@ export interface RingSettingsResponse {
4776
4828
  }
4777
4829
 
4778
4830
  export interface RuleBuilderAction {
4779
- duration?: number;
4831
+ type: string;
4780
4832
 
4781
- ip_ban?: boolean;
4833
+ ban_options?: BanOptions;
4782
4834
 
4783
- reason?: string;
4835
+ flag_content_options?: FlagContentOptions;
4784
4836
 
4785
- shadow_ban?: boolean;
4837
+ flag_user_options?: FlagUserOptions;
4786
4838
 
4787
- type?: string;
4839
+ remove_content_options?: BlockContentOptions;
4788
4840
  }
4789
4841
 
4790
4842
  export interface RuleBuilderCondition {
4791
- provider?: string;
4843
+ type: string;
4792
4844
 
4793
- threshold?: number;
4845
+ confidence?: number;
4794
4846
 
4795
- time_window?: string;
4847
+ content_count_rule_params?: ContentCountRuleParameters;
4796
4848
 
4797
- labels?: string[];
4849
+ image_content_params?: ImageContentParameters;
4850
+
4851
+ image_rule_params?: ImageRuleParameters;
4852
+
4853
+ text_content_params?: TextContentParameters;
4854
+
4855
+ text_rule_params?: TextRuleParameters;
4856
+
4857
+ user_created_within_params?: UserCreatedWithinParameters;
4858
+
4859
+ user_rule_params?: UserRuleParameters;
4860
+
4861
+ video_content_params?: VideoContentParameters;
4862
+
4863
+ video_rule_params?: VideoRuleParameters;
4798
4864
  }
4799
4865
 
4800
- export interface RuleBuilderConfig {
4801
- async?: boolean;
4866
+ export interface RuleBuilderConditionGroup {
4867
+ logic: string;
4802
4868
 
4803
- enabled?: boolean;
4869
+ conditions: RuleBuilderCondition[];
4870
+ }
4804
4871
 
4805
- rules?: RuleBuilderRule[];
4872
+ export interface RuleBuilderConfig {
4873
+ rules: RuleBuilderRule[];
4874
+
4875
+ async?: boolean;
4806
4876
  }
4807
4877
 
4808
4878
  export interface RuleBuilderRule {
4809
- enabled?: boolean;
4879
+ enabled: boolean;
4810
4880
 
4811
- id?: string;
4881
+ id: string;
4812
4882
 
4813
- name?: string;
4883
+ name: string;
4884
+
4885
+ rule_type: string;
4886
+
4887
+ action: RuleBuilderAction;
4888
+
4889
+ cooldown_period?: string;
4890
+
4891
+ logic?: string;
4814
4892
 
4815
4893
  conditions?: RuleBuilderCondition[];
4816
4894
 
4817
- action?: RuleBuilderAction;
4895
+ groups?: RuleBuilderConditionGroup[];
4818
4896
  }
4819
4897
 
4820
4898
  export interface SFUIDLastSeen {
@@ -4954,6 +5032,8 @@ export interface SingleFollowRequest {
4954
5032
 
4955
5033
  target: string;
4956
5034
 
5035
+ create_notification_activity?: boolean;
5036
+
4957
5037
  push_preference?: 'all' | 'none';
4958
5038
 
4959
5039
  custom?: Record<string, any>;
@@ -5026,6 +5106,30 @@ export interface TargetResolution {
5026
5106
  width: number;
5027
5107
  }
5028
5108
 
5109
+ export interface TextContentParameters {
5110
+ contains_url?: boolean;
5111
+
5112
+ severity?: string;
5113
+
5114
+ blocklist_match?: string[];
5115
+
5116
+ harm_labels?: string[];
5117
+ }
5118
+
5119
+ export interface TextRuleParameters {
5120
+ threshold: number;
5121
+
5122
+ time_window: string;
5123
+
5124
+ contains_url?: boolean;
5125
+
5126
+ severity?: string;
5127
+
5128
+ blocklist_match?: string[];
5129
+
5130
+ harm_labels?: string[];
5131
+ }
5132
+
5029
5133
  export interface ThreadedCommentResponse {
5030
5134
  confidence_score: number;
5031
5135
 
@@ -5355,6 +5459,8 @@ export interface UpdateFollowRequest {
5355
5459
 
5356
5460
  target: string;
5357
5461
 
5462
+ create_notification_activity?: boolean;
5463
+
5358
5464
  follower_role?: string;
5359
5465
 
5360
5466
  push_preference?: 'all' | 'none';
@@ -5554,6 +5660,10 @@ export interface UserBannedEvent {
5554
5660
  user?: User;
5555
5661
  }
5556
5662
 
5663
+ export interface UserCreatedWithinParameters {
5664
+ max_age?: string;
5665
+ }
5666
+
5557
5667
  export interface UserDeactivatedEvent {
5558
5668
  created_at: Date;
5559
5669
 
@@ -5736,6 +5846,10 @@ export interface UserResponsePrivacyFields {
5736
5846
  teams_role?: Record<string, string>;
5737
5847
  }
5738
5848
 
5849
+ export interface UserRuleParameters {
5850
+ max_age?: string;
5851
+ }
5852
+
5739
5853
  export interface UserUpdatedEvent {
5740
5854
  created_at: Date;
5741
5855
 
@@ -5798,6 +5912,10 @@ export interface VideoCallRuleConfig {
5798
5912
  rules: Record<string, HarmConfig>;
5799
5913
  }
5800
5914
 
5915
+ export interface VideoContentParameters {
5916
+ harm_labels?: string[];
5917
+ }
5918
+
5801
5919
  export interface VideoEndCallRequest {}
5802
5920
 
5803
5921
  export interface VideoKickUserRequest {}
@@ -5806,6 +5924,14 @@ export interface VideoOrientation {
5806
5924
  orientation?: number;
5807
5925
  }
5808
5926
 
5927
+ export interface VideoRuleParameters {
5928
+ threshold: number;
5929
+
5930
+ time_window: string;
5931
+
5932
+ harm_labels?: string[];
5933
+ }
5934
+
5809
5935
  export interface VideoSettings {
5810
5936
  access_request_enabled: boolean;
5811
5937