@stream-io/feeds-client 0.1.2 → 0.1.3

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.3",
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(