stream-chat 8.38.0 → 8.40.0

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 (42) hide show
  1. package/README.md +15 -2
  2. package/dist/browser.es.js +1667 -372
  3. package/dist/browser.es.js.map +1 -1
  4. package/dist/browser.full-bundle.min.js +1 -1
  5. package/dist/browser.full-bundle.min.js.map +1 -1
  6. package/dist/browser.js +1668 -371
  7. package/dist/browser.js.map +1 -1
  8. package/dist/index.es.js +1667 -372
  9. package/dist/index.es.js.map +1 -1
  10. package/dist/index.js +1668 -371
  11. package/dist/index.js.map +1 -1
  12. package/dist/types/channel.d.ts +6 -8
  13. package/dist/types/channel.d.ts.map +1 -1
  14. package/dist/types/channel_state.d.ts +14 -22
  15. package/dist/types/channel_state.d.ts.map +1 -1
  16. package/dist/types/client.d.ts +3 -1
  17. package/dist/types/client.d.ts.map +1 -1
  18. package/dist/types/constants.d.ts +7 -0
  19. package/dist/types/constants.d.ts.map +1 -0
  20. package/dist/types/index.d.ts +2 -0
  21. package/dist/types/index.d.ts.map +1 -1
  22. package/dist/types/store.d.ts +14 -0
  23. package/dist/types/store.d.ts.map +1 -0
  24. package/dist/types/thread.d.ts +93 -29
  25. package/dist/types/thread.d.ts.map +1 -1
  26. package/dist/types/thread_manager.d.ts +51 -0
  27. package/dist/types/thread_manager.d.ts.map +1 -0
  28. package/dist/types/types.d.ts +35 -18
  29. package/dist/types/types.d.ts.map +1 -1
  30. package/dist/types/utils.d.ts +48 -7
  31. package/dist/types/utils.d.ts.map +1 -1
  32. package/package.json +7 -6
  33. package/src/channel.ts +28 -13
  34. package/src/channel_state.ts +30 -27
  35. package/src/client.ts +182 -104
  36. package/src/constants.ts +4 -0
  37. package/src/index.ts +2 -0
  38. package/src/store.ts +57 -0
  39. package/src/thread.ts +470 -107
  40. package/src/thread_manager.ts +297 -0
  41. package/src/types.ts +34 -19
  42. package/src/utils.ts +362 -43
