stream-chat 8.57.6 → 8.58.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/connection.ts CHANGED
@@ -184,14 +184,20 @@ export class StableWSConnection<StreamChatGenerics extends ExtendableGenerics =
184
184
  * @returns url string
185
185
  */
186
186
  _buildUrl = () => {
187
- const qs = encodeURIComponent(this.client._buildWSPayload(this.requestID));
187
+ const qs = this.client._buildWSPayload(this.requestID);
188
188
  const token = this.client.tokenManager.getToken();
189
-
190
- return `${this.client.wsBaseURL}/connect?json=${qs}&api_key=${
191
- this.client.key
192
- }&authorization=${token}&stream-auth-type=${this.client.getAuthType()}&X-Stream-Client=${encodeURIComponent(
193
- this.client.getUserAgent(),
194
- )}`;
189
+ const wsUrlParams = this.client.options.wsUrlParams;
190
+
191
+ const params = new URLSearchParams(wsUrlParams);
192
+ params.set('json', qs);
193
+ params.set('api_key', this.client.key);
194
+ // it is expected that the autorization parameter exists even if
195
+ // the token is undefined, so we interpolate it to be safe
196
+ params.set('authorization', `${token}`);
197
+ params.set('stream-auth-type', this.client.getAuthType());
198
+ params.set('X-Stream-Client', this.client.getUserAgent());
199
+
200
+ return `${this.client.wsBaseURL}/connect?${params.toString()}`;
195
201
  };
196
202
 
197
203
  /**
package/src/moderation.ts CHANGED
@@ -21,6 +21,7 @@ import {
21
21
  CustomCheckFlag,
22
22
  ReviewQueueItem,
23
23
  QueryConfigsResponse,
24
+ RequireAtLeastOne,
24
25
  } from './types';
25
26
  import { StreamChat } from './client';
26
27
  import { normalizeQuerySort } from './utils';
@@ -28,6 +29,7 @@ import { normalizeQuerySort } from './utils';
28
29
  export const MODERATION_ENTITY_TYPES = {
29
30
  user: 'stream:user',
30
31
  message: 'stream:chat:v1:message',
32
+ userprofile: 'stream:v1:user_profile',
31
33
  };
32
34
 
33
35
  // Moderation class provides all the endpoints related to moderation v2.
@@ -247,6 +249,7 @@ export class Moderation<StreamChatGenerics extends ExtendableGenerics = DefaultG
247
249
  configKey: string,
248
250
  options?: {
249
251
  force_sync?: boolean;
252
+ test_mode?: boolean;
250
253
  },
251
254
  ) {
252
255
  return await this.client.post(this.client.baseURL + `/api/v2/moderation/check`, {
@@ -259,6 +262,57 @@ export class Moderation<StreamChatGenerics extends ExtendableGenerics = DefaultG
259
262
  });
260
263
  }
261
264
 
265
+ /**
266
+ * Experimental: Check user profile
267
+ *
268
+ * Warning: This is an experimental feature and the API is subject to change.
269
+ *
270
+ * This function is used to check a user profile for moderation.
271
+ * This will not create any review queue items for the user profile.
272
+ * You can just use this to check whether to allow a certain user profile to be created or not.
273
+ *
274
+ * Example:
275
+ *
276
+ * ```ts
277
+ * const res = await client.moderation.checkUserProfile(userId, { username: "fuck_boy_001", image: "https://example.com/profile.jpg" });
278
+ * if (res.recommended_action === "remove") {
279
+ * // Block the user profile from being created
280
+ * } else {
281
+ * // Allow the user profile to be created
282
+ * }
283
+ * ```
284
+ *
285
+ * @param userId
286
+ * @param profile.username
287
+ * @param profile.image
288
+ * @returns
289
+ */
290
+ async checkUserProfile(userId: string, profile: RequireAtLeastOne<{ image?: string; username?: string }>) {
291
+ if (!profile.username && !profile.image) {
292
+ throw new Error('Either username or image must be provided');
293
+ }
294
+
295
+ const moderationPayload: { images?: string[]; texts?: string[] } = {};
296
+ if (profile.username) {
297
+ moderationPayload.texts = [profile.username];
298
+ }
299
+ if (profile.image) {
300
+ moderationPayload.images = [profile.image];
301
+ }
302
+
303
+ return await this.check(
304
+ MODERATION_ENTITY_TYPES.userprofile,
305
+ userId,
306
+ userId,
307
+ moderationPayload,
308
+ 'user_profile:default',
309
+ {
310
+ force_sync: true,
311
+ test_mode: true,
312
+ },
313
+ );
314
+ }
315
+
262
316
  /**
263
317
  *
264
318
  * @param {string} entityType string Type of entity to be checked E.g., stream:user, stream:chat:v1:message, or any custom string
package/src/types.ts CHANGED
@@ -1241,6 +1241,11 @@ export type StreamChatOptions = AxiosRequestConfig & {
1241
1241
  * not be used in production apps.
1242
1242
  */
