stream-chat 8.57.6 → 8.59.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
@@ -214,6 +214,10 @@ import {
214
214
  UserResponse,
215
215
  UserSort,
216
216
  VoteSort,
217
+ QueryDraftsResponse,
218
+ DraftFilters,
219
+ DraftSort,
220
+ Pager,
217
221
  } from './types';
218
222
  import { InsightMetrics, postInsights } from './insights';
219
223
  import { Thread } from './thread';
@@ -330,6 +334,7 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
330
334
  warmUp: false,
331
335
  recoverStateOnReconnect: true,
332
336
  disableCache: false,
337
+ wsUrlParams: new URLSearchParams({}),
333
338
  ...inputOptions,
334
339
  };
335
340
 
@@ -4045,4 +4050,32 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
4045
4050
  ...options,
4046
4051
  });
4047
4052
  }
4053
+
4054
+ /**
4055
+ * queryDrafts - Queries drafts for the current user
4056
+ *
4057
+ * @param {object} [options] Query options
4058
+ * @param {object} [options.filter] Filters for the query
4059
+ * @param {number} [options.sort] Sort parameters
4060
+ * @param {number} [options.limit] Limit the number of results
4061
+ * @param {string} [options.next] Pagination parameter
4062
+ * @param {string} [options.prev] Pagination parameter
4063
+ * @param {string} [options.user_id] Has to be provided when called server-side
4064
+ *
4065
+ * @return {Promise<APIResponse & { drafts: DraftResponse<StreamChatGenerics>[]; next?: string }>} Response containing the drafts
4066
+ */
4067
+ async queryDrafts(
4068
+ options: Pager & {
4069
+ filter?: DraftFilters<StreamChatGenerics>;
4070
+ sort?: DraftSort;
4071
+ user_id?: string;
4072
+ } = {},
4073
+ ) {
4074
+ const payload = {
4075
+ ...options,
4076
+ sort: options.sort ? normalizeQuerySort(options.sort) : undefined,
4077
+ };
4078
+
4079
+ return await this.post<QueryDraftsResponse<StreamChatGenerics>>(this.baseURL + '/drafts/query', payload);
4080
+ }
4048
4081
  }
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
@@ -32,6 +32,8 @@ export type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<
32
32
  [K in Keys]-?: Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, undefined>>;
33
33
  }[Keys];
34
34
 
35
+ export type PartializeKeys<T, K extends keyof T> = Partial<Pick<T, K>> & Omit<T, K>;
36
+
35
37
  /* Unknown Record */
36
38
  export type UR = Record<string, unknown>;
37
39
  export type UnknownType = UR; //alias to avoid breaking change
@@ -919,9 +921,12 @@ export type UserResponse<StreamChatGenerics extends ExtendableGenerics = Default
919
921
  push_notifications?: PushNotificationSettings;
920
922
  revoke_tokens_issued_before?: string;
921
923
  shadow_banned?: boolean;
924
+ teams_role?: TeamsRole;
922
925
  updated_at?: string;
923
926
  };
924
927
 
