stream-chat 10.0.0-rc.21 → 10.0.0-rc.22
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 +308 -216
- package/dist/cjs/index.browser.js.map +3 -3
- package/dist/cjs/index.node.js +308 -216
- package/dist/cjs/index.node.js.map +3 -3
- package/dist/esm/index.mjs +311 -219
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/client.d.ts +22 -21
- package/dist/types/configuration/types.d.ts +31 -0
- package/dist/types/messageComposer/linkPreviewsManager.d.ts +2 -2
- package/dist/types/pagination/cursorDerivation/aroundPaginationFlags.d.ts +14 -0
- package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +2 -4
- package/dist/types/pagination/paginators/BasePaginator.d.ts +5 -1
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +2 -0
- package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +5 -3
- package/dist/types/pagination/paginators/MessagePaginator.d.ts +5 -1
- package/dist/types/types.d.ts +1 -39
- package/package.json +7 -2
- package/src/ChannelManager.ts +7 -0
- package/src/EventHandlerPipeline.ts +2 -1
- package/src/api-client.ts +14 -8
- package/src/channel.ts +10 -0
- package/src/client.ts +44 -43
- package/src/configuration/keys.ts +5 -0
- package/src/configuration/shape.ts +36 -0
- package/src/configuration/types.ts +31 -0
- package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +30 -0
- package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +12 -60
- package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
- package/src/pagination/paginators/BasePaginator.ts +43 -18
- package/src/pagination/paginators/ChannelPaginator.ts +39 -14
- package/src/pagination/paginators/MessageIntervalPaginator.ts +17 -11
- package/src/pagination/paginators/MessagePaginator.ts +51 -5
- package/src/types.ts +1 -40
package/dist/types/client.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { ClientState } from './client_state';
|
|
|
5
5
|
import { UploadManager } from './uploadManager';
|
|
6
6
|
import { TokenManager, type TokenManagerMinimalUser } from './token_manager';
|
|
7
7
|
import { ApiClient } from './api-client';
|
|
8
|
-
import type { APIResponse, AppIdentifier, ChannelInput, ChannelMute, ChannelOptions, ChannelResponse, ChannelStateOptions, ChannelStateResponseFields, Configs, ConnectAPIResponse, DeviceIdentifier, Event, EventHandler, EventType, FileUploadInput, GetThreadOptions, LocalMessage, OwnUserResponse, PartializeAllBut, QueryChannelsRequest, QueryChannelsResponse, QueryThreadsRequest, SdkIdentifier,
|
|
8
|
+
import type { APIResponse, AppIdentifier, ChannelInput, ChannelMute, ChannelOptions, ChannelResponse, ChannelStateOptions, ChannelStateResponseFields, Configs, ConnectAPIResponse, DeviceIdentifier, Event, EventHandler, EventType, FileUploadInput, GetThreadOptions, LocalMessage, OwnUserResponse, PartializeAllBut, QueryChannelsRequest, QueryChannelsResponse, QueryThreadsRequest, SdkIdentifier, StreamRequestOptions, TimestampNS, TokenOrProvider, UnBanUserOptions, UserMuteResponse, UserResponse } from './types';
|
|
9
9
|
import { Thread } from './thread';
|
|
10
10
|
import { Moderation } from './moderation';
|
|
11
11
|
import { ThreadManager } from './thread_manager';
|
|
@@ -19,7 +19,8 @@ import { ReminderManager } from './reminders';
|
|
|
19
19
|
import type { AbstractOfflineDB } from './offline-support';
|
|
20
20
|
import { FixedSizeQueueCache } from './utils/FixedSizeQueueCache';
|
|
21
21
|
import type { MessageComposer } from './messageComposer';
|
|
22
|
-
import type { InstanceSetupState } from './configuration';
|
|
22
|
+
import type { InstanceConfigTree, InstanceSetupState } from './configuration';
|
|
23
|
+
import type { DeepPartial } from './types.utility';
|
|
23
24
|
import { InstanceConfigurationRegistry } from './configuration/InstanceConfigurationRegistry';
|
|
24
25
|
import { StateStore } from '@stream-io/state-store';
|
|
25
26
|
import type { FileUploadRequest, GetApplicationResponse as Gen_GetApplicationResponse, MarkDeliveredRequest as Gen_MarkDeliveredRequest, ImageUploadRequest, WSAuthMessage, WSEvent } from './gen/models';
|
|
@@ -112,10 +113,8 @@ export declare class StreamChat extends ChatApi {
|
|
|
112
113
|
offlineDb?: AbstractOfflineDB;
|
|
113
114
|
notifications: NotificationManager;
|
|
114
115
|
reminders: ReminderManager;
|
|
115
|
-
persistUserOnConnectionFailure?: boolean;
|
|
116
116
|
axiosInstance: AxiosInstance;
|
|
117
117
|
baseURL?: string;
|
|
118
|
-
browser: boolean;
|
|
119
118
|
cleaningIntervalRef?: ReturnType<typeof setTimeout>;
|
|
120
119
|
clientId?: string;
|
|
121
120
|
key: string;
|
|
@@ -142,8 +141,6 @@ export declare class StreamChat extends ChatApi {
|
|
|
142
141
|
*/
|
|
143
142
|
readonly channelServerConfigsStore: StateStore<ChannelConfigsState>;
|
|
144
143
|
blockedUsers: StateStore<BlockedUsersState>;
|
|
145
|
-
node: boolean;
|
|
146
|
-
options: StreamChatOptions;
|
|
147
144
|
setUserPromise: ConnectAPIResponse | null;
|
|
148
145
|
state: ClientState;
|
|
149
146
|
tokenManager: TokenManager;
|
|
@@ -156,6 +153,12 @@ export declare class StreamChat extends ChatApi {
|
|
|
156
153
|
private _wsConnectId;
|
|
157
154
|
private _resolveWsPromise?;
|
|
158
155
|
private _rejectWsPromise?;
|
|
156
|
+
/**
|
|
157
|
+
* Whether the client runs in a browser. `client.browser` in the configuration when set, otherwise
|
|
158
|
+
* whether a global `window` exists.
|
|
159
|
+
*/
|
|
160
|
+
get browser(): boolean;
|
|
161
|
+
get node(): boolean;
|
|
159
162
|
get anonymous(): boolean;
|
|
160
163
|
get userId(): string | undefined;
|
|
161
164
|
/**
|
|
@@ -190,16 +193,16 @@ export declare class StreamChat extends ChatApi {
|
|
|
190
193
|
*
|
|
191
194
|
* @example <caption>initialize the client in user mode</caption>
|
|
192
195
|
* new StreamChat('api_key')
|
|
193
|
-
* @example <caption>initialize the client with
|
|
194
|
-
* new StreamChat('api_key', { axiosRequestConfig: { timeout: 5000 } })
|
|
196
|
+
* @example <caption>initialize the client with configuration</caption>
|
|
197
|
+
* new StreamChat('api_key', { client: { axiosRequestConfig: { timeout: 5000 } } })
|
|
195
198
|
*
|
|
196
199
|
* @param key - The API key.
|
|
197
|
-
* @param
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
* `
|
|
200
|
+
* @param config - Declarative configuration, the same tree `client.config.set()` takes (optional).
|
|
201
|
+
* Seeded before anything is built, so it reaches the client's own managers and the fields that are
|
|
202
|
+
* read once during construction — `client.baseURL`, `client.axiosRequestConfig` and
|
|
203
|
+
* `client.notificationManager`.
|
|
201
204
|
*/
|
|
202
|
-
constructor(key: string,
|
|
205
|
+
constructor(key: string, config?: DeepPartial<InstanceConfigTree>);
|
|
203
206
|
/**
|
|
204
207
|
* Subscribes the client's managers to the `'client'` configuration key.
|
|
205
208
|
*
|
|
@@ -254,21 +257,19 @@ export declare class StreamChat extends ChatApi {
|
|
|
254
257
|
*
|
|
255
258
|
* This function always returns the same client instance to avoid issues raised by multiple client and WS connections.
|
|
256
259
|
*
|
|
257
|
-
* **After the first call, the client configuration will not change if the key or
|
|
260
|
+
* **After the first call, the client configuration will not change if the key or config parameters change.**
|
|
258
261
|
*
|
|
259
262
|
* @example <caption>initialize the client in user mode</caption>
|
|
260
263
|
* StreamChat.getInstance('api_key')
|
|
261
|
-
* @example <caption>initialize the client with
|
|
262
|
-
* StreamChat.getInstance('api_key', { axiosRequestConfig: { timeout: 5000 } })
|
|
264
|
+
* @example <caption>initialize the client with configuration</caption>
|
|
265
|
+
* StreamChat.getInstance('api_key', { client: { axiosRequestConfig: { timeout: 5000 } } })
|
|
263
266
|
*
|
|
264
267
|
* @param key - The API key.
|
|
265
|
-
* @param
|
|
266
|
-
*
|
|
267
|
-
* @param options.axiosRequestConfig - Axios-level request configuration such as `timeout`,
|
|
268
|
-
* `headers` or `httpsAgent`, spread into the client's axios instance (optional).
|
|
268
|
+
* @param config - Declarative configuration, as for the constructor (optional). Ignored once the
|
|
269
|
+
* instance exists.
|
|
269
270
|
* @returns The shared client instance.
|
|
270
271
|
*/
|
|
271
|
-
static getInstance(key: string,
|
|
272
|
+
static getInstance(key: string, config?: DeepPartial<InstanceConfigTree>): StreamChat;
|
|
272
273
|
setOfflineDBApi(offlineDBInstance: AbstractOfflineDB): void;
|
|
273
274
|
getAuthType(): "anonymous" | "jwt";
|
|
274
275
|
setBaseURL(baseURL: string): void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AxiosRequestConfig } from 'axios';
|
|
1
2
|
import type { StreamChat } from '../client';
|
|
2
3
|
import type { LiveLocationManager, LiveLocationManagerConfig } from '../LiveLocationManager';
|
|
3
4
|
import type { SearchController, SearchControllerConfig } from '../search/SearchController';
|
|
@@ -6,6 +7,7 @@ import type { MessageComposerConfig } from '../messageComposer/configuration/typ
|
|
|
6
7
|
import type { Channel, ChannelConfig } from '../channel';
|
|
7
8
|
import type { Thread, ThreadConfig } from '../thread';
|
|
8
9
|
import type { ReminderManagerConfig } from '../reminders/ReminderManager';
|
|
10
|
+
import type { NotificationManager } from '../notifications/NotificationManager';
|
|
9
11
|
import type { NotificationManagerConfig } from '../notifications/types';
|
|
10
12
|
import type { MessageDeliveryReporterConfig } from '../messageDelivery/MessageDeliveryReporter';
|
|
11
13
|
import type { ThreadManagerConfig } from '../thread_manager';
|
|
@@ -111,6 +113,35 @@ export type ThreadDeclarativeConfig = {
|
|
|
111
113
|
requestHandlers?: ThreadConfig['requestHandlers'];
|
|
112
114
|
};
|
|
113
115
|
export type ClientDeclarativeConfig = {
|
|
116
|
+
/**
|
|
117
|
+
* Silences the warning `connectUser` / `connectAnonymousUser` log when called server-side, where a
|
|
118
|
+
* connection counts towards MAU and concurrent-connection billing. Read on every connect.
|
|
119
|
+
*/
|
|
120
|
+
allowServerSideConnect?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Axios-level request configuration — `timeout`, `headers`, `httpsAgent` and so on. Built into the
|
|
123
|
+
* client's axios instance once, at construction; `headers` and `params` are additionally read on every
|
|
124
|
+
* request. Copied when registered, so changing the object you passed afterwards has no effect — register
|
|
125
|
+
* a new value instead.
|
|
126
|
+
*/
|
|
127
|
+
axiosRequestConfig?: AxiosRequestConfig;
|
|
128
|
+
/** Base URL of the API, such as `https://chat-proxy-dublin.stream-io-api.com`. Read once, at construction. */
|
|
129
|
+
baseURL?: string;
|
|
130
|
+
/** Enforces browser (`true`) or Node (`false`) mode; detected from the global `window` when absent. Read live, through `client.browser` and `client.node`. */
|
|
131
|
+
browser?: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* A pre-built {@link NotificationManager} for the client to use instead of constructing its own — to
|
|
134
|
+
* share one between clients, or to hand over one that already holds notifications. Read once, at
|
|
135
|
+
* construction. The client still applies the `notifications` slice below to it, on top of any
|
|
136
|
+
* configuration the manager was constructed with.
|
|
137
|
+
*/
|
|
138
|
+
notificationManager?: NotificationManager;
|
|
139
|
+
/**
|
|
140
|
+
* When true, the user stays on the client if `connectUser` fails, so a chat application working offline
|
|
141
|
+
* keeps `client.user` and does not have to call `connectUser` again to retry. Read when a connect fails,
|
|
142
|
+
* so it can be changed at any time.
|
|
143
|
+
*/
|
|
144
|
+
persistUserOnConnectionFailure?: boolean;
|
|
114
145
|
/**
|
|
115
146
|
* Nested rather than top-level keys: each of these managers has exactly one parent — the client — so
|
|
116
147
|
* there is nothing to say once and reuse, which is what a top-level key buys (**DEC-25**).
|
|
@@ -83,10 +83,10 @@ export declare class LinkPreviewsManager implements ILinkPreviewsManager {
|
|
|
83
83
|
static previewIsFailed: (preview: LinkPreview) => boolean;
|
|
84
84
|
static previewIsPending: (preview: LinkPreview) => boolean;
|
|
85
85
|
static getPreviewData: (preview: LinkPreview) => {
|
|
86
|
-
type?: string | undefined;
|
|
87
|
-
actions?: Array<import("..").Action> | undefined;
|
|
88
86
|
custom: import("..").CustomAttachmentData;
|
|
87
|
+
type?: string | undefined;
|
|
89
88
|
text?: string | undefined;
|
|
89
|
+
actions?: Array<import("..").Action> | undefined;
|
|
90
90
|
giphy?: import("..").Images | undefined;
|
|
91
91
|
title?: string | undefined;
|
|
92
92
|
fields?: Array<import("..").Field> | undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Interval, PaginationFlags } from '../paginators';
|
|
2
|
+
/**
|
|
3
|
+
* Flags for a page centred on a point (`id_around` / `created_at_around`). The server splits the
|
|
4
|
+
* items around the point evenly and, when one side runs out, fills the rest from the other side. So
|
|
5
|
+
* on a full page a side that got less than the smaller half ran out. A page shorter than the limit
|
|
6
|
+
* holds everything on both sides.
|
|
7
|
+
*/
|
|
8
|
+
export declare const deriveAroundPaginationFlags: ({ interval, newerCount, olderCount, pageLength, requestedPageSize, }: {
|
|
9
|
+
interval: Interval;
|
|
10
|
+
newerCount: number;
|
|
11
|
+
olderCount: number;
|
|
12
|
+
pageLength: number;
|
|
13
|
+
requestedPageSize: number;
|
|
14
|
+
}) => PaginationFlags;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type { TimestampNS } from '../../types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CursorDeriveContext, PaginationFlags } from '../paginators';
|
|
3
3
|
export declare const deriveCreatedAtAroundPaginationFlags: <T extends {
|
|
4
4
|
id: string;
|
|
5
5
|
created_at: TimestampNS;
|
|
6
6
|
}, Q extends {
|
|
7
7
|
created_at_around?: Date | string;
|
|
8
|
-
}
|
|
9
|
-
paginator: P;
|
|
10
|
-
}) => PaginationFlags;
|
|
8
|
+
}>({ hasMoreHead, hasMoreTail, interval, page, queryShape, requestedPageSize, }: CursorDeriveContext<T, Q>) => PaginationFlags;
|
|
@@ -906,9 +906,11 @@ export declare abstract class BasePaginator<T, Q> {
|
|
|
906
906
|
* Locate item inside a specific interval using the same logic as locateByItem,
|
|
907
907
|
* but scoped to interval items.
|
|
908
908
|
*/
|
|
909
|
-
protected locateByItemInInterval({ item, interval, }: {
|
|
909
|
+
protected locateByItemInInterval({ item, interval, plateauScan, }: {
|
|
910
910
|
item: T;
|
|
911
911
|
interval: Interval | LogicalInterval;
|
|
912
|
+
/** Walk the interval for an item the binary search missed. Off when it cannot be there. */
|
|
913
|
+
plateauScan?: boolean;
|
|
912
914
|
}): ItemLocation | null;
|
|
913
915
|
protected locateIntervalForItem(item: T): AnyInterval | undefined;
|
|
914
916
|
/**
|
|
@@ -1114,6 +1116,8 @@ export declare abstract class BasePaginator<T, Q> {
|
|
|
1114
1116
|
} & Pick<PaginationQueryParams<Q>, "reset">) => boolean;
|
|
1115
1117
|
protected getStateBeforeFirstQuery(): PaginatorState<T>;
|
|
1116
1118
|
isJumpQueryShape(_queryShape: Q): boolean;
|
|
1119
|
+
/** The page size a query's results are measured against when deriving the head/tail flags. */
|
|
1120
|
+
protected getRequestedPageSize(_queryShape: Q | undefined): number;
|
|
1117
1121
|
protected getStateAfterQuery(stateUpdate: Partial<PaginatorState<T>>, _isFirstPage: boolean): PaginatorState<T>;
|
|
1118
1122
|
preloadFirstPageFromOfflineDb: (_params: PaginationQueryParams<Q>) => Promise<T[] | undefined> | T[] | undefined;
|
|
1119
1123
|
populateOfflineDbAfterQuery: (_params: {
|
|
@@ -96,6 +96,8 @@ export declare class ChannelPaginator extends BasePaginator<Channel, ChannelQuer
|
|
|
96
96
|
private _itemsLoadedFromOfflineDB;
|
|
97
97
|
/** The query in flight refreshes a cache-only window, so its response replaces the window. */
|
|
98
98
|
private _replaceOfflineSeedOnResponse;
|
|
99
|
+
/** The query handed to the sync manager, from the cache read until it runs. See `executeQuery`. */
|
|
100
|
+
private _queryAwaitingSync;
|
|
99
101
|
protected _sortComparatorFactory: ChannelSortComparatorFactory | undefined;
|
|
100
102
|
sortComparator: (a: Channel, b: Channel) => number;
|
|
101
103
|
filterBuilder: FilterBuilder<ChannelFilters>;
|
|
@@ -274,6 +274,8 @@ export declare class MessageIntervalPaginator extends BasePaginator<LocalMessage
|
|
|
274
274
|
*/
|
|
275
275
|
seedFirstPageSync(messages: LocalMessage[], requestedPageSize: number, messagePaginationOptions?: MessagePaginationParams, options?: SeedFirstPageOptions): void;
|
|
276
276
|
isJumpQueryShape(queryShape: MessageQueryShape): boolean;
|
|
277
|
+
/** A jump sends its own `limit`, so its head/tail flags are derived against that, not `pageSize`. */
|
|
278
|
+
protected getRequestedPageSize(queryShape: MessageQueryShape | undefined): number;
|
|
277
279
|
jumpToMessage: (messageId: string, { focusReason, focusSignalTtlMs, pageSize, suppressFocusSignal, watchChannel, }?: JumpToMessageOptions) => Promise<boolean>;
|
|
278
280
|
jumpToTheLatestMessage: (options?: JumpToMessageOptions) => Promise<boolean>;
|
|
279
281
|
/**
|
|
@@ -460,9 +462,9 @@ export declare class MessageIntervalPaginator extends BasePaginator<LocalMessage
|
|
|
460
462
|
* `isTail`/`hasMoreTail` are set; intervals entirely newer keep their flags (unloaded older
|
|
461
463
|
* messages may still sit between them and the cutoff). The active window is re-emitted once.
|
|
462
464
|
*/
|
|
463
|
-
truncate
|
|
465
|
+
truncate({ truncatedAt }: {
|
|
464
466
|
truncatedAt: TimestampNS;
|
|
465
|
-
})
|
|
467
|
+
}): void;
|
|
466
468
|
applyMessageDeletionForUser: ({ userId, hardDelete, deletedAt, }: {
|
|
467
469
|
userId: string;
|
|
468
470
|
hardDelete?: boolean;
|
|
@@ -485,7 +487,7 @@ export declare class MessageIntervalPaginator extends BasePaginator<LocalMessage
|
|
|
485
487
|
* re-emits the active window a single time (if it held an affected message) rather than one
|
|
486
488
|
* `ingestItem` re-emit per message.
|
|
487
489
|
*/
|
|
488
|
-
reflectUserUpdate
|
|
490
|
+
reflectUserUpdate(user: UserResponse): void;
|
|
489
491
|
/**
|
|
490
492
|
* Map a timestamp to a loaded message — the first message in the latest (head) window whose
|
|
491
493
|
* `created_at` is >= `timestamp` (mirrors the legacy `ChannelState.findMessageByTimestamp`
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { BasePaginatorConfig, ExecuteQueryReturnValue, Interval, PostQueryReconcileParams } from './BasePaginator';
|
|
2
2
|
import { type MessagePaginatorOptions as BaseMessagePaginatorOptions, type JumpToMessageOptions, MessageIntervalPaginator, type MessageQueryShape } from './MessageIntervalPaginator';
|
|
3
|
-
import type { LocalMessage, TimestampNS } from '../../types';
|
|
3
|
+
import type { LocalMessage, TimestampNS, UserResponse } from '../../types';
|
|
4
|
+
import type { EntityStoreChangeBatch } from '../../entityStore/EntityStore';
|
|
4
5
|
import { StateStore } from '@stream-io/state-store';
|
|
5
6
|
export type { JumpToMessageOptions, MergeNewestPageOptions, MessageFocusReason, MessageFocusSignal, MessageFocusSignalState, MessagePaginatorFilter, MessagePaginatorSort, MessagePaginatorState, MessageQueryShape, SeedFirstPageOptions, } from './MessageIntervalPaginator';
|
|
6
7
|
export { MessageIntervalPaginator } from './MessageIntervalPaginator';
|
|
@@ -142,7 +143,10 @@ export declare class MessagePaginator extends MessageIntervalPaginator {
|
|
|
142
143
|
seedLastMessageAt(value: TimestampNS | null | undefined): void;
|
|
143
144
|
ingestItem(item: LocalMessage): boolean;
|
|
144
145
|
ingestPage(params: Parameters<MessageIntervalPaginator['ingestPage']>[0]): Interval | null;
|
|
146
|
+
onEntitiesChanged(batch: EntityStoreChangeBatch): void;
|
|
147
|
+
reflectUserUpdate(user: UserResponse): void;
|
|
145
148
|
removeItem(params: Parameters<MessageIntervalPaginator['removeItem']>[0]): ReturnType<MessageIntervalPaginator['removeItem']>;
|
|
149
|
+
truncate(params: Parameters<MessageIntervalPaginator['truncate']>[0]): void;
|
|
146
150
|
/**
|
|
147
151
|
* The still-loaded message with the greatest `created_at` that passes
|
|
148
152
|
* {@link shouldAdvanceLastMessage} (skips system / thread-only per config), from the newest-loaded
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AxiosResponse } from 'axios';
|
|
2
2
|
import type { CustomEventTypes } from './custom_types';
|
|
3
|
-
import type { NotificationManager } from './notifications';
|
|
4
|
-
import type { InstanceConfigTree } from './configuration/types';
|
|
5
|
-
import type { DeepPartial } from './types.utility';
|
|
6
3
|
import type { APIError, Attachment, BanRequest, ChannelConfigWithInfo, ChannelOwnCapability, ChannelStateResponseFields, CreateDeviceRequest, CreatePollRequest, DraftPayloadResponse, FlagRequest, Images, MessageResponse, OwnUserResponse, QueryChannelsRequest, QueryMembersPayload, QueryPollsRequest, QueryPollVotesRequest, QueryReactionsRequest, QueryRemindersRequest, QueryThreadsRequest, QueryUsersPayload, ReactionResponse, SearchPayload, SendMessageRequest, SendMessageResponse, SharedLocationResponseData, TimestampNS, TranslateMessageRequest, UpdateChannelRequest, UpdateMessageRequest, UpdateMessageResponse, UpdatePollRequest, UserResponse, WSEvent } from './gen/models';
|
|
7
4
|
import type { ChatApi } from './gen-imports';
|
|
8
5
|
/**
|
|
@@ -78,41 +75,6 @@ export type Automod = ChannelConfigWithInfo['automod'];
|
|
|
78
75
|
export type AutomodBehavior = ChannelConfigWithInfo['automod_behavior'];
|
|
79
76
|
export type PinnedMessagePaginationOptions = Omit<NonNullable<Parameters<ChatApi['getPinnedMessages']>[1]>, 'sort'>;
|
|
80
77
|
export type QueryMembersOptions = Partial<Omit<QueryMembersPayload, 'filter_conditions'>>;
|
|
81
|
-
export type StreamChatOptions = {
|
|
82
|
-
/**
|
|
83
|
-
* Used to disable warnings that are triggered by using connectUser or connectAnonymousUser server-side.
|
|
84
|
-
*/
|
|
85
|
-
allowServerSideConnect?: boolean;
|
|
86
|
-
axiosRequestConfig?: AxiosRequestConfig;
|
|
87
|
-
/**
|
|
88
|
-
* Base url to use for API
|
|
89
|
-
* such as https://chat-proxy-dublin.stream-io-api.com
|
|
90
|
-
*/
|
|
91
|
-
baseURL?: string;
|
|
92
|
-
browser?: boolean;
|
|
93
|
-
/**
|
|
94
|
-
* Custom notification manager service to use for the client.
|
|
95
|
-
* If not provided, a default notification manager will be created.
|
|
96
|
-
* Notifications are used to communicate events like errors, warnings, info, etc. Other services can publish notifications or subscribe to the NotificationManager state changes.
|
|
97
|
-
*/
|
|
98
|
-
notifications?: NotificationManager;
|
|
99
|
-
/**
|
|
100
|
-
* Declarative configuration for instances the SDK creates on your behalf, seeded before the client's
|
|
101
|
-
* own managers are constructed.
|
|
102
|
-
*
|
|
103
|
-
* Equivalent to calling `client.config.set(tree)` immediately after construction, except for the
|
|
104
|
-
* `client` subtree — the configuration registry is created inside the constructor, so this is the only
|
|
105
|
-
* way to configure `reminders` / `notifications` before they are built.
|
|
106
|
-
*/
|
|
107
|
-
config?: DeepPartial<InstanceConfigTree>;
|
|
108
|
-
/**
|
|
109
|
-
* When true, user will be persisted on client. Otherwise if `connectUser` call fails, then you need to
|
|
110
|
-
* call `connectUser` again to retry.
|
|
111
|
-
* This is mainly useful for chat application working in offline mode, where you will need client.user to
|
|
112
|
-
* persist even if connectUser call fails.
|
|
113
|
-
*/
|
|
114
|
-
persistUserOnConnectionFailure?: boolean;
|
|
115
|
-
};
|
|
116
78
|
export type UnBanUserOptions = {
|
|
117
79
|
client_id?: string;
|
|
118
80
|
connection_id?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stream-chat",
|
|
3
|
-
"version": "10.0.0-rc.
|
|
3
|
+
"version": "10.0.0-rc.22",
|
|
4
4
|
"description": "JS SDK for the Stream Chat API",
|
|
5
5
|
"homepage": "https://getstream.io/chat/",
|
|
6
6
|
"author": {
|
|
@@ -56,7 +56,8 @@
|
|
|
56
56
|
"@eslint/js": "^9.39.4",
|
|
57
57
|
"@semantic-release/changelog": "^6.0.3",
|
|
58
58
|
"@semantic-release/git": "^10.0.1",
|
|
59
|
-
"@
|
|
59
|
+
"@stream-io/node-sdk": "^0.8.10",
|
|
60
|
+
"@types/node": "^22.19.19",
|
|
60
61
|
"@types/sinon": "^10.0.6",
|
|
61
62
|
"@vitest/coverage-v8": "^4.1.10",
|
|
62
63
|
"concurrently": "^9.2.1",
|
|
@@ -90,6 +91,10 @@
|
|
|
90
91
|
"test": "yarn test-unit",
|
|
91
92
|
"test-unit": "vitest",
|
|
92
93
|
"test-coverage": "vitest run --coverage",
|
|
94
|
+
"test-docs": "vitest run --config test/docs-snippets/vitest.config.mts",
|
|
95
|
+
"test-docs-sweep": "vitest run --config test/docs-snippets/vitest.sweep.config.mts",
|
|
96
|
+
"test-docs-sync": "vitest run --config test/docs-snippets/vitest.sync.config.mts",
|
|
97
|
+
"types-docs": "tsc -p test/docs-snippets/tsconfig.json",
|
|
93
98
|
"fix-staged": "lint-staged --config .lintstagedrc.fix.json --concurrent 1",
|
|
94
99
|
"semantic-release": "semantic-release",
|
|
95
100
|
"postinstall": "node -e \"require('fs').existsSync('scripts/install-husky.mjs') && import('./scripts/install-husky.mjs')\"",
|
package/src/ChannelManager.ts
CHANGED
|
@@ -212,6 +212,12 @@ const channelTruncatedHandler: LabeledEventHandler<EventHandlerContext> = {
|
|
|
212
212
|
id: 'ChannelManager:default-handler:channel.truncated',
|
|
213
213
|
};
|
|
214
214
|
|
|
215
|
+
// a hard delete of the last message might move the channel's `last_message_at` back
|
|
216
|
+
const messageDeletedHandler: LabeledEventHandler<EventHandlerContext> = {
|
|
217
|
+
handle: (context) => (context.event.hard_delete ? reinsertItem(context) : undefined),
|
|
218
|
+
id: 'ChannelManager:default-handler:message.deleted',
|
|
219
|
+
};
|
|
220
|
+
|
|
215
221
|
const channelVisibleHandler: LabeledEventHandler<EventHandlerContext> = {
|
|
216
222
|
handle: updateLists,
|
|
217
223
|
id: 'ChannelManager:default-handler:channel.visible',
|
|
@@ -417,6 +423,7 @@ export class ChannelManager extends WithSubscriptions {
|
|
|
417
423
|
'channel.hidden': [channelHiddenHandler],
|
|
418
424
|
'channel.visible': [channelVisibleHandler],
|
|
419
425
|
'member.updated': [memberUpdatedHandler],
|
|
426
|
+
'message.deleted': [messageDeletedHandler],
|
|
420
427
|
'message.new': [messageNewHandler],
|
|
421
428
|
'message.read': [readStateChangedHandler],
|
|
422
429
|
'message.read_locally': [readStateChangedHandler],
|
|
@@ -207,8 +207,9 @@ export class EventHandlerPipeline<CTX extends Record<string, unknown> = {}> {
|
|
|
207
207
|
ctx,
|
|
208
208
|
});
|
|
209
209
|
if (result?.action === 'stop') return;
|
|
210
|
-
} catch {
|
|
210
|
+
} catch (error) {
|
|
211
211
|
console.error(`[pipeline:${this.id}] handler failed`, {
|
|
212
|
+
error,
|
|
212
213
|
handlerId: handler.id ?? 'unknown',
|
|
213
214
|
handlerIndex: i,
|
|
214
215
|
});
|
package/src/api-client.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AxiosRequestConfig, AxiosResponse, Method } from 'axios';
|
|
2
|
-
import {
|
|
1
|
+
import type { AxiosError, AxiosRequestConfig, AxiosResponse, Method } from 'axios';
|
|
2
|
+
import { isAxiosError } from 'axios';
|
|
3
3
|
|
|
4
4
|
import type {
|
|
5
5
|
APIError,
|
|
@@ -147,11 +147,12 @@ export class ApiClient {
|
|
|
147
147
|
additonalConfig: AxiosRequestConfig,
|
|
148
148
|
): AxiosRequestConfig {
|
|
149
149
|
const token = this._getToken();
|
|
150
|
+
const axiosRequestConfig = this.client.config.getConfig('client')?.axiosRequestConfig;
|
|
150
151
|
|
|
151
152
|
return {
|
|
152
153
|
...additonalConfig,
|
|
153
154
|
headers: {
|
|
154
|
-
...
|
|
155
|
+
...axiosRequestConfig?.headers,
|
|
155
156
|
...additonalConfig.headers,
|
|
156
157
|
Authorization: token,
|
|
157
158
|
'stream-auth-type': this.client.getAuthType(),
|
|
@@ -162,9 +163,8 @@ export class ApiClient {
|
|
|
162
163
|
params: {
|
|
163
164
|
user_id: this.client.userId,
|
|
164
165
|
api_key: this.client.key,
|
|
165
|
-
//
|
|
166
|
-
|
|
167
|
-
...this.client.options.axiosRequestConfig?.params,
|
|
166
|
+
// Read per request, unlike the rest of `axiosRequestConfig`, which the axios instance took at construction.
|
|
167
|
+
...axiosRequestConfig?.params,
|
|
168
168
|
...additonalConfig.params,
|
|
169
169
|
},
|
|
170
170
|
} satisfies AxiosRequestConfig;
|
|
@@ -268,7 +268,7 @@ export class ApiClient {
|
|
|
268
268
|
delayBetweenRetries: (attemptNumber) => retryInterval(attemptNumber + 1),
|
|
269
269
|
retryAttempts: 10,
|
|
270
270
|
isRetryable: (error) => {
|
|
271
|
-
if (!(error
|
|
271
|
+
if (!isAxiosError(error)) return false;
|
|
272
272
|
|
|
273
273
|
if (error.status === 429 || isTokenExpiredError(error)) return true;
|
|
274
274
|
|
|
@@ -354,8 +354,14 @@ const toAxiosRequestConfig = ({
|
|
|
354
354
|
...(typeof timeout === 'number' ? { timeout } : {}),
|
|
355
355
|
});
|
|
356
356
|
|
|
357
|
+
/**
|
|
358
|
+
* `isAxiosError` checks the flag axios sets on its errors rather than `instanceof AxiosError`: an
|
|
359
|
+
* error raised by a second copy of axios (e.g. an adapter installed from another package's copy, as
|
|
360
|
+
* `stream-chat-react-native` does) is an instance of that copy's class, so `instanceof` misses it and
|
|
361
|
+
* the error would escape unwrapped, without its Stream `code`.
|
|
362
|
+
*/
|
|
357
363
|
const errorIsApiError = (error: unknown): error is AxiosError<APIError> => {
|
|
358
|
-
if (!(error
|
|
364
|
+
if (!isAxiosError(error)) return false;
|
|
359
365
|
|
|
360
366
|
return (
|
|
361
367
|
typeof (error as AxiosError<APIError | undefined>).response?.data?.code === 'number'
|
package/src/channel.ts
CHANGED
|
@@ -2414,6 +2414,15 @@ export class Channel extends ChannelApi {
|
|
|
2414
2414
|
.debug(`Received an event of type "${event.type}".`, { event });
|
|
2415
2415
|
|
|
2416
2416
|
const channelState = channel.state;
|
|
2417
|
+
|
|
2418
|
+
// The server unhides a channel on any new message without sending `channel.visible`.
|
|
2419
|
+
if (
|
|
2420
|
+
(event.type === 'message.new' || event.type === 'notification.message_new') &&
|
|
2421
|
+
channel.data?.hidden
|
|
2422
|
+
) {
|
|
2423
|
+
channel.data = { ...channel.data, hidden: false };
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2417
2426
|
switch (event.type) {
|
|
2418
2427
|
case 'typing.start':
|
|
2419
2428
|
if (event.user?.id) {
|
|
@@ -2710,6 +2719,7 @@ export class Channel extends ChannelApi {
|
|
|
2710
2719
|
}
|
|
2711
2720
|
break;
|
|
2712
2721
|
case 'channel.truncated': {
|
|
2722
|
+
if (event.channel) channel.data = { ...channel.data, ...event.channel };
|
|
2713
2723
|
const truncatedAt = event.channel?.truncated_at;
|
|
2714
2724
|
if (truncatedAt != null) {
|
|
2715
2725
|
this._setOwnUnreadCount(this.countUnread(truncatedAt));
|