stream-chat 9.27.2 → 9.29.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.
package/src/client.ts CHANGED
@@ -13,6 +13,7 @@ import { CheckSignature, DevToken, JWTUserToken } from './signing';
13
13
  import { TokenManager } from './token_manager';
14
14
  import { WSConnectionFallback } from './connection_fallback';
15
15
  import { Campaign } from './campaign';
16
+ import { ChannelBatchUpdater } from './channel_batch_updater';
16
17
  import { Segment } from './segment';
17
18
  import { isErrorResponse, isWSFailure } from './errors';
18
19
  import {
@@ -75,6 +76,7 @@ import type {
75
76
  CreatePollAPIResponse,
76
77
  CreatePollData,
77
78
  CreatePollOptionAPIResponse,
79
+ CreatePredefinedFilterOptions,
78
80
  CreateReminderOptions,
79
81
  CustomPermissionOptions,
80
82
  DeactivateUsersOptions,
@@ -104,6 +106,7 @@ import type {
104
106
  FlagsPaginationOptions,
105
107
  FlagsResponse,
106
108
  FlagUserResponse,
109
+ FutureChannelBansResponse,
107
110
  GetBlockedUsersAPIResponse,
108
111
  GetCampaignOptions,
109
112
  GetChannelTypeResponse,
@@ -123,6 +126,8 @@ import type {
123
126
  ListCommandsResponse,
124
127
  ListImportsPaginationOptions,
125
128
  ListImportsResponse,
129
+ ListPredefinedFiltersOptions,
130
+ ListPredefinedFiltersResponse,
126
131
  LocalMessage,
127
132
  Logger,
128
133
  MarkChannelsReadOptions,
@@ -152,6 +157,7 @@ import type {
152
157
  PollVote,
153
158
  PollVoteData,
154
159
  PollVotesAPIResponse,
160
+ PredefinedFilterResponse,
155
161
  Product,
156
162
  PushPreference,
157
163
  PushProvider,
@@ -161,6 +167,7 @@ import type {
161
167
  PushProviderUpsertResponse,
162
168
  QueryChannelsAPIResponse,
163
169
  QueryDraftsResponse,
170
+ QueryFutureChannelBansOptions,
164
171
  QueryMessageHistoryFilters,
165
172
  QueryMessageHistoryOptions,
166
173
  QueryMessageHistoryResponse,
@@ -209,6 +216,8 @@ import type {
209
216
  TokenOrProvider,
210
217
  TranslateResponse,
211
218
  UnBanUserOptions,
219
+ UpdateChannelsBatchOptions,
220
+ UpdateChannelsBatchResponse,
212
221
  UpdateChannelTypeRequest,
213
222
  UpdateChannelTypeResponse,
214
223
  UpdateCommandOptions,
@@ -218,6 +227,7 @@ import type {
218
227
  UpdateMessageOptions,
219
228
  UpdatePollAPIResponse,
220
229
  UpdatePollOptionAPIResponse,
230
+ UpdatePredefinedFilterOptions,
221
231
  UpdateReminderOptions,
222
232
  UpdateSegmentData,
223
233
  UpdateUsersAPIResponse,
@@ -1814,6 +1824,21 @@ export class StreamChat {
1814
1824
  });
1815
1825
  }
1816
1826
 
1827
+ /**
1828
+ * queryFutureChannelBans - Query future channel bans created by a user
1829
+ *
1830
+ * @param {QueryFutureChannelBansOptions} options Option object with user_id, exclude_expired_bans, limit, offset
1831
+ * @returns {Promise<FutureChannelBansResponse>} Future Channel Bans Response
1832
+ */
1833
+ async queryFutureChannelBans(options: QueryFutureChannelBansOptions = {}) {
1834
+ return await this.get<FutureChannelBansResponse>(
1835
+ this.baseURL + '/query_future_channel_bans',
1836
+ {
1837
+ payload: options,
1838
+ },
1839
+ );
1840
+ }
1841
+
1817
1842
  /**
1818
1843
  * queryMessageFlags - Query message flags
1819
1844
  *
@@ -1838,10 +1863,10 @@ export class StreamChat {
1838
1863
  /**
1839
1864
  * queryChannelsRequest - Queries channels and returns the raw response
1840
1865
  *
1841
- * @param {ChannelFilters} filterConditions object MongoDB style filters
1866
+ * @param {ChannelFilters} filterConditions object MongoDB style filters. Can be empty object when using predefined_filter in options.
1842
1867
  * @param {ChannelSort} [sort] Sort options, for instance {created_at: -1}.
1843
1868
  * When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{last_updated: -1}, {created_at: 1}]
1844
- * @param {ChannelOptions} [options] Options object
1869
+ * @param {ChannelOptions} [options] Options object. Can include predefined_filter, filter_values, and sort_values for using predefined filters.
1845
1870
  *
1846
1871
  * @return {Promise<Array<ChannelAPIResponse>>} search channels response
1847
1872
  */
@@ -1862,13 +1887,23 @@ export class StreamChat {
1862
1887
  defaultOptions.watch = false;
1863
1888
  }
1864
1889
 
1865
- // Return a list of channels
1866
- const payload = {
1867
- filter_conditions: filterConditions,
1868
- sort: normalizeQuerySort(sort),
1869
- ...defaultOptions,
1870
- ...options,
1871
- };
1890
+ const { predefined_filter, filter_values, sort_values, ...restOptions } = options;
1891
+
1892
+ // Build payload based on whether we're using a predefined filter or traditional filters
1893
+ const payload = predefined_filter
1894
+ ? {
1895
+ predefined_filter,
1896
+ filter_values,
1897
+ sort_values,
1898
+ ...defaultOptions,
1899
+ ...restOptions,
1900
+ }
1901
+ : {
1902
+ filter_conditions: filterConditions,
1903
+ sort: normalizeQuerySort(sort),
1904
+ ...defaultOptions,
1905
+ ...restOptions,
1906
+ };
1872
1907
 
1873
1908
  const data = await this.post<QueryChannelsAPIResponse>(
1874
1909
  this.baseURL + '/channels',
@@ -3746,6 +3781,15 @@ export class StreamChat {
3746
3781
  return new Campaign(this, idOrData, data);
3747
3782
  }
3748
3783
 
3784
+ /**
3785
+ * channelBatchUpdater - Returns a ChannelBatchUpdater instance for batch channel operations
3786
+ *
3787
+ * @return {ChannelBatchUpdater} A ChannelBatchUpdater instance
3788
+ */
3789
+ channelBatchUpdater() {
3790
+ return new ChannelBatchUpdater(this);
3791
+ }
3792
+
3749
3793
  segment(type: SegmentType, idOrData: string | SegmentData, data?: SegmentData) {
3750
3794
  if (typeof idOrData === 'string') {
3751
3795
  return new Segment(this, type, idOrData, data);
@@ -3757,7 +3801,7 @@ export class StreamChat {
3757
3801
  validateServerSideAuth() {
3758
3802
  if (!this.secret) {
3759
3803
  throw new Error(
3760
- 'Campaigns is a server-side only feature. Please initialize the client with a secret to use this feature.',
3804
+ 'This feature can be used server-side only. Please initialize the client with a secret to use this feature.',
3761
3805
  );
3762
3806
  }
3763
3807
  }
@@ -4792,4 +4836,95 @@ export class StreamChat {
4792
4836
  syncDeliveredCandidates(collections: Channel[]) {
4793
4837
  this.messageDeliveryReporter.syncDeliveredCandidates(collections);
4794
4838
  }
4839
+
4840
+ /**
4841
+ * Update Channels Batch
4842
+ *
4843
+ * @param {UpdateChannelsBatchOptions} payload for updating channels in batch
4844
+ * @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response
4845
+ */
4846
+ async updateChannelsBatch(payload: UpdateChannelsBatchOptions) {
4847
+ return await this.put<APIResponse & UpdateChannelsBatchResponse>(
4848
+ this.baseURL + `/channels/batch`,
4849
+ payload,
4850
+ );
4851
+ }
4852
+
4853
+ /**
4854
+ * createPredefinedFilter - Creates a new predefined filter (server-side only)
4855
+ *
4856
+ * @param {CreatePredefinedFilterOptions} options Predefined filter options
4857
+ *
4858
+ * @return {Promise<PredefinedFilterResponse>} The created predefined filter
4859
+ */
4860
+ async createPredefinedFilter(options: CreatePredefinedFilterOptions) {
4861
+ this.validateServerSideAuth();
4862
+ return await this.post<PredefinedFilterResponse>(
4863
+ `${this.baseURL}/predefined_filters`,
4864
+ options,
4865
+ );
4866
+ }
4867
+
4868
+ /**
4869
+ * getPredefinedFilter - Gets a predefined filter by name (server-side only)
4870
+ *
4871
+ * @param {string} name Predefined filter name
4872
+ *
4873
+ * @return {Promise<PredefinedFilterResponse>} The predefined filter
4874
+ */
4875
+ async getPredefinedFilter(name: string) {
4876
+ this.validateServerSideAuth();
4877
+ return await this.get<PredefinedFilterResponse>(
4878
+ `${this.baseURL}/predefined_filters/${encodeURIComponent(name)}`,
4879
+ );
4880
+ }
4881
+
4882
+ /**
4883
+ * updatePredefinedFilter - Updates a predefined filter (server-side only)
4884
+ *
4885
+ * @param {string} name Predefined filter name
4886
+ * @param {UpdatePredefinedFilterOptions} options Predefined filter options
4887
+ *
4888
+ * @return {Promise<PredefinedFilterResponse>} The updated predefined filter
4889
+ */
4890
+ async updatePredefinedFilter(name: string, options: UpdatePredefinedFilterOptions) {
4891
+ this.validateServerSideAuth();
4892
+ return await this.put<PredefinedFilterResponse>(
4893
+ `${this.baseURL}/predefined_filters/${encodeURIComponent(name)}`,
4894
+ options,
4895
+ );
4896
+ }
4897
+
4898
+ /**
4899
+ * deletePredefinedFilter - Deletes a predefined filter (server-side only)
4900
+ *
4901
+ * @param {string} name Predefined filter name
4902
+ *
4903
+ * @return {Promise<APIResponse>} The server response
4904
+ */
4905
+ async deletePredefinedFilter(name: string) {
4906
+ this.validateServerSideAuth();
4907
+ return await this.delete<APIResponse>(
4908
+ `${this.baseURL}/predefined_filters/${encodeURIComponent(name)}`,
4909
+ );
4910
+ }
4911
+
4912
+ /**
4913
+ * listPredefinedFilters - Lists all predefined filters (server-side only)
4914
+ *
4915
+ * @param {ListPredefinedFiltersOptions} options Query options
4916
+ *
4917
+ * @return {Promise<ListPredefinedFiltersResponse>} The list of predefined filters
4918
+ */
4919
+ async listPredefinedFilters(options: ListPredefinedFiltersOptions = {}) {
4920
+ this.validateServerSideAuth();
4921
+ const { sort, ...paginationOptions } = options;
4922
+ return await this.get<ListPredefinedFiltersResponse>(
4923
+ `${this.baseURL}/predefined_filters`,
4924
+ {
4925
+ ...paginationOptions,
4926
+ ...(sort ? { sort: JSON.stringify(sort) } : {}),
4927
+ },
4928
+ );
4929
+ }
4795
4930
  }
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './base64';
2
2
  export * from './campaign';
3
+ export * from './channel_batch_updater';
3
4
  export * from './client';
4
5
  export * from './client_state';
5
6
  export * from './channel';
@@ -16,15 +16,16 @@ export const getTriggerCharWithToken = ({
16
16
  isCommand?: boolean;
17
17
  acceptTrailingSpaces?: boolean;
18
18
  }) => {
19
- const triggerNorWhitespace = `[^\\s${trigger}]*`;
19
+ const escapedTrigger = escapeRegExp(trigger);
20
+ const triggerNorWhitespace = `[^\\s${escapedTrigger}]*`;
20
21
 
21
22
  const match = text.match(
22
23
  new RegExp(
23
24
  isCommand
24
- ? `^[${trigger}]${triggerNorWhitespace}$`
25
+ ? `^[${escapedTrigger}]${triggerNorWhitespace}$`
25
26
  : acceptTrailingSpaces
26
- ? `(?!^|\\W)?[${trigger}]${triggerNorWhitespace}\\s?${triggerNorWhitespace}$`
27
- : `(?!^|\\W)?[${trigger}]${triggerNorWhitespace}$`,
27
+ ? `(?!^|\\W)?[${escapedTrigger}]${triggerNorWhitespace}\\s?${triggerNorWhitespace}$`
28
+ : `(?!^|\\W)?[${escapedTrigger}]${triggerNorWhitespace}$`,
28
29
  'g',
29
30
  ),
30
31
  );
package/src/types.ts CHANGED
@@ -284,6 +284,26 @@ export type BannedUsersResponse = APIResponse & {
284
284
  }>;
285
285
  };
286
286
 
287
+ export type FutureChannelBan = {
288
+ user: UserResponse;
289
+ expires?: string;
290
+ reason?: string;
291
+ shadow?: boolean;
292
+ created_at: string;
293
+ };
294
+
295
+ export type FutureChannelBansResponse = APIResponse & {
296
+ bans: FutureChannelBan[];
297
+ };
298
+
299
+ export type QueryFutureChannelBansOptions = {
300
+ user_id?: string;
301
+ target_user_id?: string;
302
+ exclude_expired_bans?: boolean;
303
+ limit?: number;
304
+ offset?: number;
305
+ };
306
+
287
307
  export type BlockListResponse = BlockList & {
288
308
  created_at?: string;
289
309
  type?: string;
@@ -994,6 +1014,7 @@ export type BannedUsersPaginationOptions = Omit<
994
1014
  };
995
1015
 
996
1016
  export type BanUserOptions = UnBanUserOptions & {
1017
+ ban_from_future_channels?: boolean;
997
1018
  banned_by?: UserResponse;
998
1019
  banned_by_id?: string;
999
1020
  ip_ban?: boolean;
@@ -1011,6 +1032,21 @@ export type ChannelOptions = {
1011
1032
  state?: boolean;
1012
1033
  user_id?: string;
1013
1034
  watch?: boolean;
1035
+ /**
1036
+ * Name of a predefined filter to use instead of filter_conditions.
1037
+ * When provided, filter_conditions and sort parameters are ignored.
1038
+ */
1039
+ predefined_filter?: string;
1040
+ /**
1041
+ * Values to interpolate into the predefined filter template placeholders.
1042
+ * Only used when predefined_filter is provided.
1043
+ */
1044
+ filter_values?: Record<string, unknown>;
1045
+ /**
1046
+ * Values to interpolate into the predefined filter sort template placeholders.
1047
+ * Only used when predefined_filter is provided.
1048
+ */
1049
+ sort_values?: Record<string, unknown>;
1014
1050
  };
1015
1051
 
1016
1052
  export type ChannelQueryOptions = {
@@ -1478,6 +1514,7 @@ export type UnBanUserOptions = {
1478
1514
  client_id?: string;
1479
1515
  connection_id?: string;
1480
1516
  id?: string;
1517
+ remove_future_channels_ban?: boolean;
1481
1518
  shadow?: boolean;
1482
1519
  target_user_id?: string;
1483
1520
  type?: string;
@@ -4495,3 +4532,101 @@ export type EventHook = {
4495
4532
  created_at?: string;
4496
4533
  updated_at?: string;
4497
4534
  };
4535
+
4536
+ export type BatchUpdateOperation =
4537
+ | 'addMembers'
4538
+ | 'removeMembers'
4539
+ | 'inviteMembers'
4540
+ | 'assignRoles'
4541
+ | 'addModerators'
4542
+ | 'demoteModerators'
4543
+ | 'hide'
4544
+ | 'show'
4545
+ | 'archive'
4546
+ | 'unarchive'
4547
+ | 'updateData'
4548
+ | 'addFilterTags'
4549
+ | 'removeFilterTags';
4550
+
4551
+ export type BatchChannelDataUpdate = {
4552
+ frozen?: boolean;
4553
+ disabled?: boolean;
4554
+ custom?: Record<string, unknown>;
4555
+ team?: string;
4556
+ config_overrides?: Record<string, unknown>;
4557
+ auto_translation_enabled?: boolean;
4558
+ auto_translation_language?: string;
4559
+ };
4560
+
4561
+ export type UpdateChannelsBatchOptions = {
4562
+ operation: BatchUpdateOperation;
4563
+ filter: UpdateChannelsBatchFilters;
4564
+ members?: string[] | Array<NewMemberPayload>;
4565
+ data?: BatchChannelDataUpdate;
4566
+ filter_tags_update?: string[];
4567
+ };
4568
+
4569
+ export type UpdateChannelsBatchFilters = QueryFilters<{
4570
+ cids?:
4571
+ | RequireOnlyOne<Pick<QueryFilter<string>, '$in' | '$eq'>>
4572
+ | PrimitiveFilter<string[]>;
4573
+ types?:
4574
+ | RequireOnlyOne<Pick<QueryFilter<string>, '$in' | '$eq'>>
4575
+ | PrimitiveFilter<string[]>;
4576
+ filter_tags?:
4577
+ | RequireOnlyOne<Pick<QueryFilter<string>, '$in' | '$eq'>>
4578
+ | PrimitiveFilter<Record<string, string>>;
4579
+ }>;
4580
+
4581
+ export type UpdateChannelsBatchResponse = {
4582
+ result: Record<string, string>;
4583
+ } & Partial<TaskResponse>;
4584
+
4585
+ /**
4586
+ * Predefined Filter Types
4587
+ */
4588
+
4589
+ export type PredefinedFilterOperation = 'QueryChannels';
4590
+
4591
+ export type PredefinedFilterSortParam = {
4592
+ field: string;
4593
+ direction?: AscDesc;
4594
+ type?: string;
4595
+ };
4596
+
4597
+ export type PredefinedFilter = {
4598
+ name: string;
4599
+ operation: PredefinedFilterOperation;
4600
+ filter: Record<string, unknown>;
4601
+ created_at: string;
4602
+ updated_at: string;
4603
+ description?: string;
4604
+ sort?: PredefinedFilterSortParam[];
4605
+ query_id?: number;
4606
+ };
4607
+
4608
+ export type CreatePredefinedFilterOptions = {
4609
+ name: string;
4610
+ operation: PredefinedFilterOperation;
4611
+ filter: Record<string, unknown>;
4612
+ description?: string;
4613
+ sort?: PredefinedFilterSortParam[];
4614
+ };
4615
+
4616
+ export type UpdatePredefinedFilterOptions = Omit<CreatePredefinedFilterOptions, 'name'>;
4617
+
4618
+ export type PredefinedFilterResponse = APIResponse & {
4619
+ predefined_filter: PredefinedFilter;
4620
+ };
4621
+
4622
+ export type ListPredefinedFiltersResponse = APIResponse & {
4623
+ predefined_filters: PredefinedFilter[];
4624
+ next?: string;
4625
+ prev?: string;
4626
+ };
4627
+
4628
+ export type PredefinedFilterSort = SortParam[];
4629
+
4630
+ export type ListPredefinedFiltersOptions = Pager & {
4631
+ sort?: PredefinedFilterSort;
4632
+ };