928
+ export type TeamsRole = { [team: string]: string };
929
+
925
930
  export type PrivacySettings = {
926
931
  read_receipts?: {
927
932
  enabled?: boolean;
@@ -1241,6 +1246,11 @@ export type StreamChatOptions = AxiosRequestConfig & {
1241
1246
  * not be used in production apps.
1242
1247
  */
1243
1248
  wsConnection?: StableWSConnection;
1249
+ /**
1250
+ * Sets a suffix to the wsUrl when it is being built in `wsConnection`. Is meant to be
1251
+ * used purely in testing suites and should not be used in production apps.
1252
+ */
1253
+ wsUrlParams?: URLSearchParams;
1244
1254
  };
1245
1255
 
1246
1256
  export type SyncOptions = {
@@ -1308,6 +1318,7 @@ export type Event<StreamChatGenerics extends ExtendableGenerics = DefaultGeneric
1308
1318
  connection_id?: string;
1309
1319
  // event creation timestamp, format Date ISO string
1310
1320
  created_at?: string;
1321
+ draft?: DraftResponse<StreamChatGenerics>;
1311
1322
  // id of the message that was marked as unread - all the following messages are considered unread. (notification.mark_unread)
1312
1323
  first_unread_message_id?: string;
1313
1324
  hard_delete?: boolean;
@@ -1592,6 +1603,18 @@ export type ChannelFilters<StreamChatGenerics extends ExtendableGenerics = Defau
1592
1603
  }
1593
1604
  >;
1594
1605
 
1606
+ export type DraftFilters<SCG extends ExtendableGenerics = DefaultGenerics> = {
1607
+ channel_cid?:
1608
+ | RequireOnlyOne<Pick<QueryFilter<DraftResponse<SCG>['channel_cid']>, '$in' | '$eq'>>
1609
+ | PrimitiveFilter<DraftResponse<SCG>['channel_cid']>;
1610
+ created_at?:
1611
+ | RequireOnlyOne<Pick<QueryFilter<DraftResponse<SCG>['created_at']>, '$eq' | '$gt' | '$lt' | '$gte' | '$lte'>>
1612
+ | PrimitiveFilter<DraftResponse<SCG>['created_at']>;
1613
+ parent_id?:
1614
+ | RequireOnlyOne<Pick<QueryFilter<DraftResponse<SCG>['created_at']>, '$in' | '$eq' | '$exists'>>
1615
+ | PrimitiveFilter<DraftResponse<SCG>['parent_id']>;
1616
+ };
1617
+
1595
1618
  export type QueryPollsParams = {
1596
1619
  filter?: QueryPollsFilters;
1597
1620
  options?: QueryPollsOptions;
@@ -2041,6 +2064,12 @@ export type SearchMessageSort<StreamChatGenerics extends ExtendableGenerics = De
2041
2064
  | SearchMessageSortBase<StreamChatGenerics>
2042
2065
  | Array<SearchMessageSortBase<StreamChatGenerics>>;
2043
2066
 
2067
+ export type DraftSortBase = {
2068
+ created_at?: AscDesc;
2069
+ };
2070
+
2071
+ export type DraftSort = DraftSortBase | Array<DraftSortBase>;
2072
+
2044
2073
  export type QuerySort<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> =
2045
2074
  | BannedUsersSort
2046
2075
  | ChannelSort<StreamChatGenerics>
@@ -3045,6 +3074,7 @@ export type CampaignData = {
3045
3074
  segment_ids?: string[];
3046
3075
  sender_id?: string;
3047
3076
  sender_mode?: 'exclude' | 'include' | null;
3077
+ show_channels?: boolean;
3048
3078
  skip_push?: boolean;
3049
3079
  skip_webhook?: boolean;
3050
3080
  user_ids?: string[];
@@ -3828,3 +3858,45 @@ export type SdkIdentifier = { name: 'react' | 'react-native' | 'expo' | 'angular
3828
3858
  * available. Is used by the react-native SDKs to enrich the user agent further.
3829
3859
  */
3830
3860
  export type DeviceIdentifier = { os: string; model?: string };
3861
+
3862
+ export type DraftResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = {
3863
+ channel_cid: string;
3864
+ created_at: string;
3865
+ message: DraftMessage<StreamChatGenerics>;
3866
+ channel?: ChannelResponse<StreamChatGenerics>;
3867
+ parent_id?: string;
3868
+ parent_message?: MessageResponseBase<StreamChatGenerics>;
3869
+ quoted_message?: MessageResponseBase<StreamChatGenerics>;
3870
+ };
3871
+ export type CreateDraftResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & {
3872
+ draft: DraftResponse<StreamChatGenerics>;
3873
+ };
3874
+
3875
+ export type GetDraftResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & {
3876
+ draft: DraftResponse<StreamChatGenerics>;
3877
+ };
3878
+
3879
+ export type QueryDraftsResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & {
3880
+ drafts: DraftResponse<StreamChatGenerics>[];
3881
+ } & Omit<Pager, 'limit'>;
3882
+
3883
+ export type DraftMessagePayload<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = PartializeKeys<
3884
+ DraftMessage<StreamChatGenerics>,
3885
+ 'id'
3886
+ > & { user_id?: string };
3887
+
3888
+ export type DraftMessage<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = {
3889
+ id: string;
3890
+ text: string;
3891
+ attachments?: Attachment<StreamChatGenerics>[];
3892
+ custom?: {};
3893
+ html?: string;
3894
+ mentioned_users?: string[];
3895
+ mml?: string;
3896
+ parent_id?: string;
3897
+ poll_id?: string;
3898
+ quoted_message_id?: string;
3899
+ show_in_channel?: boolean;
3900
+ silent?: boolean;
3901
+ type?: MessageLabel;
3902
+ };