1243
1243
  wsConnection?: StableWSConnection;
1244
+ /**
1245
+ * Sets a suffix to the wsUrl when it is being built in `wsConnection`. Is meant to be
1246
+ * used purely in testing suites and should not be used in production apps.
1247
+ */
1248
+ wsUrlParams?: URLSearchParams;
1244
1249
  };
1245
1250
 
1246
1251
  export type SyncOptions = {
@@ -1592,6 +1597,18 @@ export type ChannelFilters<StreamChatGenerics extends ExtendableGenerics = Defau
1592
1597
  }
1593
1598
  >;
1594
1599
 
1600
+ export type DraftFilters<SCG extends ExtendableGenerics = DefaultGenerics> = {
1601
+ channel_cid?:
1602
+ | RequireOnlyOne<Pick<QueryFilter<DraftResponse<SCG>['channel_cid']>, '$in' | '$eq'>>
1603
+ | PrimitiveFilter<DraftResponse<SCG>['channel_cid']>;
1604
+ created_at?:
1605
+ | RequireOnlyOne<Pick<QueryFilter<DraftResponse<SCG>['created_at']>, '$eq' | '$gt' | '$lt' | '$gte' | '$lte'>>
1606
+ | PrimitiveFilter<DraftResponse<SCG>['created_at']>;
1607
+ parent_id?:
1608
+ | RequireOnlyOne<Pick<QueryFilter<DraftResponse<SCG>['created_at']>, '$in' | '$eq' | '$exists'>>
1609
+ | PrimitiveFilter<DraftResponse<SCG>['parent_id']>;
1610
+ };
1611
+
1595
1612
  export type QueryPollsParams = {
1596
1613
  filter?: QueryPollsFilters;
1597
1614
  options?: QueryPollsOptions;
@@ -2041,6 +2058,12 @@ export type SearchMessageSort<StreamChatGenerics extends ExtendableGenerics = De
2041
2058
  | SearchMessageSortBase<StreamChatGenerics>
2042
2059
  | Array<SearchMessageSortBase<StreamChatGenerics>>;
2043
2060
 
2061
+ export type DraftSortBase = {
2062
+ created_at?: AscDesc;
2063
+ };
2064
+
2065
+ export type DraftSort = DraftSortBase | Array<DraftSortBase>;
2066
+
2044
2067
  export type QuerySort<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> =
2045
2068
  | BannedUsersSort
2046
2069
  | ChannelSort<StreamChatGenerics>
@@ -3828,3 +3851,51 @@ export type SdkIdentifier = { name: 'react' | 'react-native' | 'expo' | 'angular
3828
3851
  * available. Is used by the react-native SDKs to enrich the user agent further.
3829
3852
  */
3830
3853
  export type DeviceIdentifier = { os: string; model?: string };
3854
+
3855
+ export declare type DraftResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = {
3856
+ channel_cid: string;
3857
+ created_at: string;
3858
+ message: DraftMessage<StreamChatGenerics>;
3859
+ channel?: ChannelResponse<StreamChatGenerics>;
3860
+ parent_id?: string;
3861
+ parent_message?: MessageResponseBase<StreamChatGenerics>;
3862
+ quoted_message?: MessageResponseBase<StreamChatGenerics>;
3863
+ };
3864
+ export declare type CreateDraftResponse<
3865
+ StreamChatGenerics extends ExtendableGenerics = DefaultGenerics
3866
+ > = APIResponse & {
3867
+ draft: DraftResponse<StreamChatGenerics>;
3868
+ };
3869
+
3870
+ export declare type GetDraftResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & {
3871
+ draft: DraftResponse<StreamChatGenerics>;
3872
+ };
3873
+
3874
+ export declare type QueryDraftsResponse<
3875
+ StreamChatGenerics extends ExtendableGenerics = DefaultGenerics
3876
+ > = APIResponse & {
3877
+ drafts: DraftResponse<StreamChatGenerics>[];
3878
+ next?: string;
3879
+ };
3880
+
3881
+ export declare type DraftMessagePayload<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = Omit<
3882
+ DraftMessage<StreamChatGenerics>,
3883
+ 'id'
3884
+ > &
3885
+ Partial<Pick<DraftMessage<StreamChatGenerics>, 'id'>>;
3886
+
3887
+ export declare type DraftMessage<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = {
3888
+ id: string;
3889
+ text: string;
3890
+ attachments?: Attachment<StreamChatGenerics>[];
3891
+ custom?: {};
3892
+ html?: string;
3893
+ mentioned_users?: string[];
3894
+ mml?: string;
3895
+ parent_id?: string;
3896
+ poll_id?: string;
3897
+ quoted_message_id?: string;
3898
+ show_in_channel?: boolean;
3899
+ silent?: boolean;
3900
+ type?: MessageLabel;
3901
+ };