package/src/client.ts CHANGED
@@ -21,6 +21,7 @@ import {
21
21
  isFunction,
22
22
  isOnline,
23
23
  isOwnUserBaseProperty,
24
+ messageSetPagination,
24
25
  normalizeQuerySort,
25
26
  randomId,
26
27
  retryInterval,
@@ -207,6 +208,8 @@ import {
207
208
  import { InsightMetrics, postInsights } from './insights';
208
209
  import { Thread } from './thread';
209
210
  import { Moderation } from './moderation';
211
+ import { ThreadManager } from './thread_manager';
212
+ import { DEFAULT_QUERY_CHANNELS_MESSAGE_LIST_PAGE_SIZE } from './constants';
210
213
 
211
214
  function isString(x: unknown): x is string {
212
215
  return typeof x === 'string' || x instanceof String;
@@ -219,6 +222,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
219
222
  activeChannels: {
220
223
  [key: string]: Channel<StreamChatGenerics>;
221
224
  };
225
+ threads: ThreadManager<StreamChatGenerics>;
222
226
  anonymous: boolean;
223
227
  persistUserOnConnectionFailure?: boolean;
224
228
  axiosInstance: AxiosInstance;
@@ -338,6 +342,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
338
342
  this.setUserPromise = null;
339
343
  // keeps a reference to all the channels that are in use
340
344
  this.activeChannels = {};
345
+
341
346
  // mapping between channel groups and configs
342
347
  this.configs = {};
343
348
  this.anonymous = false;
@@ -349,8 +354,8 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
349
354
  this.consecutiveFailures = 0;
350
355
  this.insightMetrics = new InsightMetrics();
351
356
 
352
- this.defaultWSTimeoutWithFallback = 6000;
353
- this.defaultWSTimeout = 15000;
357
+ this.defaultWSTimeoutWithFallback = 6 * 1000;
358
+ this.defaultWSTimeout = 15 * 1000;
354
359
 
355
360
  this.axiosInstance.defaults.paramsSerializer = axiosParamsSerializer;
356
361
 
@@ -404,6 +409,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
404
409
  */
405
410
  this.logger = isFunction(inputOptions.logger) ? inputOptions.logger : () => null;
406
411
  this.recoverStateOnReconnect = this.options.recoverStateOnReconnect;
412
+ this.threads = new ThreadManager({ client: this });
407
413
  }
408
414
 
409
415
  /**
@@ -604,7 +610,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
604
610
  tags: ['connection', 'client'],
605
611
  });
606
612
 
607
- return Promise.resolve();
613
+ return;
608
614
  }
609
615
 
610
616
  this.clientID = `${this.userID}--${randomId()}`;
@@ -1601,7 +1607,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
1601
1607
  },
1602
1608
  });
1603
1609
 
1604
- return this.hydrateActiveChannels(data.channels, stateOptions);
1610
+ return this.hydrateActiveChannels(data.channels, stateOptions, options);
1605
1611
  }
1606
1612
 
1607
1613
  /**
@@ -1630,7 +1636,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
1630
1636
  };
1631
1637
 
1632
1638
  return await this.post<QueryReactionsAPIResponse<StreamChatGenerics>>(
1633
- this.baseURL + '/messages/' + messageID + '/reactions',
1639
+ this.baseURL + '/messages/' + encodeURIComponent(messageID) + '/reactions',
1634
1640
  payload,
1635
1641
  );
1636
1642
  }
@@ -1638,26 +1644,38 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
1638
1644
  hydrateActiveChannels(
1639
1645
  channelsFromApi: ChannelAPIResponse<StreamChatGenerics>[] = [],
1640
1646
  stateOptions: ChannelStateOptions = {},
1647
+ queryChannelsOptions?: ChannelOptions,
1641
1648
  ) {
1642
1649
  const { skipInitialization, offlineMode = false } = stateOptions;
1643
-
1644
- for (const channelState of channelsFromApi) {
1645
- this._addChannelConfig(channelState.channel);
1646
- }
1647
-
1648
1650
  const channels: Channel<StreamChatGenerics>[] = [];
1649
1651
 
1650
1652
  for (const channelState of channelsFromApi) {
1653
+ this._addChannelConfig(channelState.channel);
1651
1654
  const c = this.channel(channelState.channel.type, channelState.channel.id);
1652
1655
  c.data = channelState.channel;
1653
1656
  c.offlineMode = offlineMode;
1654
1657
  c.initialized = !offlineMode;
1655
1658
 
1659
+ let updatedMessagesSet;
1656
1660
  if (skipInitialization === undefined) {
1657
- c._initializeState(channelState, 'latest');
1661
+ const { messageSet } = c._initializeState(channelState, 'latest');
1662
+ updatedMessagesSet = messageSet;
1658
1663
  } else if (!skipInitialization.includes(channelState.channel.id)) {
1659
1664
  c.state.clearMessages();
1660
- c._initializeState(channelState, 'latest');
1665
+ const { messageSet } = c._initializeState(channelState, 'latest');
1666
+ updatedMessagesSet = messageSet;
1667
+ }
1668
+
1669
+ if (updatedMessagesSet) {
1670
+ updatedMessagesSet.pagination = {
1671
+ ...updatedMessagesSet.pagination,
1672
+ ...messageSetPagination({
1673
+ parentSet: updatedMessagesSet,
1674
+ requestedPageSize: queryChannelsOptions?.message_limit || DEFAULT_QUERY_CHANNELS_MESSAGE_LIST_PAGE_SIZE,
1675
+ returnedPage: channelState.messages,
1676
+ logger: this.logger,
1677
+ }),
1678
+ };
1661
1679
  }
1662
1680
 
1663
1681
  channels.push(c);
@@ -2063,7 +2081,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2063
2081
  APIResponse & { user: UserResponse<StreamChatGenerics> } & {
2064
2082
  task_id?: string;
2065
2083
  }
2066
- >(this.baseURL + `/users/${userID}`, params);
2084
+ >(this.baseURL + `/users/${encodeURIComponent(userID)}`, params);
2067
2085
  }
2068
2086
 
2069
2087
  /**
@@ -2089,7 +2107,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2089
2107
  */
2090
2108
  async reactivateUser(userID: string, options?: ReactivateUserOptions) {
2091
2109
  return await this.post<APIResponse & { user: UserResponse<StreamChatGenerics> }>(
2092
- this.baseURL + `/users/${userID}/reactivate`,
2110
+ this.baseURL + `/users/${encodeURIComponent(userID)}/reactivate`,
2093
2111
  { ...options },
2094
2112
  );
2095
2113
  }
@@ -2116,7 +2134,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2116
2134
  */
2117
2135
  async deactivateUser(userID: string, options?: DeactivateUsersOptions) {
2118
2136
  return await this.post<APIResponse & { user: UserResponse<StreamChatGenerics> }>(
2119
- this.baseURL + `/users/${userID}/deactivate`,
2137
+ this.baseURL + `/users/${encodeURIComponent(userID)}/deactivate`,
2120
2138
  { ...options },
2121
2139
  );
2122
2140
  }
@@ -2140,7 +2158,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2140
2158
  reactions: ReactionResponse<StreamChatGenerics>[];
2141
2159
  user: UserResponse<StreamChatGenerics>;
2142
2160
  }
2143
- >(this.baseURL + `/users/${userID}/export`, { ...options });
2161
+ >(this.baseURL + `/users/${encodeURIComponent(userID)}/export`, { ...options });
2144
2162
  }
2145
2163
 
2146
2164
  /** banUser - bans a user from all channels
@@ -2316,7 +2334,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2316
2334
  * @returns {Promise<GetCallTokenResponse>}
2317
2335
  */
