stream-chat 9.53.0 → 9.54.1
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/dist/cjs/index.browser.js +362 -79
- package/dist/cjs/index.browser.js.map +3 -3
- package/dist/cjs/index.node.js +362 -79
- package/dist/cjs/index.node.js.map +3 -3
- package/dist/esm/index.mjs +362 -79
- package/dist/esm/index.mjs.map +3 -3
- package/dist/types/client.d.ts +5 -73
- package/dist/types/connection.d.ts +12 -0
- package/dist/types/poll.d.ts +22 -4
- package/dist/types/poll_optimistic_votes.d.ts +63 -0
- package/dist/types/types.d.ts +36 -9
- package/dist/types/utils.d.ts +1 -3
- package/package.json +6 -1
- package/src/client.ts +3 -3
- package/src/connection.ts +47 -2
- package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +20 -10
- package/src/poll.ts +95 -61
- package/src/poll_optimistic_votes.ts +321 -0
- package/src/thread.ts +11 -4
- package/src/types.ts +41 -9
package/dist/types/client.d.ts
CHANGED
|
@@ -988,6 +988,7 @@ export declare class StreamChat {
|
|
|
988
988
|
* @returns {Promise<APIResponse>}
|
|
989
989
|
*/
|
|
990
990
|
flagMessage(targetMessageID: string, options?: {
|
|
991
|
+
custom?: Record<string, unknown>;
|
|
991
992
|
reason?: string;
|
|
992
993
|
user_id?: string;
|
|
993
994
|
}): Promise<FlagMessageResponse>;
|
|
@@ -1120,77 +1121,10 @@ export declare class StreamChat {
|
|
|
1120
1121
|
* @param {string} messageId
|
|
1121
1122
|
* @param {string} language
|
|
1122
1123
|
*
|
|
1123
|
-
* @return {MessageResponse} Response that includes the message
|
|
1124
|
+
* @return {APIResponse & { message: MessageResponse }} Response that includes the translated message
|
|
1124
1125
|
*/
|
|
1125
|
-
translateMessage(messageId: string, language: string): Promise<APIResponse &
|
|
1126
|
-
|
|
1127
|
-
attachments?: import("./types").Attachment[];
|
|
1128
|
-
html?: string;
|
|
1129
|
-
mml?: string;
|
|
1130
|
-
parent_id?: string;
|
|
1131
|
-
pin_expires?: string | null;
|
|
1132
|
-
pinned?: boolean;
|
|
1133
|
-
pinned_at?: string | null;
|
|
1134
|
-
poll_id?: string;
|
|
1135
|
-
quoted_message_id?: string;
|
|
1136
|
-
restricted_visibility?: string[];
|
|
1137
|
-
show_in_channel?: boolean;
|
|
1138
|
-
silent?: boolean;
|
|
1139
|
-
text?: string;
|
|
1140
|
-
type?: import("./types").MessageLabel;
|
|
1141
|
-
user?: UserResponse | null;
|
|
1142
|
-
user_id?: string;
|
|
1143
|
-
} & {
|
|
1144
|
-
type: import("./types").MessageLabel;
|
|
1145
|
-
args?: string;
|
|
1146
|
-
before_message_send_failed?: boolean;
|
|
1147
|
-
channel?: ChannelResponse;
|
|
1148
|
-
cid?: string;
|
|
1149
|
-
command?: string;
|
|
1150
|
-
command_info?: {
|
|
1151
|
-
name?: string;
|
|
1152
|
-
};
|
|
1153
|
-
created_at?: string;
|
|
1154
|
-
deleted_at?: string;
|
|
1155
|
-
deleted_reply_count?: number;
|
|
1156
|
-
i18n?: import("./types").RequireAtLeastOne<Record<`${import("./types").TranslationLanguages}_text`, string>> & {
|
|
1157
|
-
language: import("./types").TranslationLanguages;
|
|
1158
|
-
};
|
|
1159
|
-
latest_reactions?: ReactionResponse[];
|
|
1160
|
-
member?: import("./types").ChannelMemberResponse;
|
|
1161
|
-
mentioned_users?: UserResponse[];
|
|
1162
|
-
mentioned_channel?: boolean;
|
|
1163
|
-
mentioned_here?: boolean;
|
|
1164
|
-
mentioned_group_ids?: string[];
|
|
1165
|
-
mentioned_groups?: import("./types").UserGroupResponse[];
|
|
1166
|
-
mentioned_roles?: string[];
|
|
1167
|
-
message_text_updated_at?: string;
|
|
1168
|
-
moderation?: import("./types").ModerationResponse;
|
|
1169
|
-
moderation_details?: import("./types").ModerationDetailsResponse;
|
|
1170
|
-
own_reactions?: ReactionResponse[] | null;
|
|
1171
|
-
pin_expires?: string | null;
|
|
1172
|
-
pinned_at?: string | null;
|
|
1173
|
-
pinned_by?: UserResponse | null;
|
|
1174
|
-
poll?: import("./types").PollResponse;
|
|
1175
|
-
reaction_counts?: {
|
|
1176
|
-
[key: string]: number;
|
|
1177
|
-
} | null;
|
|
1178
|
-
reaction_groups?: {
|
|
1179
|
-
[key: string]: import("./types").ReactionGroupResponse;
|
|
1180
|
-
} | null;
|
|
1181
|
-
reaction_scores?: {
|
|
1182
|
-
[key: string]: number;
|
|
1183
|
-
} | null;
|
|
1184
|
-
reminder?: import("./types").ReminderResponseBase;
|
|
1185
|
-
reply_count?: number;
|
|
1186
|
-
shadowed?: boolean;
|
|
1187
|
-
shared_location?: SharedLocationResponse;
|
|
1188
|
-
status?: string;
|
|
1189
|
-
thread_participants?: UserResponse[];
|
|
1190
|
-
updated_at?: string;
|
|
1191
|
-
deleted_for_me?: boolean;
|
|
1192
|
-
} & {
|
|
1193
|
-
quoted_message?: import("./types").MessageResponseBase;
|
|
1126
|
+
translateMessage(messageId: string, language: string): Promise<APIResponse & {
|
|
1127
|
+
message: MessageResponse;
|
|
1194
1128
|
}>;
|
|
1195
1129
|
/**
|
|
1196
1130
|
* translate - translates the given text to provided language
|
|
@@ -1891,9 +1825,7 @@ export declare class StreamChat {
|
|
|
1891
1825
|
created_at?: string;
|
|
1892
1826
|
deleted_at?: string;
|
|
1893
1827
|
deleted_reply_count?: number;
|
|
1894
|
-
i18n?: import("./types").
|
|
1895
|
-
language: import("./types").TranslationLanguages;
|
|
1896
|
-
};
|
|
1828
|
+
i18n?: import("./types").TranslatedField;
|
|
1897
1829
|
latest_reactions?: ReactionResponse[];
|
|
1898
1830
|
member?: import("./types").ChannelMemberResponse;
|
|
1899
1831
|
mentioned_users?: UserResponse[];
|
|
@@ -38,6 +38,12 @@ export declare class StableWSConnection {
|
|
|
38
38
|
StatusCode?: string | number;
|
|
39
39
|
}) => void;
|
|
40
40
|
requestID: string | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Set when the server sent a `connection.error` with code 40 (token expired) on an
|
|
43
|
+
* already established socket. The server closes the socket right after it, and the
|
|
44
|
+
* reconnect that follows must use a fresh token from the tokenProvider.
|
|
45
|
+
*/
|
|
46
|
+
tokenExpiredByServer: boolean;
|
|
41
47
|
resolvePromise?: (value: ConnectionOpen) => void;
|
|
42
48
|
totalFailures: number;
|
|
43
49
|
ws?: WebSocket;
|
|
@@ -99,6 +105,12 @@ export declare class StableWSConnection {
|
|
|
99
105
|
onmessage: (wsID: number, event: WebSocket.MessageEvent) => void;
|
|
100
106
|
onclose: (wsID: number, event: WebSocket.CloseEvent) => void;
|
|
101
107
|
onerror: (wsID: number, event: WebSocket.ErrorEvent) => void;
|
|
108
|
+
/**
|
|
109
|
+
* _reconnectAfterFailure - Reconnects after the socket closed or failed. If the server
|
|
110
|
+
* reported that the token expired, the token is refreshed before reconnecting.
|
|
111
|
+
* Static tokens cannot be refreshed and reconnect as before.
|
|
112
|
+
*/
|
|
113
|
+
_reconnectAfterFailure(): void;
|
|
102
114
|
/**
|
|
103
115
|
* _setHealth - Sets the connection to healthy or unhealthy.
|
|
104
116
|
* Broadcasts an event in case the connection status changed.
|
package/dist/types/poll.d.ts
CHANGED
|
@@ -29,10 +29,13 @@ export declare class Poll {
|
|
|
29
29
|
readonly state: StateStore<PollState>;
|
|
30
30
|
id: string;
|
|
31
31
|
private client;
|
|
32
|
+
private optimisticVotes;
|
|
33
|
+
private closeConfirmed;
|
|
32
34
|
constructor({ client, poll }: PollInitOptions);
|
|
33
35
|
private getInitialStateFromPollResponse;
|
|
34
36
|
private upsertOfflineDb;
|
|
35
37
|
reinitializeState: (poll: PollInitOptions["poll"]) => void;
|
|
38
|
+
private updateFromVoteEvent;
|
|
36
39
|
get data(): PollState;
|
|
37
40
|
handlePollUpdated: (event: Event) => void;
|
|
38
41
|
handlePollClosed: (event: Event) => void;
|
|
@@ -42,15 +45,30 @@ export declare class Poll {
|
|
|
42
45
|
query: (id: string) => Promise<PollResponse>;
|
|
43
46
|
update: (data: Exclude<PollData, "id">) => Promise<import("./types").APIResponse & import("./types").UpdatePollAPIResponse>;
|
|
44
47
|
partialUpdate: (partialPollObject: PartialPollUpdate) => Promise<import("./types").APIResponse & import("./types").UpdatePollAPIResponse>;
|
|
45
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Closes the poll. The poll is marked as closed optimistically and the change is
|
|
50
|
+
* reverted if the request fails, unless the server confirmed the close meanwhile.
|
|
51
|
+
* Does nothing if the poll is already closed.
|
|
52
|
+
*/
|
|
53
|
+
close: () => Promise<(import("./types").APIResponse & import("./types").UpdatePollAPIResponse) | undefined>;
|
|
46
54
|
delete: () => Promise<import("./types").APIResponse>;
|
|
47
55
|
createOption: (option: PollOptionData) => Promise<import("./types").APIResponse & import("./types").CreatePollOptionAPIResponse>;
|
|
48
56
|
updateOption: (option: PollOptionData) => Promise<import("./types").APIResponse & import("./types").CreatePollOptionAPIResponse>;
|
|
49
57
|
deleteOption: (optionId: string) => Promise<import("./types").APIResponse>;
|
|
58
|
+
/**
|
|
59
|
+
* Casts a vote for an option. The vote is shown right away through a local placeholder vote,
|
|
60
|
+
* which the server's vote replaces once the WS events of all pending vote changes arrived.
|
|
61
|
+
* If the request fails, the change is reverted.
|
|
62
|
+
*/
|
|
50
63
|
castVote: (optionId: string, messageId: string) => Promise<(import("./types").APIResponse & import("./types").CastVoteAPIResponse) | undefined>;
|
|
51
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Removes a vote. The vote is removed right away and restored if the request fails. Vote
|
|
66
|
+
* requests are sent in order, so removing a vote whose cast is not confirmed yet uses the vote
|
|
67
|
+
* id from the cast's response; if that cast failed, there is nothing to remove.
|
|
68
|
+
*/
|
|
69
|
+
removeVote: (voteId: string, messageId: string) => Promise<(import("./types").APIResponse & {
|
|
52
70
|
vote: PollVote;
|
|
53
|
-
}>;
|
|
71
|
+
}) | undefined>;
|
|
54
72
|
addAnswer: (answerText: string, messageId: string) => Promise<import("./types").APIResponse & import("./types").CastVoteAPIResponse>;
|
|
55
73
|
removeAnswer: (answerId: string, messageId: string) => Promise<import("./types").APIResponse & {
|
|
56
74
|
vote: PollVote;
|
|
@@ -59,6 +77,6 @@ export declare class Poll {
|
|
|
59
77
|
queryOptionVotes: (params: PollOptionVotesQueryParams) => Promise<import("./types").APIResponse & import("./types").PollVotesAPIResponse>;
|
|
60
78
|
}
|
|
61
79
|
export declare function extractPollData(pollResponse: PollResponse): PollData;
|
|
62
|
-
export declare function mapPollStateToResponse(poll: Poll): PollResponse;
|
|
80
|
+
export declare function mapPollStateToResponse(poll: Poll, state?: PollState): PollResponse;
|
|
63
81
|
export declare function extractPollEnrichedData(pollResponse: PollResponse): Omit<PollEnrichData, 'own_votes' | 'latest_answers'>;
|
|
64
82
|
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { StreamChat } from './client';
|
|
2
|
+
import type { Poll, PollState } from './poll';
|
|
3
|
+
import type { PollResponse, PollVote } from './types';
|
|
4
|
+
type OptionId = string;
|
|
5
|
+
/**
|
|
6
|
+
* Optimistic updates for the current user's votes on a poll. Vote changes are shown right away.
|
|
7
|
+
* While any of them is not confirmed by its WS event, vote events are only stored, as the server
|
|
8
|
+
* state they carry does not contain the pending changes yet. Once all are confirmed (a failed
|
|
9
|
+
* request counts as confirmed), the server's vote state is shown, which also reverts failed changes.
|
|
10
|
+
* Vote requests are sent one after another, so the server applies them in the order they were made.
|
|
11
|
+
* A lost WS event is recovered from after CATCH_UP_TIMEOUT_MS (see applySucceededChanges).
|
|
12
|
+
*/
|
|
13
|
+
export declare class OptimisticPollVotes {
|
|
14
|
+
private serverVoteState;
|
|
15
|
+
private pendingCount;
|
|
16
|
+
private succeededChanges;
|
|
17
|
+
private readonly requestTag;
|
|
18
|
+
private catchUpTimeout?;
|
|
19
|
+
private readonly client;
|
|
20
|
+
private readonly poll;
|
|
21
|
+
constructor({ client, poll }: {
|
|
22
|
+
client: StreamChat;
|
|
23
|
+
poll: Poll;
|
|
24
|
+
});
|
|
25
|
+
get serverOwnVotes(): Record<string, PollVote>;
|
|
26
|
+
withServerVotes: (pollState: PollState) => PollState;
|
|
27
|
+
/**
|
|
28
|
+
* Casts a vote for an option, shown right away through a placeholder vote. In polls with unique
|
|
29
|
+
* votes, it replaces the existing own votes.
|
|
30
|
+
*/
|
|
31
|
+
castVote: (optionId: OptionId, messageId: string) => Promise<(import("./types").APIResponse & import("./types").CastVoteAPIResponse) | undefined>;
|
|
32
|
+
removeVote: (voteId: string, messageId: string) => Promise<(import("./types").APIResponse & {
|
|
33
|
+
vote: PollVote;
|
|
34
|
+
}) | undefined>;
|
|
35
|
+
private send;
|
|
36
|
+
handleVoteEvent: (poll: PollResponse, { confirmsOwnVote, ownVotesByOptionId, }: {
|
|
37
|
+
confirmsOwnVote: boolean;
|
|
38
|
+
ownVotesByOptionId: Record<OptionId, PollVote>;
|
|
39
|
+
}) => Partial<PollState>;
|
|
40
|
+
reset: (pollState: PollState) => void;
|
|
41
|
+
private track;
|
|
42
|
+
private settleWithoutEvent;
|
|
43
|
+
private createPlaceholderVote;
|
|
44
|
+
/**
|
|
45
|
+
* The server id of a vote to remove, once everything sent before the removal has finished. Casts
|
|
46
|
+
* and removals of an option alternate, so the option's last succeeded change tells: a cast is the
|
|
47
|
+
* vote being removed (e.g. a placeholder), a removal means the cast in between failed. Without
|
|
48
|
+
* one, the server's own vote of the option is the vote being removed.
|
|
49
|
+
*/
|
|
50
|
+
private getServerVoteId;
|
|
51
|
+
private takeServerVoteState;
|
|
52
|
+
private scheduleCatchUp;
|
|
53
|
+
/**
|
|
54
|
+
* A WS event of an own vote change got lost, so the server's own votes are stale. All requests
|
|
55
|
+
* have finished (the timeout starts once nothing is left to send and a new request cancels it),
|
|
56
|
+
* so applying the succeeded changes in order gives the server's own votes (changes whose events
|
|
57
|
+
* did arrive end up the same). They are shown with the vote counts of the last WS event, which
|
|
58
|
+
* contain the other users' votes too.
|
|
59
|
+
*/
|
|
60
|
+
private applySucceededChanges;
|
|
61
|
+
}
|
|
62
|
+
export declare function getMaxVotedOptionIds(voteCountsByOption: PollResponse['vote_counts_by_option']): string[];
|
|
63
|
+
export {};
|
package/dist/types/types.d.ts
CHANGED
|
@@ -92,6 +92,7 @@ export type AppSettingsAPIResponse = APIResponse & {
|
|
|
92
92
|
auto_translation_enabled?: boolean;
|
|
93
93
|
before_message_send_hook_url?: string;
|
|
94
94
|
before_message_send_hook_attempt_timeout_ms?: number;
|
|
95
|
+
before_message_send_hook_system_messages?: boolean;
|
|
95
96
|
campaign_enabled?: boolean;
|
|
96
97
|
cdn_expiration_seconds?: number;
|
|
97
98
|
chat_primary_use_case?: string;
|
|
@@ -436,8 +437,10 @@ export type FlagMessageResponse = APIResponse & {
|
|
|
436
437
|
user: UserResponse;
|
|
437
438
|
approved_at?: string;
|
|
438
439
|
channel_cid?: string;
|
|
440
|
+
custom?: Record<string, unknown>;
|
|
439
441
|
details?: object;
|
|
440
442
|
message_user_id?: string;
|
|
443
|
+
reason?: string;
|
|
441
444
|
rejected_at?: string;
|
|
442
445
|
reviewed_at?: string;
|
|
443
446
|
reviewed_by?: string;
|
|
@@ -622,6 +625,7 @@ export type PushPreferencesResponse = {
|
|
|
622
625
|
/** Per-channel push preferences returned by the API (matches OpenAPI `ChannelPushPreferencesResponse`). */
|
|
623
626
|
export type ChannelPushPreference = {
|
|
624
627
|
chat_level?: ChatLevelPushPreference;
|
|
628
|
+
chat_preferences?: ChatPreferences;
|
|
625
629
|
disabled_until?: string;
|
|
626
630
|
};
|
|
627
631
|
export type UpsertPushPreferencesResponse = APIResponse & {
|
|
@@ -667,9 +671,7 @@ export type MessageResponseBase = MessageBase & {
|
|
|
667
671
|
created_at?: string;
|
|
668
672
|
deleted_at?: string;
|
|
669
673
|
deleted_reply_count?: number;
|
|
670
|
-
i18n?:
|
|
671
|
-
language: TranslationLanguages;
|
|
672
|
-
};
|
|
674
|
+
i18n?: TranslatedField;
|
|
673
675
|
latest_reactions?: ReactionResponse[];
|
|
674
676
|
member?: ChannelMemberResponse;
|
|
675
677
|
mentioned_users?: UserResponse[];
|
|
@@ -895,6 +897,7 @@ export type UserResponse = CustomUserData & {
|
|
|
895
897
|
deactivated_at?: string;
|
|
896
898
|
deleted_at?: string;
|
|
897
899
|
image?: string;
|
|
900
|
+
invisible?: boolean;
|
|
898
901
|
language?: TranslationLanguages | '';
|
|
899
902
|
last_active?: string;
|
|
900
903
|
name?: string;
|
|
@@ -1260,7 +1263,7 @@ export type UpdateChannelOptions = Partial<{
|
|
|
1260
1263
|
data: Omit<ChannelResponse, 'id' | 'cid'>;
|
|
1261
1264
|
demote_moderators: string[];
|
|
1262
1265
|
invites: string[];
|
|
1263
|
-
message:
|
|
1266
|
+
message: Message;
|
|
1264
1267
|
reject_invite: boolean;
|
|
1265
1268
|
remove_members: string[];
|
|
1266
1269
|
user: UserResponse;
|
|
@@ -1637,6 +1640,9 @@ export type ChannelFilters = QueryFilters<ContainsOperator<Omit<CustomChannelDat
|
|
|
1637
1640
|
app_banned?: 'only' | 'excluded';
|
|
1638
1641
|
has_unread?: boolean;
|
|
1639
1642
|
archived?: boolean;
|
|
1643
|
+
invite?: {
|
|
1644
|
+
$eq?: Exclude<InviteStatus, 'member'>;
|
|
1645
|
+
} | Exclude<InviteStatus, 'member'>;
|
|
1640
1646
|
'member.user.name'?: RequireOnlyOne<{
|
|
1641
1647
|
$autocomplete?: string;
|
|
1642
1648
|
$eq?: string;
|
|
@@ -1647,8 +1653,13 @@ export type ChannelFilters = QueryFilters<ContainsOperator<Omit<CustomChannelDat
|
|
|
1647
1653
|
} & QueryFilter<string>> | PrimitiveFilter<string>;
|
|
1648
1654
|
pinned?: boolean;
|
|
1649
1655
|
last_updated?: RequireOnlyOne<Pick<QueryFilter<string>, '$eq' | '$gt' | '$gte' | '$lt' | '$lte'>> | PrimitiveFilter<string>;
|
|
1656
|
+
/**
|
|
1657
|
+
* With multi-tenancy, client-side queries without a `team` filter only return channels of
|
|
1658
|
+
* the user's teams; an empty filter (`team: {}`) queries across all teams.
|
|
1659
|
+
*/
|
|
1660
|
+
team?: RequireOnlyOne<QueryFilter<ChannelResponse['team']>> | PrimitiveFilter<ChannelResponse['team']> | Record<string, never>;
|
|
1650
1661
|
} & {
|
|
1651
|
-
[Key in keyof Omit<ChannelResponse, 'name' | 'members' | keyof CustomChannelData>]: RequireOnlyOne<QueryFilter<ChannelResponse[Key]>> | PrimitiveFilter<ChannelResponse[Key]>;
|
|
1662
|
+
[Key in keyof Omit<ChannelResponse, 'name' | 'members' | 'team' | keyof CustomChannelData>]: RequireOnlyOne<QueryFilter<ChannelResponse[Key]>> | PrimitiveFilter<ChannelResponse[Key]>;
|
|
1652
1663
|
}>;
|
|
1653
1664
|
export type DraftFilters = {
|
|
1654
1665
|
channel_cid?: RequireOnlyOne<Pick<QueryFilter<DraftResponse['channel_cid']>, '$in' | '$eq'>> | PrimitiveFilter<DraftResponse['channel_cid']>;
|
|
@@ -2320,9 +2331,13 @@ export type Mute = {
|
|
|
2320
2331
|
export type PartialUpdateChannelFields = Partial<ChannelResponse> & {
|
|
2321
2332
|
config_overrides?: Partial<ChannelConfigFields>;
|
|
2322
2333
|
};
|
|
2334
|
+
/** Dot-notation path to a nested custom field, e.g. `channel_detail.topic`. */
|
|
2335
|
+
type NestedFieldPath = `${string}.${string}`;
|
|
2323
2336
|
export type PartialUpdateChannel = {
|
|
2324
|
-
set?: PartialUpdateChannelFields
|
|
2325
|
-
|
|
2337
|
+
set?: PartialUpdateChannelFields & {
|
|
2338
|
+
[path: NestedFieldPath]: unknown;
|
|
2339
|
+
};
|
|
2340
|
+
unset?: Array<keyof PartialUpdateChannelFields | NestedFieldPath>;
|
|
2326
2341
|
};
|
|
2327
2342
|
export type PartialUpdateMember = {
|
|
2328
2343
|
set?: ChannelMemberUpdates;
|
|
@@ -2335,8 +2350,10 @@ export type PartialUserUpdate = {
|
|
|
2335
2350
|
};
|
|
2336
2351
|
export type MessageUpdatableFields = Omit<MessageResponse, 'cid' | 'created_at' | 'updated_at' | 'deleted_at' | 'user' | 'user_id'>;
|
|
2337
2352
|
export type PartialMessageUpdate = {
|
|
2338
|
-
set?: Partial<MessageUpdatableFields
|
|
2339
|
-
|
|
2353
|
+
set?: Partial<MessageUpdatableFields> & {
|
|
2354
|
+
[path: NestedFieldPath]: unknown;
|
|
2355
|
+
};
|
|
2356
|
+
unset?: Array<keyof MessageUpdatableFields | NestedFieldPath>;
|
|
2340
2357
|
};
|
|
2341
2358
|
export type PendingMessageResponse = {
|
|
2342
2359
|
message: MessageResponse;
|
|
@@ -2423,6 +2440,9 @@ export type TestSNSDataInput = {
|
|
|
2423
2440
|
export type TokenOrProvider = null | string | TokenProvider | undefined;
|
|
2424
2441
|
export type TokenProvider = () => Promise<string>;
|
|
2425
2442
|
export type TranslationLanguages = 'af' | 'am' | 'ar' | 'az' | 'bg' | 'bn' | 'bs' | 'cs' | 'da' | 'de' | 'el' | 'en' | 'es' | 'es-MX' | 'et' | 'fa' | 'fa-AF' | 'fi' | 'fr' | 'fr-CA' | 'ha' | 'he' | 'hi' | 'hr' | 'hu' | 'id' | 'it' | 'ja' | 'ka' | 'ko' | 'lt' | 'lv' | 'ms' | 'nl' | 'no' | 'pl' | 'ps' | 'pt' | 'ro' | 'ru' | 'sk' | 'sl' | 'so' | 'sq' | 'sr' | 'sv' | 'sw' | 'ta' | 'th' | 'tl' | 'tr' | 'uk' | 'ur' | 'vi' | 'zh' | 'zh-TW' | (string & {});
|
|
2443
|
+
export type TranslatedField = RequireAtLeastOne<Record<`${TranslationLanguages}_text`, string>> & {
|
|
2444
|
+
language: TranslationLanguages;
|
|
2445
|
+
};
|
|
2426
2446
|
export type TypingStartEvent = Event;
|
|
2427
2447
|
export type ReservedUpdatedMessageFields = keyof typeof RESERVED_UPDATED_MESSAGE_FIELDS;
|
|
2428
2448
|
export type UpdatedMessage = Omit<MessageResponse, ReservedUpdatedMessageFields | 'mentioned_groups'> & {
|
|
@@ -2582,6 +2602,7 @@ export type TaskStatus = {
|
|
|
2582
2602
|
};
|
|
2583
2603
|
export type TruncateOptions = {
|
|
2584
2604
|
hard_delete?: boolean;
|
|
2605
|
+
member_ids?: string[];
|
|
2585
2606
|
message?: Message;
|
|
2586
2607
|
skip_push?: boolean;
|
|
2587
2608
|
truncated_at?: Date;
|
|
@@ -2695,7 +2716,9 @@ export type PollResponse = CustomPollData & PollEnrichData & {
|
|
|
2695
2716
|
allow_answers?: boolean;
|
|
2696
2717
|
allow_user_suggested_options?: boolean;
|
|
2697
2718
|
description?: string;
|
|
2719
|
+
description_i18n?: TranslatedField;
|
|
2698
2720
|
is_closed?: boolean;
|
|
2721
|
+
name_i18n?: TranslatedField;
|
|
2699
2722
|
voting_visibility?: VotingVisibility;
|
|
2700
2723
|
};
|
|
2701
2724
|
export type PollOption = {
|
|
@@ -2705,6 +2728,7 @@ export type PollOption = {
|
|
|
2705
2728
|
text: string;
|
|
2706
2729
|
updated_at: string;
|
|
2707
2730
|
vote_count: number;
|
|
2731
|
+
text_i18n?: TranslatedField;
|
|
2708
2732
|
votes?: PollVote[];
|
|
2709
2733
|
};
|
|
2710
2734
|
export declare enum VotingVisibility {
|
|
@@ -2768,6 +2792,7 @@ export type PollOptionResponse = CustomPollData & {
|
|
|
2768
2792
|
text: string;
|
|
2769
2793
|
updated_at: string;
|
|
2770
2794
|
vote_count: number;
|
|
2795
|
+
text_i18n?: TranslatedField;
|
|
2771
2796
|
votes?: PollVote[];
|
|
2772
2797
|
};
|
|
2773
2798
|
export type PollVote = {
|
|
@@ -2782,6 +2807,7 @@ export type PollVote = {
|
|
|
2782
2807
|
export type PollAnswer = Exclude<PollVote, 'option_id'> & {
|
|
2783
2808
|
answer_text: string;
|
|
2784
2809
|
is_answer: boolean;
|
|
2810
|
+
answer_text_i18n?: TranslatedField;
|
|
2785
2811
|
};
|
|
2786
2812
|
export type PollVotesAPIResponse = {
|
|
2787
2813
|
votes: (PollVote | PollAnswer)[];
|
|
@@ -2861,6 +2887,7 @@ export type ReviewQueueItem = {
|
|
|
2861
2887
|
id: string;
|
|
2862
2888
|
moderation_payload: ModerationPayload;
|
|
2863
2889
|
moderation_payload_hash: string;
|
|
2890
|
+
message?: MessageResponse;
|
|
2864
2891
|
options: any;
|
|
2865
2892
|
recommended_action: string;
|
|
2866
2893
|
results: any;
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -134,9 +134,7 @@ export declare const toDeletedMessage: ({ message, deletedAt, hardDelete, }: {
|
|
|
134
134
|
[key: string]: number;
|
|
135
135
|
} | null | undefined;
|
|
136
136
|
reply_count?: number | undefined;
|
|
137
|
-
i18n?:
|
|
138
|
-
language: import("./types").TranslationLanguages;
|
|
139
|
-
}) | undefined;
|
|
137
|
+
i18n?: import("./types").TranslatedField | undefined;
|
|
140
138
|
html?: string | undefined;
|
|
141
139
|
user?: (UserResponse | null) | undefined;
|
|
142
140
|
id: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stream-chat",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.54.1",
|
|
4
4
|
"description": "JS SDK for the Stream Chat API",
|
|
5
5
|
"homepage": "https://getstream.io/chat/",
|
|
6
6
|
"author": {
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"@eslint/js": "^9.39.4",
|
|
67
67
|
"@semantic-release/changelog": "^6.0.3",
|
|
68
68
|
"@semantic-release/git": "^10.0.1",
|
|
69
|
+
"@stream-io/node-sdk": "^0.8.10",
|
|
69
70
|
"@types/node": "^22.19.19",
|
|
70
71
|
"@types/sinon": "^10.0.6",
|
|
71
72
|
"@vitest/coverage-v8": "^4.1.10",
|
|
@@ -101,6 +102,10 @@
|
|
|
101
102
|
"run-types-gen": "tsc -p test/typescript/tsconfig.json",
|
|
102
103
|
"test-unit": "vitest",
|
|
103
104
|
"test-coverage": "vitest run --coverage",
|
|
105
|
+
"test-docs": "vitest run --config test/docs-snippets/vitest.config.mts",
|
|
106
|
+
"test-docs-sweep": "vitest run --config test/docs-snippets/vitest.sweep.config.mts",
|
|
107
|
+
"test-docs-sync": "vitest run --config test/docs-snippets/vitest.sync.config.mts",
|
|
108
|
+
"types-docs": "tsc -p test/docs-snippets/tsconfig.json",
|
|
104
109
|
"fix-staged": "lint-staged --config .lintstagedrc.fix.json --concurrent 1",
|
|
105
110
|
"semantic-release": "semantic-release",
|
|
106
111
|
"postinstall": "node -e \"require('fs').existsSync('scripts/install-husky.mjs') && import('./scripts/install-husky.mjs')\"",
|
package/src/client.ts
CHANGED
|
@@ -3096,7 +3096,7 @@ export class StreamChat {
|
|
|
3096
3096
|
*/
|
|
3097
3097
|
async flagMessage(
|
|
3098
3098
|
targetMessageID: string,
|
|
3099
|
-
options: { reason?: string; user_id?: string } = {},
|
|
3099
|
+
options: { custom?: Record<string, unknown>; reason?: string; user_id?: string } = {},
|
|
3100
3100
|
) {
|
|
3101
3101
|
return await this.post<FlagMessageResponse>(this.baseURL + '/moderation/flag', {
|
|
3102
3102
|
target_message_id: targetMessageID,
|
|
@@ -3330,10 +3330,10 @@ export class StreamChat {
|
|
|
3330
3330
|
* @param {string} messageId
|
|
3331
3331
|
* @param {string} language
|
|
3332
3332
|
*
|
|
3333
|
-
* @return {MessageResponse} Response that includes the message
|
|
3333
|
+
* @return {APIResponse & { message: MessageResponse }} Response that includes the translated message
|
|
3334
3334
|
*/
|
|
3335
3335
|
async translateMessage(messageId: string, language: string) {
|
|
3336
|
-
return await this.post<APIResponse & MessageResponse>(
|
|
3336
|
+
return await this.post<APIResponse & { message: MessageResponse }>(
|
|
3337
3337
|
this.baseURL + `/messages/${encodeURIComponent(messageId)}/translate`,
|
|
3338
3338
|
{ language },
|
|
3339
3339
|
);
|
package/src/connection.ts
CHANGED
|
@@ -68,6 +68,12 @@ export class StableWSConnection {
|
|
|
68
68
|
},
|
|
69
69
|
) => void;
|
|
70
70
|
requestID: string | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Set when the server sent a `connection.error` with code 40 (token expired) on an
|
|
73
|
+
* already established socket. The server closes the socket right after it, and the
|
|
74
|
+
* reconnect that follows must use a fresh token from the tokenProvider.
|
|
75
|
+
*/
|
|
76
|
+
tokenExpiredByServer: boolean;
|
|
71
77
|
resolvePromise?: (value: ConnectionOpen) => void;
|
|
72
78
|
totalFailures: number;
|
|
73
79
|
ws?: WebSocket;
|
|
@@ -92,6 +98,8 @@ export class StableWSConnection {
|
|
|
92
98
|
this.wsID = 1;
|
|
93
99
|
/** Store the last event time for health checks */
|
|
94
100
|
this.lastEvent = null;
|
|
101
|
+
/** Set when the server reports that the token of the open socket expired */
|
|
102
|
+
this.tokenExpiredByServer = false;
|
|
95
103
|
/** Send a health check message every 25 seconds */
|
|
96
104
|
this.pingInterval = 25 * 1000;
|
|
97
105
|
this.connectionCheckTimeout = this.pingInterval + 10 * 1000;
|
|
@@ -229,6 +237,7 @@ export class StableWSConnection {
|
|
|
229
237
|
this.wsID += 1;
|
|
230
238
|
this.isConnecting = false;
|
|
231
239
|
this.isDisconnected = true;
|
|
240
|
+
this.tokenExpiredByServer = false;
|
|
232
241
|
|
|
233
242
|
// start by removing all the listeners
|
|
234
243
|
if (this.healthCheckTimeoutRef) {
|
|
@@ -408,6 +417,13 @@ export class StableWSConnection {
|
|
|
408
417
|
|
|
409
418
|
if (options.refreshToken) {
|
|
410
419
|
await this.client.tokenManager.loadToken();
|
|
420
|
+
|
|
421
|
+
// Another reconnect may have started while the token was loading, e.g. when
|
|
422
|
+
// the socket fires both an error and a close event.
|
|
423
|
+
if (this.isConnecting || this.isHealthy) {
|
|
424
|
+
this._log('_reconnect() - Abort (4) since already connecting or healthy');
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
411
427
|
}
|
|
412
428
|
|
|
413
429
|
try {
|
|
@@ -501,6 +517,17 @@ export class StableWSConnection {
|
|
|
501
517
|
this.scheduleNextPing();
|
|
502
518
|
}
|
|
503
519
|
|
|
520
|
+
// The server reports a token that expired after the connection was established
|
|
521
|
+
// (auto_disconnect_ws) and then closes the socket. Remember it so the reconnect
|
|
522
|
+
// refreshes the token first instead of retrying once with the expired token.
|
|
523
|
+
if (
|
|
524
|
+
data?.type === 'connection.error' &&
|
|
525
|
+
data?.error?.code === chatCodes.TOKEN_EXPIRED
|
|
526
|
+
) {
|
|
527
|
+
this._log('onmessage() - server reported that the token expired', { wsID });
|
|
528
|
+
this.tokenExpiredByServer = true;
|
|
529
|
+
}
|
|
530
|
+
|
|
504
531
|
this.client.dispatchEvent(data);
|
|
505
532
|
this.scheduleConnectionCheck();
|
|
506
533
|
};
|
|
@@ -535,7 +562,7 @@ export class StableWSConnection {
|
|
|
535
562
|
this._log(`onclose() - WS connection closed. Calling reconnect ...`, { event });
|
|
536
563
|
|
|
537
564
|
// reconnect if its an abnormal failure
|
|
538
|
-
this.
|
|
565
|
+
this._reconnectAfterFailure();
|
|
539
566
|
}
|
|
540
567
|
};
|
|
541
568
|
|
|
@@ -550,9 +577,26 @@ export class StableWSConnection {
|
|
|
550
577
|
this.rejectPromise?.(this._errorFromWSEvent(event));
|
|
551
578
|
this._log(`onerror() - WS connection resulted into error`, { event });
|
|
552
579
|
|
|
553
|
-
this.
|
|
580
|
+
this._reconnectAfterFailure();
|
|
554
581
|
};
|
|
555
582
|
|
|
583
|
+
/**
|
|
584
|
+
* _reconnectAfterFailure - Reconnects after the socket closed or failed. If the server
|
|
585
|
+
* reported that the token expired, the token is refreshed before reconnecting.
|
|
586
|
+
* Static tokens cannot be refreshed and reconnect as before.
|
|
587
|
+
*/
|
|
588
|
+
_reconnectAfterFailure() {
|
|
589
|
+
if (this.tokenExpiredByServer && !this.client.tokenManager.isStatic()) {
|
|
590
|
+
this._log(
|
|
591
|
+
'_reconnectAfterFailure() - token expired, so going to reload token and reconnect',
|
|
592
|
+
);
|
|
593
|
+
this._reconnect({ refreshToken: true });
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
this._reconnect();
|
|
598
|
+
}
|
|
599
|
+
|
|
556
600
|
/**
|
|
557
601
|
* _setHealth - Sets the connection to healthy or unhealthy.
|
|
558
602
|
* Broadcasts an event in case the connection status changed.
|
|
@@ -642,6 +686,7 @@ export class StableWSConnection {
|
|
|
642
686
|
*/
|
|
643
687
|
_setupConnectionPromise = () => {
|
|
644
688
|
this.isResolved = false;
|
|
689
|
+
this.tokenExpiredByServer = false;
|
|
645
690
|
/** a promise that is resolved once ws.open is called */
|
|
646
691
|
this.connectionOpen = new Promise<ConnectionOpen>((resolve, reject) => {
|
|
647
692
|
this.resolvePromise = resolve;
|
|
@@ -32,12 +32,15 @@ export const createLinkPreviewsCompositionMiddleware = (
|
|
|
32
32
|
LinkPreviewsManager.getPreviewData(preview),
|
|
33
33
|
);
|
|
34
34
|
|
|
35
|
-
const
|
|
35
|
+
const messageAttachments: Attachment[] = (state.message.attachments ?? []).concat(
|
|
36
36
|
linkPreviews,
|
|
37
37
|
);
|
|
38
|
+
const localAttachments: Attachment[] = (
|
|
39
|
+
state.localMessage.attachments ?? []
|
|
40
|
+
).concat(linkPreviews);
|
|
38
41
|
|
|
39
42
|
// prevent introducing attachments array into the payload sent to the server
|
|
40
|
-
if (!
|
|
43
|
+
if (!messageAttachments.length && !localAttachments.length) return forward();
|
|
41
44
|
|
|
42
45
|
const sendOptions = { ...state.sendOptions };
|
|
43
46
|
const skip_enrich_url =
|
|
@@ -47,16 +50,23 @@ export const createLinkPreviewsCompositionMiddleware = (
|
|
|
47
50
|
sendOptions.skip_enrich_url = true;
|
|
48
51
|
}
|
|
49
52
|
|
|
53
|
+
// Each payload gets the `attachments` key only when there is something to put in it,
|
|
54
|
+
// matching the attachments middleware. An empty array is not "nothing to say": on an edit
|
|
55
|
+
// the API reads it as "remove every attachment".
|
|
50
56
|
return next({
|
|
51
57
|
...state,
|
|
52
|
-
message:
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
message: messageAttachments.length
|
|
59
|
+
? {
|
|
60
|
+
...state.message,
|
|
61
|
+
attachments: messageAttachments,
|
|
62
|
+
}
|
|
63
|
+
: state.message,
|
|
64
|
+
localMessage: localAttachments.length
|
|
65
|
+
? {
|
|
66
|
+
...state.localMessage,
|
|
67
|
+
attachments: localAttachments,
|
|
68
|
+
}
|
|
69
|
+
: state.localMessage,
|
|
60
70
|
sendOptions,
|
|
61
71
|
});
|
|
62
72
|
},
|