2318
2336
  async getCallToken(callID: string, options: { user_id?: string } = {}) {
2319
- return await this.post<GetCallTokenResponse>(this.baseURL + `/calls/${callID}`, { ...options });
2337
+ return await this.post<GetCallTokenResponse>(this.baseURL + `/calls/${encodeURIComponent(callID)}`, { ...options });
2320
2338
  }
2321
2339
 
2322
2340
  /**
@@ -2376,10 +2394,13 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2376
2394
  * @returns {Promise<ReviewFlagReportResponse>>}
2377
2395
  */
2378
2396
  async _reviewFlagReport(id: string, reviewResult: string, options: ReviewFlagReportOptions = {}) {
2379
- return await this.patch<ReviewFlagReportResponse<StreamChatGenerics>>(this.baseURL + `/moderation/reports/${id}`, {
2380
- review_result: reviewResult,
2381
- ...options,
2382
- });
2397
+ return await this.patch<ReviewFlagReportResponse<StreamChatGenerics>>(
2398
+ this.baseURL + `/moderation/reports/${encodeURIComponent(id)}`,
2399
+ {
2400
+ review_result: reviewResult,
2401
+ ...options,
2402
+ },
2403
+ );
2383
2404
  }
2384
2405
 
2385
2406
  /**
@@ -2426,15 +2447,20 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2426
2447
  }
2427
2448
 
2428
2449
  getCommand(name: string) {
2429
- return this.get<GetCommandResponse<StreamChatGenerics>>(this.baseURL + `/commands/${name}`);
2450
+ return this.get<GetCommandResponse<StreamChatGenerics>>(this.baseURL + `/commands/${encodeURIComponent(name)}`);
2430
2451
  }
2431
2452
 
2432
2453
  updateCommand(name: string, data: UpdateCommandOptions<StreamChatGenerics>) {
2433
- return this.put<UpdateCommandResponse<StreamChatGenerics>>(this.baseURL + `/commands/${name}`, data);
2454
+ return this.put<UpdateCommandResponse<StreamChatGenerics>>(
2455
+ this.baseURL + `/commands/${encodeURIComponent(name)}`,
2456
+ data,
2457
+ );
2434
2458
  }
2435
2459
 
2436
2460
  deleteCommand(name: string) {
2437
- return this.delete<DeleteCommandResponse<StreamChatGenerics>>(this.baseURL + `/commands/${name}`);
2461
+ return this.delete<DeleteCommandResponse<StreamChatGenerics>>(
2462
+ this.baseURL + `/commands/${encodeURIComponent(name)}`,
2463
+ );
2438
2464
  }
2439
2465
 
2440
2466
  listCommands() {
@@ -2447,15 +2473,20 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2447
2473
  }
2448
2474
 
2449
2475
  getChannelType(channelType: string) {
2450
- return this.get<GetChannelTypeResponse<StreamChatGenerics>>(this.baseURL + `/channeltypes/${channelType}`);
2476
+ return this.get<GetChannelTypeResponse<StreamChatGenerics>>(
2477
+ this.baseURL + `/channeltypes/${encodeURIComponent(channelType)}`,
2478
+ );
2451
2479
  }
2452
2480
 
2453
2481
  updateChannelType(channelType: string, data: UpdateChannelOptions<StreamChatGenerics>) {
2454
- return this.put<UpdateChannelResponse<StreamChatGenerics>>(this.baseURL + `/channeltypes/${channelType}`, data);
2482
+ return this.put<UpdateChannelResponse<StreamChatGenerics>>(
2483
+ this.baseURL + `/channeltypes/${encodeURIComponent(channelType)}`,
2484
+ data,
2485
+ );
2455
2486
  }
2456
2487
 
2457
2488
  deleteChannelType(channelType: string) {
2458
- return this.delete<APIResponse>(this.baseURL + `/channeltypes/${channelType}`);
2489
+ return this.delete<APIResponse>(this.baseURL + `/channeltypes/${encodeURIComponent(channelType)}`);
2459
2490
  }
2460
2491
 
2461
2492
  listChannelTypes() {
@@ -2472,7 +2503,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2472
2503
  */
2473
2504
  async translateMessage(messageId: string, language: string) {
2474
2505
  return await this.post<APIResponse & MessageResponse<StreamChatGenerics>>(
2475
- this.baseURL + `/messages/${messageId}/translate`,
2506
+ this.baseURL + `/messages/${encodeURIComponent(messageId)}/translate`,
2476
2507
  { language },
2477
2508
  );
2478
2509
  }
@@ -2622,10 +2653,13 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2622
2653
  clonedMessage.mentioned_users = clonedMessage.mentioned_users.map((mu) => ((mu as unknown) as UserResponse).id);
2623
2654
  }
2624
2655
 
2625
- return await this.post<UpdateMessageAPIResponse<StreamChatGenerics>>(this.baseURL + `/messages/${message.id}`, {
2626
- message: clonedMessage,
2627
- ...options,
2628
- });
2656
+ return await this.post<UpdateMessageAPIResponse<StreamChatGenerics>>(
2657
+ this.baseURL + `/messages/${encodeURIComponent(message.id as string)}`,
2658
+ {
2659
+ message: clonedMessage,
2660
+ ...options,
2661
+ },
2662
+ );
2629
2663
  }
2630
2664
 
2631
2665
  /**
@@ -2654,11 +2688,14 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2654
2688
  if (userId != null && isString(userId)) {
2655
2689
  user = { id: userId };
2656
2690
  }
2657
- return await this.put<UpdateMessageAPIResponse<StreamChatGenerics>>(this.baseURL + `/messages/${id}`, {
2658
- ...partialMessageObject,
2659
- ...options,
2660
- user,
2661
- });
2691
+ return await this.put<UpdateMessageAPIResponse<StreamChatGenerics>>(
2692
+ this.baseURL + `/messages/${encodeURIComponent(id)}`,
2693
+ {
2694
+ ...partialMessageObject,
2695
+ ...options,
2696
+ user,
2697
+ },
2698
+ );
2662
2699
  }
2663
2700
 
2664
2701
  async deleteMessage(messageID: string, hardDelete?: boolean) {
@@ -2667,7 +2704,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2667
2704
  params = { hard: true };
2668
2705
  }
2669
2706
  return await this.delete<APIResponse & { message: MessageResponse<StreamChatGenerics> }>(
2670
- this.baseURL + `/messages/${messageID}`,
2707
+ this.baseURL + `/messages/${encodeURIComponent(messageID)}`,
2671
2708
  params,
2672
2709
  );
2673
2710
  }
@@ -2686,7 +2723,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2686
2723
  */
2687
2724
  async undeleteMessage(messageID: string, userID: string) {
2688
2725
  return await this.post<APIResponse & { message: MessageResponse<StreamChatGenerics> }>(
2689
- this.baseURL + `/messages/${messageID}/undelete`,
2726
+ this.baseURL + `/messages/${encodeURIComponent(messageID)}/undelete`,
2690
2727
  { undeleted_by: userID },
2691
2728
  );
2692
2729
  }
@@ -2721,7 +2758,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2721
2758
  const res = await this.post<QueryThreadsAPIResponse<StreamChatGenerics>>(this.baseURL + `/threads`, opts);
2722
2759
 
2723
2760
  return {
2724
- threads: res.threads.map((thread) => new Thread(this, thread)),
2761
+ threads: res.threads.map((thread) => new Thread({ client: this, threadData: thread })),
2725
2762
  next: res.next,
2726
2763
  };
2727
2764
  }
@@ -2749,9 +2786,12 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2749
2786
  ...options,
2750
2787
  };
2751
2788
 
2752
- const res = await this.get<GetThreadAPIResponse<StreamChatGenerics>>(this.baseURL + `/threads/${messageId}`, opts);
2789
+ const res = await this.get<GetThreadAPIResponse<StreamChatGenerics>>(
2790
+ this.baseURL + `/threads/${encodeURIComponent(messageId)}`,
2791
+ opts,
2792
+ );
2753
2793
 
2754
- return new Thread<StreamChatGenerics>(this, res.thread);
2794
+ return new Thread<StreamChatGenerics>({ client: this, threadData: res.thread });
2755
2795
  }
2756
2796
 
2757
2797
  /**
@@ -2790,7 +2830,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2790
2830
  }
2791
2831
 
2792
2832
  return await this.patch<GetThreadAPIResponse<StreamChatGenerics>>(
2793
- this.baseURL + `/threads/${messageId}`,
2833
+ this.baseURL + `/threads/${encodeURIComponent(messageId)}`,
2794
2834
  partialThreadObject,
2795
2835
  );
2796
2836
  }
@@ -2905,7 +2945,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2905
2945
  * @returns {Promise<PermissionAPIResponse>}
2906
2946
  */
2907
2947
  getPermission(name: string) {
2908
- return this.get<PermissionAPIResponse>(`${this.baseURL}/permissions/${name}`);
2948
+ return this.get<PermissionAPIResponse>(`${this.baseURL}/permissions/${encodeURIComponent(name)}`);
2909
2949
  }
2910
2950
 
2911
2951
  /** createPermission - creates a custom permission
@@ -2926,7 +2966,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2926
2966
  * @returns {Promise<APIResponse>}
2927
2967
  */
2928
2968
  updatePermission(id: string, permissionData: Omit<CustomPermissionOptions, 'id'>) {
2929
- return this.put<APIResponse>(`${this.baseURL}/permissions/${id}`, {
2969
+ return this.put<APIResponse>(`${this.baseURL}/permissions/${encodeURIComponent(id)}`, {
2930
2970
  ...permissionData,
2931
2971
  });
2932
2972
  }
@@ -2937,7 +2977,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2937
2977
  * @returns {Promise<APIResponse>}
2938
2978
  */
2939
2979
  deletePermission(name: string) {
2940
- return this.delete<APIResponse>(`${this.baseURL}/permissions/${name}`);
2980
+ return this.delete<APIResponse>(`${this.baseURL}/permissions/${encodeURIComponent(name)}`);
2941
2981
  }
2942
2982
 
2943
2983
  /** listPermissions - returns the list of all permissions for this application
@@ -2971,7 +3011,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2971
3011
  * @returns {Promise<APIResponse>}
2972
3012
  */
2973
3013
  deleteRole(name: string) {
2974
- return this.delete<APIResponse>(`${this.baseURL}/roles/${name}`);
3014
+ return this.delete<APIResponse>(`${this.baseURL}/roles/${encodeURIComponent(name)}`);
2975
3015
  }
2976
3016
 
2977
3017
  /** sync - returns all events that happened for a list of channels since last sync
@@ -2998,7 +3038,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
2998
3038
  * @return {Promise<APIResponse>} The Server Response
2999
3039
  */
3000
3040
  async sendUserCustomEvent(targetUserID: string, event: UserCustomEvent) {
3001
- return await this.post<APIResponse>(`${this.baseURL}/users/${targetUserID}/event`, {
3041
+ return await this.post<APIResponse>(`${this.baseURL}/users/${encodeURIComponent(targetUserID)}/event`, {
3002
3042
  event,
3003
3043
  });
3004
3044
  }
@@ -3012,15 +3052,17 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3012
3052
  }
3013
3053
 
3014
3054
  getBlockList(name: string) {
3015
- return this.get<APIResponse & { blocklist: BlockListResponse }>(`${this.baseURL}/blocklists/${name}`);
3055
+ return this.get<APIResponse & { blocklist: BlockListResponse }>(
3056
+ `${this.baseURL}/blocklists/${encodeURIComponent(name)}`,
3057
+ );
3016
3058
  }
3017
3059
 
3018
3060
  updateBlockList(name: string, data: { words: string[] }) {
3019
- return this.put<APIResponse>(`${this.baseURL}/blocklists/${name}`, data);
3061
+ return this.put<APIResponse>(`${this.baseURL}/blocklists/${encodeURIComponent(name)}`, data);
3020
3062
  }
3021
3063
 
3022
3064
  deleteBlockList(name: string) {
3023
- return this.delete<APIResponse>(`${this.baseURL}/blocklists/${name}`);
3065
+ return this.delete<APIResponse>(`${this.baseURL}/blocklists/${encodeURIComponent(name)}`);
3024
3066
  }
3025
3067
 
3026
3068
  exportChannels(request: Array<ExportChannelRequest>, options: ExportChannelOptions = {}) {
@@ -3037,7 +3079,9 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3037
3079
  }
3038
3080
 
3039
3081
  getExportChannelStatus(id: string) {
3040
- return this.get<APIResponse & ExportChannelStatusResponse>(`${this.baseURL}/export_channels/${id}`);
3082
+ return this.get<APIResponse & ExportChannelStatusResponse>(
3083
+ `${this.baseURL}/export_channels/${encodeURIComponent(id)}`,
3084
+ );
3041
3085
  }
3042
3086
 
3043
3087
  campaign(idOrData: string | CampaignData, data?: CampaignData) {
@@ -3115,7 +3159,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3115
3159
 
3116
3160
  async getSegment(id: string) {
3117
3161
  this.validateServerSideAuth();
3118
- return this.get<{ segment: SegmentResponse } & APIResponse>(this.baseURL + `/segments/${id}`);
3162
+ return this.get<{ segment: SegmentResponse } & APIResponse>(this.baseURL + `/segments/${encodeURIComponent(id)}`);
3119
3163
  }
3120
3164
 
3121
3165
  /**
@@ -3128,7 +3172,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3128
3172
  */
3129
3173
  async updateSegment(id: string, data: Partial<UpdateSegmentData>) {
3130
3174
  this.validateServerSideAuth();
3131
- return this.put<{ segment: SegmentResponse }>(this.baseURL + `/segments/${id}`, data);
3175
+ return this.put<{ segment: SegmentResponse }>(this.baseURL + `/segments/${encodeURIComponent(id)}`, data);
3132
3176
  }
3133
3177
 
3134
3178
  /**
@@ -3142,7 +3186,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3142
3186
  async addSegmentTargets(id: string, targets: string[]) {
3143
3187
  this.validateServerSideAuth();
3144
3188
  const body = { target_ids: targets };
3145
- return this.post<APIResponse>(this.baseURL + `/segments/${id}/addtargets`, body);
3189
+ return this.post<APIResponse>(this.baseURL + `/segments/${encodeURIComponent(id)}/addtargets`, body);
3146
3190
  }
3147
3191
 
3148
3192
  async querySegmentTargets(
@@ -3153,7 +3197,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3153
3197
  ) {
3154
3198
  this.validateServerSideAuth();
3155
3199
  return this.post<{ targets: SegmentTargetsResponse[]; next?: string } & APIResponse>(
3156
- this.baseURL + `/segments/${id}/targets/query`,
3200
+ this.baseURL + `/segments/${encodeURIComponent(id)}/targets/query`,
3157
3201
  {
3158
3202
  filter: filter || {},
3159
3203
  sort: sort || [],
@@ -3172,7 +3216,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3172
3216
  async removeSegmentTargets(id: string, targets: string[]) {
3173
3217
  this.validateServerSideAuth();
3174
3218
  const body = { target_ids: targets };
3175
- return this.post<APIResponse>(this.baseURL + `/segments/${id}/deletetargets`, body);
3219
+ return this.post<APIResponse>(this.baseURL + `/segments/${encodeURIComponent(id)}/deletetargets`, body);
3176
3220
  }
3177
3221
 
3178
3222
  /**
@@ -3207,7 +3251,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3207
3251
  */
3208
3252
  async deleteSegment(id: string) {
3209
3253
  this.validateServerSideAuth();
3210
- return this.delete<APIResponse>(this.baseURL + `/segments/${id}`);
3254
+ return this.delete<APIResponse>(this.baseURL + `/segments/${encodeURIComponent(id)}`);
3211
3255
  }
3212
3256
 
3213
3257
  /**
@@ -3220,7 +3264,9 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3220
3264
  */
3221
3265
  async segmentTargetExists(segmentId: string, targetId: string) {
3222
3266
  this.validateServerSideAuth();
3223
- return this.get<APIResponse>(this.baseURL + `/segments/${segmentId}/target/${targetId}`);
3267
+ return this.get<APIResponse>(
3268
+ this.baseURL + `/segments/${encodeURIComponent(segmentId)}/target/${encodeURIComponent(targetId)}`,
3269
+ );
3224
3270
  }
3225
3271
 
3226
3272
  /**
@@ -3237,15 +3283,20 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3237
3283
 
3238
3284
  async getCampaign(id: string) {
3239
3285
  this.validateServerSideAuth();
3240
- return this.get<{ campaign: CampaignResponse } & APIResponse>(this.baseURL + `/campaigns/${id}`);
3286
+ return this.get<{ campaign: CampaignResponse } & APIResponse>(
3287
+ this.baseURL + `/campaigns/${encodeURIComponent(id)}`,
3288
+ );
3241
3289
  }
3242
3290
 
3243
3291
  async startCampaign(id: string, options?: { scheduledFor?: string; stopAt?: string }) {
3244
3292
  this.validateServerSideAuth();
3245
- return this.post<{ campaign: CampaignResponse } & APIResponse>(this.baseURL + `/campaigns/${id}/start`, {
3246
- scheduled_for: options?.scheduledFor,
3247
- stop_at: options?.stopAt,
3248
- });
3293
+ return this.post<{ campaign: CampaignResponse } & APIResponse>(
3294
+ this.baseURL + `/campaigns/${encodeURIComponent(id)}/start`,
3295
+ {
3296
+ scheduled_for: options?.scheduledFor,
3297
+ stop_at: options?.stopAt,
3298
+ },
3299
+ );
3249
3300
  }
3250
3301
  /**
3251
3302
  * queryCampaigns - Query Campaigns
@@ -3278,7 +3329,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3278
3329
  */
3279
3330
  async updateCampaign(id: string, params: Partial<CampaignData>) {
3280
3331
  this.validateServerSideAuth();
3281
- return this.put<{ campaign: CampaignResponse }>(this.baseURL + `/campaigns/${id}`, params);
3332
+ return this.put<{ campaign: CampaignResponse }>(this.baseURL + `/campaigns/${encodeURIComponent(id)}`, params);
3282
3333
  }
3283
3334
 
3284
3335
  /**
@@ -3290,7 +3341,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3290
3341
  */
3291
3342
  async deleteCampaign(id: string) {
3292
3343
  this.validateServerSideAuth();
3293
- return this.delete<APIResponse>(this.baseURL + `/campaigns/${id}`);
3344
+ return this.delete<APIResponse>(this.baseURL + `/campaigns/${encodeURIComponent(id)}`);
3294
3345
  }
3295
3346
 
3296
3347
  /**
@@ -3302,7 +3353,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3302
3353
  */
3303
3354
  async stopCampaign(id: string) {
3304
3355
  this.validateServerSideAuth();
3305
- return this.post<{ campaign: CampaignResponse }>(this.baseURL + `/campaigns/${id}/stop`);
3356
+ return this.post<{ campaign: CampaignResponse }>(this.baseURL + `/campaigns/${encodeURIComponent(id)}/stop`);
3306
3357
  }
3307
3358
 
3308
3359
  /**
@@ -3323,7 +3374,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3323
3374
  * @return {TaskStatus} The task status
3324
3375
  */
3325
3376
  async getTask(id: string) {
3326
- return this.get<APIResponse & TaskStatus>(`${this.baseURL}/tasks/${id}`);
3377
+ return this.get<APIResponse & TaskStatus>(`${this.baseURL}/tasks/${encodeURIComponent(id)}`);
3327
3378
  }
3328
3379
 
3329
3380
  /**
@@ -3414,7 +3465,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3414
3465
  * @return {APIResponse & GetImportResponse} An ImportTask
3415
3466
  */
3416
3467
  async _getImport(id: string) {
3417
- return await this.get<APIResponse & GetImportResponse>(this.baseURL + `/imports/${id}`);
3468
+ return await this.get<APIResponse & GetImportResponse>(this.baseURL + `/imports/${encodeURIComponent(id)}`);
3418
3469
  }
3419
3470
 
3420
3471
  /**
@@ -3458,7 +3509,9 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3458
3509
  * @return {APIResponse} An API response
3459
3510
  */
3460
3511
  async deletePushProvider({ type, name }: PushProviderID) {
3461
- return await this.delete<APIResponse>(this.baseURL + `/push_providers/${type}/${name}`);
3512
+ return await this.delete<APIResponse>(
3513
+ this.baseURL + `/push_providers/${encodeURIComponent(type)}/${encodeURIComponent(name)}`,
3514
+ );
3462
3515
  }
3463
3516
 
3464
3517
  /**
@@ -3486,7 +3539,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3486
3539
  * @return {APIResponse & MessageResponse} The message
3487
3540
  */
3488
3541
  async commitMessage(id: string) {
3489
- return await this.post<APIResponse & MessageResponse>(this.baseURL + `/messages/${id}/commit`);
3542
+ return await this.post<APIResponse & MessageResponse>(this.baseURL + `/messages/${encodeURIComponent(id)}/commit`);
3490
3543
  }
3491
3544
 
3492
3545
  /**
@@ -3509,8 +3562,9 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3509
3562
  * @returns {APIResponse & GetPollAPIResponse} The poll
3510
3563
  */
3511
3564
  async getPoll(id: string, userId?: string): Promise<APIResponse & GetPollAPIResponse> {
3512
- return await this.get<APIResponse & GetPollAPIResponse>(this.baseURL + `/polls/${id}`,
3513
- userId ? { user_id: userId } : {}
3565
+ return await this.get<APIResponse & GetPollAPIResponse>(
3566
+ this.baseURL + `/polls/${encodeURIComponent(id)}`,
3567
+ userId ? { user_id: userId } : {},
3514
3568
  );
3515
3569
  }
3516
3570
 
@@ -3523,7 +3577,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3523
3577
  async updatePoll(poll: PollData, userId?: string) {
3524
3578
  return await this.put<APIResponse & UpdatePollAPIResponse>(this.baseURL + `/polls`, {
3525
3579
  ...poll,
3526
- ...(userId ? { user_id: userId } : {})
3580
+ ...(userId ? { user_id: userId } : {}),
3527
3581
  });
3528
3582
  }
3529
3583
 
@@ -3538,11 +3592,11 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3538
3592
  async partialUpdatePoll(
3539
3593
  id: string,
3540
3594
  partialPollObject: PartialPollUpdate,
3541
- userId?: string
3595
+ userId?: string,
3542
3596
  ): Promise<APIResponse & UpdatePollAPIResponse> {
3543
- return await this.patch<APIResponse & UpdatePollAPIResponse>(this.baseURL + `/polls/${id}`, {
3597
+ return await this.patch<APIResponse & UpdatePollAPIResponse>(this.baseURL + `/polls/${encodeURIComponent(id)}`, {
3544
3598
  ...partialPollObject,
3545
- ...(userId ? { user_id: userId } : {})
3599
+ ...(userId ? { user_id: userId } : {}),
3546
3600
  });
3547
3601
  }
3548
3602
 
@@ -3553,7 +3607,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3553
3607
  * @returns
3554
3608
  */
3555
3609
  async deletePoll(id: string, userId?: string): Promise<APIResponse> {
3556
- return await this.delete<APIResponse>(this.baseURL + `/polls/${id}`, {
3610
+ return await this.delete<APIResponse>(this.baseURL + `/polls/${encodeURIComponent(id)}`, {
3557
3611
  ...(userId ? { user_id: userId } : {}),
3558
3612
  });
3559
3613
  }
@@ -3569,7 +3623,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3569
3623
  set: {
3570
3624
  is_closed: true,
3571
3625
  },
3572
- ...(userId ? { user_id: userId } : {})
3626
+ ...(userId ? { user_id: userId } : {}),
3573
3627
  });
3574
3628
  }
3575
3629
 
@@ -3582,10 +3636,12 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3582
3636
  */
3583
3637
  async createPollOption(pollId: string, option: PollOptionData, userId?: string) {
3584
3638
  return await this.post<APIResponse & CreatePollOptionAPIResponse>(
3585
- this.baseURL + `/polls/${pollId}/options`, {
3639
+ this.baseURL + `/polls/${encodeURIComponent(pollId)}/options`,
3640
+ {
3586
3641
  ...option,
3587
- ...(userId ? { user_id: userId } : {})
3588
- });
3642
+ ...(userId ? { user_id: userId } : {}),
3643
+ },
3644
+ );
3589
3645
  }
3590
3646
 
3591
3647
  /**
@@ -3597,7 +3653,9 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3597
3653
  */
3598
3654
  async getPollOption(pollId: string, optionId: string, userId?: string) {
3599
3655
  return await this.get<APIResponse & GetPollOptionAPIResponse>(
3600
- this.baseURL + `/polls/${pollId}/options/${optionId}`, userId ? { user_id: userId } : {});
3656
+ this.baseURL + `/polls/${encodeURIComponent(pollId)}/options/${encodeURIComponent(optionId)}`,
3657
+ userId ? { user_id: userId } : {},
3658
+ );
3601
3659
  }
3602
3660
 
3603
3661
  /**
@@ -3608,10 +3666,13 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3608
3666
  * @returns
3609
3667
  */
3610
3668
  async updatePollOption(pollId: string, option: PollOptionData, userId?: string) {
3611
- return await this.put<APIResponse & UpdatePollOptionAPIResponse>(this.baseURL + `/polls/${pollId}/options`, {
3612
- ...option,
3613
- ...(userId ? { user_id: userId } : {}),
3614
- });
3669
+ return await this.put<APIResponse & UpdatePollOptionAPIResponse>(
3670
+ this.baseURL + `/polls/${encodeURIComponent(pollId)}/options`,
3671
+ {
3672
+ ...option,
3673
+ ...(userId ? { user_id: userId } : {}),
3674
+ },
3675
+ );
3615
3676
  }
3616
3677
 
3617
3678
  /**
@@ -3622,7 +3683,10 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3622
3683
  * @returns {APIResponse} The poll option
3623
3684
  */
3624
3685
  async deletePollOption(pollId: string, optionId: string, userId?: string) {
3625
- return await this.delete<APIResponse>(this.baseURL + `/polls/${pollId}/options/${optionId}`, userId ? { user_id: userId } : {});
3686
+ return await this.delete<APIResponse>(
3687
+ this.baseURL + `/polls/${encodeURIComponent(pollId)}/options/${encodeURIComponent(optionId)}`,
3688
+ userId ? { user_id: userId } : {},
3689
+ );
3626
3690
  }
3627
3691
 
3628
3692
  /**
@@ -3635,7 +3699,8 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3635
3699
  */
3636
3700
  async castPollVote(messageId: string, pollId: string, vote: PollVoteData, userId?: string) {
3637
3701
  return await this.post<APIResponse & CastVoteAPIResponse>(
3638
- this.baseURL + `/messages/${messageId}/polls/${pollId}/vote`, {
3702
+ this.baseURL + `/messages/${encodeURIComponent(messageId)}/polls/${encodeURIComponent(pollId)}/vote`,
3703
+ {
3639
3704
  vote,
3640
3705
  ...(userId ? { user_id: userId } : {}),
3641
3706
  },
@@ -3650,16 +3715,26 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3650
3715
  * @param userId string The user id (only serverside)
3651
3716
  */
3652
3717
  async addPollAnswer(messageId: string, pollId: string, answerText: string, userId?: string) {
3653
- return this.castPollVote(messageId, pollId, {
3654
- answer_text: answerText,
3655
- }, userId);
3718
+ return this.castPollVote(
3719
+ messageId,
3720
+ pollId,
3721
+ {
3722
+ answer_text: answerText,
3723
+ },
3724
+ userId,
3725
+ );
3656
3726
  }
3657
3727
 
3658
3728
  async removePollVote(messageId: string, pollId: string, voteId: string, userId?: string) {
3659
3729
  return await this.delete<APIResponse & { vote: PollVote }>(
3660
- this.baseURL + `/messages/${messageId}/polls/${pollId}/vote/${voteId}`, {
3661
- ...(userId ? { user_id: userId } : {}),
3662
- });
3730
+ this.baseURL +
3731
+ `/messages/${encodeURIComponent(messageId)}/polls/${encodeURIComponent(pollId)}/vote/${encodeURIComponent(
3732
+ voteId,
3733
+ )}`,
3734
+ {
3735
+ ...(userId ? { user_id: userId } : {}),
3736
+ },
3737
+ );
3663
3738
  }
3664
3739
 
3665
3740
  /**
@@ -3674,9 +3749,9 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3674
3749
  filter: QueryPollsFilters = {},
3675
3750
  sort: PollSort = [],
3676
3751
  options: QueryPollsOptions = {},
3677
- userId?: string
3752
+ userId?: string,
3678
3753
  ): Promise<APIResponse & QueryPollsResponse> {
3679
- const q = userId ? `?user_id=${userId}` : '';
3754
+ const q = userId ? `?user_id=${userId}` : '';
3680
3755
  return await this.post<APIResponse & QueryPollsResponse>(this.baseURL + `/polls/query${q}`, {
3681
3756
  filter,
3682
3757
  sort: normalizeQuerySort(sort),
@@ -3698,14 +3773,17 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
3698
3773
  filter: QueryVotesFilters = {},
3699
3774
  sort: VoteSort = [],
3700
3775
  options: QueryVotesOptions = {},
3701
- userId?: string
3776
+ userId?: string,
3702
3777
  ): Promise<APIResponse & PollVotesAPIResponse> {
3703
- const q = userId ? `?user_id=${userId}` : '';
3704
- return await this.post<APIResponse & PollVotesAPIResponse>(this.baseURL + `/polls/${pollId}/votes${q}`, {
3705
- filter,
3706
- sort: normalizeQuerySort(sort),
3707
- ...options,
3708
- });
3778
+ const q = userId ? `?user_id=${userId}` : '';
3779
+ return await this.post<APIResponse & PollVotesAPIResponse>(
3780
+ this.baseURL + `/polls/${encodeURIComponent(pollId)}/votes${q}`,
3781
+ {
3782
+ filter,
3783
+ sort: normalizeQuerySort(sort),
3784
+ ...options,
3785
+ },
3786
+ );
3709
3787
  }
3710
3788
 
3711
3789
  /**