stream-chat 9.50.2 → 10.0.0-rc.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 +18869 -13986
- package/dist/cjs/index.browser.js.map +4 -4
- package/dist/cjs/index.node.js +18888 -13992
- package/dist/cjs/index.node.js.map +4 -4
- package/dist/esm/index.mjs +18866 -13983
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/ChannelPaginatorsOrchestrator.d.ts +130 -0
- package/dist/types/EventHandlerPipeline.d.ts +104 -0
- package/dist/types/api-client.d.ts +26 -0
- package/dist/types/campaign.d.ts +0 -44
- package/dist/types/channel.d.ts +436 -480
- package/dist/types/channel_batch_updater.d.ts +0 -93
- package/dist/types/channel_manager.d.ts +8 -10
- package/dist/types/channel_state.d.ts +53 -201
- package/dist/types/client.d.ts +440 -1910
- package/dist/types/client_state.d.ts +4 -4
- package/dist/types/configuration/InstanceConfigurationService.d.ts +26 -0
- package/dist/types/configuration/index.d.ts +1 -0
- package/dist/types/configuration/types.d.ts +53 -0
- package/dist/types/connection.d.ts +49 -41
- package/dist/types/connection_fallback.d.ts +6 -4
- package/dist/types/constants.d.ts +0 -4
- package/dist/types/custom_types.d.ts +2 -0
- package/dist/types/errors.d.ts +2 -2
- package/dist/types/gen/chat/ChannelApi.d.ts +45 -0
- package/dist/types/gen/chat/ChatApi.d.ts +334 -0
- package/dist/types/gen/model-decoders/decoders.d.ts +3 -0
- package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts +6 -0
- package/dist/types/gen/models/index.d.ts +8836 -0
- package/dist/types/gen/moderation/ModerationApi.d.ts +50 -0
- package/dist/types/gen-imports.d.ts +3 -0
- package/dist/types/index.d.ts +5 -5
- package/dist/types/insights.d.ts +7 -6
- package/dist/types/logger.d.ts +9 -0
- package/dist/types/messageComposer/LocationComposer.d.ts +7 -4
- package/dist/types/messageComposer/attachmentIdentity.d.ts +2 -2
- package/dist/types/messageComposer/attachmentManager.d.ts +8 -4
- package/dist/types/messageComposer/configuration/types.d.ts +11 -11
- package/dist/types/messageComposer/linkPreviewsManager.d.ts +25 -13
- package/dist/types/messageComposer/messageComposer.d.ts +10 -10
- package/dist/types/messageComposer/middleware/messageComposer/types.d.ts +3 -3
- package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +4 -7
- package/dist/types/messageComposer/middleware/textComposer/commandUtils.d.ts +3 -3
- package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +7 -7
- package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +218 -4
- package/dist/types/messageComposer/middleware/textComposer/types.d.ts +9 -4
- package/dist/types/messageComposer/pollComposer.d.ts +5 -4
- package/dist/types/messageComposer/textComposer.d.ts +8 -3
- package/dist/types/messageComposer/types.d.ts +6 -28
- package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +40 -25
- package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +53 -12
- package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +19 -0
- package/dist/types/messageOperations/MessageOperations.d.ts +17 -0
- package/dist/types/messageOperations/index.d.ts +3 -0
- package/dist/types/messageOperations/types.d.ts +49 -0
- package/dist/types/moderation.d.ts +21 -203
- package/dist/types/notifications/types.d.ts +8 -7
- package/dist/types/offline-support/offline_support_api.d.ts +110 -87
- package/dist/types/offline-support/types.d.ts +19 -23
- package/dist/types/offline-support/util.d.ts +4 -2
- package/dist/types/pagination/FilterBuilder.d.ts +1 -1
- package/dist/types/pagination/ItemIndex.d.ts +82 -0
- package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +9 -0
- package/dist/types/pagination/cursorDerivation/idAroundPaginationFlags.d.ts +6 -0
- package/dist/types/pagination/cursorDerivation/index.d.ts +1 -0
- package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +6 -0
- package/dist/types/pagination/filterCompiler.d.ts +7 -0
- package/dist/types/pagination/index.d.ts +1 -3
- package/dist/types/pagination/paginators/BasePaginator.d.ts +709 -0
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +58 -0
- package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +260 -0
- package/dist/types/pagination/paginators/MessagePaginator.d.ts +208 -0
- package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +39 -0
- package/dist/types/pagination/paginators/ReminderPaginator.d.ts +19 -0
- package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +24 -0
- package/dist/types/pagination/paginators/index.d.ts +7 -0
- package/dist/types/pagination/sortCompiler.d.ts +49 -0
- package/dist/types/pagination/types.normalization.d.ts +11 -0
- package/dist/types/pagination/utility.normalization.d.ts +18 -0
- package/dist/types/pagination/utility.queryChannel.d.ts +26 -0
- package/dist/types/pagination/utility.search.d.ts +13 -0
- package/dist/types/permissions.d.ts +1 -1
- package/dist/types/poll.d.ts +29 -32
- package/dist/types/poll_manager.d.ts +2 -2
- package/dist/types/reminders/Reminder.d.ts +2 -5
- package/dist/types/reminders/ReminderManager.d.ts +2 -9
- package/dist/types/search/MessageSearchSource.d.ts +4 -4
- package/dist/types/search/UserSearchSource.d.ts +1 -1
- package/dist/types/search/types.d.ts +3 -3
- package/dist/types/segment.d.ts +0 -34
- package/dist/types/signing.d.ts +105 -65
- package/dist/types/store.d.ts +1 -0
- package/dist/types/thread.d.ts +51 -34
- package/dist/types/thread_manager.d.ts +3 -3
- package/dist/types/token_manager.d.ts +15 -10
- package/dist/types/types.d.ts +196 -3384
- package/dist/types/utils/FixedSizeQueueCache.d.ts +12 -6
- package/dist/types/utils/WithSubscriptions.d.ts +2 -1
- package/dist/types/utils/concurrency.d.ts +4 -4
- package/dist/types/utils/mergeWith/mergeWith.d.ts +3 -3
- package/dist/types/utils/mergeWith/mergeWithCore.d.ts +8 -3
- package/dist/types/utils/retryable.d.ts +34 -0
- package/dist/types/utils.d.ts +104 -137
- package/package.json +7 -3
- package/src/ChannelPaginatorsOrchestrator.ts +545 -0
- package/src/CooldownTimer.ts +2 -2
- package/src/EventHandlerPipeline.ts +228 -0
- package/src/LiveLocationManager.ts +12 -11
- package/src/api-client.ts +275 -0
- package/src/campaign.ts +1 -77
- package/src/channel.ts +1262 -1277
- package/src/channel_batch_updater.ts +1 -211
- package/src/channel_manager.ts +92 -88
- package/src/channel_state.ts +144 -1013
- package/src/client.ts +888 -3944
- package/src/client_state.ts +4 -4
- package/src/configuration/InstanceConfigurationService.ts +73 -0
- package/src/configuration/index.ts +1 -0
- package/src/configuration/types.ts +81 -0
- package/src/connection.ts +145 -94
- package/src/connection_fallback.ts +29 -27
- package/src/constants.ts +1 -5
- package/src/custom_types.ts +4 -1
- package/src/errors.ts +2 -2
- package/src/gen/chat/ChannelApi.ts +275 -0
- package/src/gen/chat/ChatApi.ts +2554 -0
- package/src/gen/model-decoders/decoders.ts +2680 -0
- package/src/gen/model-decoders/event-decoder-mapping.ts +198 -0
- package/src/gen/models/index.ts +12673 -0
- package/src/gen/moderation/ModerationApi.ts +607 -0
- package/src/gen-imports.ts +3 -0
- package/src/index.ts +5 -10
- package/src/insights.ts +6 -5
- package/src/logger.ts +28 -0
- package/src/messageComposer/LocationComposer.ts +9 -5
- package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -0
- package/src/messageComposer/attachmentIdentity.ts +16 -9
- package/src/messageComposer/attachmentManager.ts +13 -8
- package/src/messageComposer/configuration/types.ts +11 -11
- package/src/messageComposer/linkPreviewsManager.ts +9 -10
- package/src/messageComposer/messageComposer.ts +57 -53
- package/src/messageComposer/middleware/messageComposer/attachments.ts +1 -2
- package/src/messageComposer/middleware/messageComposer/cleanData.ts +1 -1
- package/src/messageComposer/middleware/messageComposer/compositionValidation.ts +2 -2
- package/src/messageComposer/middleware/messageComposer/messageComposerState.ts +2 -2
- package/src/messageComposer/middleware/messageComposer/sharedLocation.ts +4 -3
- package/src/messageComposer/middleware/messageComposer/textComposer.ts +2 -2
- package/src/messageComposer/middleware/messageComposer/types.ts +3 -4
- package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +9 -5
- package/src/messageComposer/middleware/pollComposer/state.ts +0 -2
- package/src/messageComposer/middleware/pollComposer/types.ts +4 -7
- package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +10 -1
- package/src/messageComposer/middleware/textComposer/commandEffects.ts +4 -4
- package/src/messageComposer/middleware/textComposer/commandUtils.ts +3 -6
- package/src/messageComposer/middleware/textComposer/commands.ts +3 -3
- package/src/messageComposer/middleware/textComposer/mentionUtils.ts +1 -1
- package/src/messageComposer/middleware/textComposer/mentions.ts +31 -15
- package/src/messageComposer/middleware/textComposer/types.ts +9 -4
- package/src/messageComposer/pollComposer.ts +6 -8
- package/src/messageComposer/textComposer.ts +27 -2
- package/src/messageComposer/types.ts +6 -28
- package/src/messageDelivery/MessageDeliveryReporter.ts +101 -45
- package/src/messageDelivery/MessageReceiptsTracker.ts +294 -21
- package/src/messageOperations/MessageOperationStatePolicy.ts +77 -0
- package/src/messageOperations/MessageOperations.ts +212 -0
- package/src/messageOperations/index.ts +10 -0
- package/src/messageOperations/types.ts +64 -0
- package/src/moderation.ts +38 -431
- package/src/notifications/types.ts +8 -7
- package/src/offline-support/offline_support_api.ts +198 -132
- package/src/offline-support/offline_sync_manager.ts +17 -7
- package/src/offline-support/types.ts +23 -26
- package/src/offline-support/util.ts +5 -4
- package/src/pagination/FilterBuilder.ts +4 -1
- package/src/pagination/ItemIndex.ts +112 -0
- package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +73 -0
- package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +53 -0
- package/src/pagination/cursorDerivation/index.ts +1 -0
- package/src/pagination/cursorDerivation/linearPaginationFlags.ts +86 -0
- package/src/pagination/filterCompiler.ts +196 -0
- package/src/pagination/index.ts +1 -3
- package/src/pagination/paginators/BasePaginator.ts +2393 -0
- package/src/pagination/paginators/ChannelPaginator.ts +427 -0
- package/src/pagination/paginators/MessageIntervalPaginator.ts +1073 -0
- package/src/pagination/paginators/MessagePaginator.ts +496 -0
- package/src/pagination/paginators/PinnedMessagePaginator.ts +105 -0
- package/src/pagination/paginators/ReminderPaginator.ts +105 -0
- package/src/pagination/paginators/UserGroupPaginator.ts +125 -0
- package/src/pagination/paginators/index.ts +7 -0
- package/src/pagination/sortCompiler.ts +178 -0
- package/src/pagination/types.normalization.ts +14 -0
- package/src/pagination/utility.normalization.ts +106 -0
- package/src/pagination/utility.queryChannel.ts +84 -0
- package/src/pagination/utility.search.ts +80 -0
- package/src/permissions.ts +7 -8
- package/src/poll.ts +101 -110
- package/src/poll_manager.ts +14 -8
- package/src/reminders/Reminder.ts +2 -5
- package/src/reminders/ReminderManager.ts +19 -21
- package/src/search/BaseSearchSource.ts +0 -3
- package/src/search/ChannelMemberSearchSource.ts +7 -1
- package/src/search/ChannelSearchSource.ts +10 -3
- package/src/search/MessageSearchSource.ts +29 -30
- package/src/search/UserSearchSource.ts +12 -8
- package/src/search/types.ts +3 -4
- package/src/segment.ts +1 -95
- package/src/signing.ts +107 -67
- package/src/store.ts +2 -1
- package/src/thread.ts +439 -236
- package/src/thread_manager.ts +36 -15
- package/src/token_manager.ts +21 -10
- package/src/types.ts +375 -4524
- package/src/uploadManager.ts +8 -0
- package/src/utils/FixedSizeQueueCache.ts +12 -6
- package/src/utils/WithSubscriptions.ts +2 -1
- package/src/utils/concurrency.ts +4 -4
- package/src/utils/mergeWith/mergeWith.ts +3 -3
- package/src/utils/mergeWith/mergeWithCore.ts +140 -164
- package/src/utils/mergeWith/mergeWithDiff.ts +3 -3
- package/src/utils/retryable.ts +117 -0
- package/src/utils.ts +133 -524
- package/dist/types/events.d.ts +0 -72
- package/dist/types/pagination/BasePaginator.d.ts +0 -69
- package/dist/types/pagination/ReminderPaginator.d.ts +0 -16
- package/dist/types/pagination/UserGroupPaginator.d.ts +0 -21
- package/src/events.ts +0 -75
- package/src/pagination/BasePaginator.ts +0 -184
- package/src/pagination/ReminderPaginator.ts +0 -56
- package/src/pagination/UserGroupPaginator.ts +0 -93
|
@@ -8,7 +8,11 @@ import {
|
|
|
8
8
|
sleep,
|
|
9
9
|
} from './utils';
|
|
10
10
|
import { isAPIError, isConnectionIDError, isErrorRetryable } from './errors';
|
|
11
|
-
import
|
|
11
|
+
import { chatLoggerSystem } from './logger';
|
|
12
|
+
import type { ConnectionOpen, UR } from './types';
|
|
13
|
+
import type { WSEvent } from './gen/models';
|
|
14
|
+
|
|
15
|
+
const logger = chatLoggerSystem.getLogger('connection-fallback');
|
|
12
16
|
|
|
13
17
|
export enum ConnectionState {
|
|
14
18
|
Closed = 'CLOSED',
|
|
@@ -33,15 +37,8 @@ export class WSConnectionFallback {
|
|
|
33
37
|
addConnectionEventListeners(this._onlineStatusChanged);
|
|
34
38
|
}
|
|
35
39
|
|
|
36
|
-
_log(msg: string, extra: UR = {}, level: LogLevel = 'info') {
|
|
37
|
-
this.client.logger(level, 'WSConnectionFallback:' + msg, {
|
|
38
|
-
tags: ['connection_fallback', 'connection'],
|
|
39
|
-
...extra,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
40
|
_setState(state: ConnectionState) {
|
|
44
|
-
|
|
41
|
+
logger.withExtraTags('_setState').debug(`Transitioning to state: ${state}.`);
|
|
45
42
|
|
|
46
43
|
// transition from connecting => connected
|
|
47
44
|
if (
|
|
@@ -60,7 +57,9 @@ export class WSConnectionFallback {
|
|
|
60
57
|
|
|
61
58
|
/** @private */
|
|
62
59
|
_onlineStatusChanged = (event: { type: string }) => {
|
|
63
|
-
|
|
60
|
+
logger
|
|
61
|
+
.withExtraTags('_onlineStatusChanged')
|
|
62
|
+
.info(`Network status changed to ${event.type}.`);
|
|
64
63
|
|
|
65
64
|
if (event.type === 'offline') {
|
|
66
65
|
this._setState(ConnectionState.Closed);
|
|
@@ -85,24 +84,22 @@ export class WSConnectionFallback {
|
|
|
85
84
|
}
|
|
86
85
|
|
|
87
86
|
try {
|
|
88
|
-
const res = await this.client.doAxiosRequest<T>(
|
|
87
|
+
const res = await this.client.api.doAxiosRequest<T>(
|
|
89
88
|
'get',
|
|
90
89
|
(this.client.baseURL as string).replace(':3030', ':8900') + '/longpoll', // replace port if present for testing with local API
|
|
91
90
|
undefined,
|
|
92
|
-
{
|
|
93
|
-
config: { ...config, cancelToken: this.cancelToken?.token },
|
|
94
|
-
params,
|
|
95
|
-
},
|
|
91
|
+
{ ...config, cancelToken: this.cancelToken?.token, params },
|
|
96
92
|
);
|
|
97
93
|
|
|
98
94
|
this.consecutiveFailures = 0; // always reset in case of no error
|
|
99
95
|
return res;
|
|
100
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
101
96
|
} catch (error: any) {
|
|
102
97
|
this.consecutiveFailures += 1;
|
|
103
98
|
|
|
104
99
|
if (retry && isErrorRetryable(error)) {
|
|
105
|
-
|
|
100
|
+
logger
|
|
101
|
+
.withExtraTags('_req')
|
|
102
|
+
.debug('Encountered a retryable error. Retrying the request.');
|
|
106
103
|
await sleep(retryInterval(this.consecutiveFailures));
|
|
107
104
|
return this._req<T>(params, config, retry);
|
|
108
105
|
}
|
|
@@ -116,7 +113,7 @@ export class WSConnectionFallback {
|
|
|
116
113
|
while (this.state === ConnectionState.Connected) {
|
|
117
114
|
try {
|
|
118
115
|
const data = await this._req<{
|
|
119
|
-
events:
|
|
116
|
+
events: WSEvent[];
|
|
120
117
|
}>({}, { timeout: 30000 }, true); // 30s => API responds in 20s if there is no event
|
|
121
118
|
|
|
122
119
|
if (data.events?.length) {
|
|
@@ -124,17 +121,18 @@ export class WSConnectionFallback {
|
|
|
124
121
|
this.client.dispatchEvent(data.events[i]);
|
|
125
122
|
}
|
|
126
123
|
}
|
|
127
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
128
124
|
} catch (error: any) {
|
|
129
125
|
if (axios.isCancel(error)) {
|
|
130
|
-
|
|
126
|
+
logger.withExtraTags('_poll').debug('Axios canceled the request.');
|
|
131
127
|
return;
|
|
132
128
|
}
|
|
133
129
|
|
|
134
130
|
/** client.doAxiosRequest will take care of TOKEN_EXPIRED error */
|
|
135
131
|
|
|
136
132
|
if (isConnectionIDError(error)) {
|
|
137
|
-
|
|
133
|
+
logger
|
|
134
|
+
.withExtraTags('_poll')
|
|
135
|
+
.warn('Received a connection ID error. Reconnecting without an ID.');
|
|
138
136
|
this._setState(ConnectionState.Disconnected);
|
|
139
137
|
this.connect(true);
|
|
140
138
|
return;
|
|
@@ -152,15 +150,20 @@ export class WSConnectionFallback {
|
|
|
152
150
|
|
|
153
151
|
/**
|
|
154
152
|
* connect try to open a longpoll request
|
|
155
|
-
*
|
|
153
|
+
*
|
|
154
|
+
* @param reconnect - should be false for first call and true for subsequent calls to keep the connection alive and call recoverState
|
|
156
155
|
*/
|
|
157
156
|
connect = async (reconnect = false) => {
|
|
158
157
|
if (this.state === ConnectionState.Connecting) {
|
|
159
|
-
|
|
158
|
+
logger
|
|
159
|
+
.withExtraTags('connect')
|
|
160
|
+
.warn('A connection attempt is already in progress.', { reconnect });
|
|
160
161
|
return;
|
|
161
162
|
}
|
|
162
163
|
if (this.state === ConnectionState.Connected) {
|
|
163
|
-
|
|
164
|
+
logger
|
|
165
|
+
.withExtraTags('connect')
|
|
166
|
+
.warn('Already connected and polling.', { reconnect });
|
|
164
167
|
return;
|
|
165
168
|
}
|
|
166
169
|
|
|
@@ -175,7 +178,6 @@ export class WSConnectionFallback {
|
|
|
175
178
|
|
|
176
179
|
this._setState(ConnectionState.Connected);
|
|
177
180
|
this.connectionID = event.connection_id;
|
|
178
|
-
// @ts-expect-error type mismatch
|
|
179
181
|
this.client.dispatchEvent(event);
|
|
180
182
|
this._poll();
|
|
181
183
|
if (reconnect) {
|
|
@@ -205,9 +207,9 @@ export class WSConnectionFallback {
|
|
|
205
207
|
|
|
206
208
|
try {
|
|
207
209
|
await this._req({ close: true, connection_id }, { timeout }, false);
|
|
208
|
-
|
|
210
|
+
logger.withExtraTags('disconnect').info('Closed the connection ID.');
|
|
209
211
|
} catch (err) {
|
|
210
|
-
|
|
212
|
+
logger.withExtraTags('disconnect').error('Disconnect failed.', { error: err });
|
|
211
213
|
}
|
|
212
214
|
};
|
|
213
215
|
}
|
package/src/constants.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
export const DEFAULT_QUERY_CHANNELS_MESSAGE_LIST_PAGE_SIZE = 25;
|
|
2
2
|
export const DEFAULT_QUERY_CHANNEL_MESSAGE_LIST_PAGE_SIZE = 100;
|
|
3
|
-
export const DEFAULT_MESSAGE_SET_PAGINATION = Object.freeze({
|
|
4
|
-
hasNext: false,
|
|
5
|
-
hasPrev: false,
|
|
6
|
-
});
|
|
7
3
|
export const DEFAULT_UPLOAD_SIZE_LIMIT_BYTES = 100 * 1024 * 1024; // 100 MB
|
|
8
4
|
export const API_MAX_FILES_ALLOWED_PER_MESSAGE = 10;
|
|
9
5
|
export const MAX_CHANNEL_MEMBER_COUNT_IN_CHANNEL_QUERY = 100;
|
|
@@ -23,7 +19,7 @@ export const RESERVED_UPDATED_MESSAGE_FIELDS = Object.freeze({
|
|
|
23
19
|
own_reactions: true,
|
|
24
20
|
reaction_counts: true,
|
|
25
21
|
reply_count: true,
|
|
26
|
-
//
|
|
22
|
+
// MessageRequest text related fields that shouldn't be in update
|
|
27
23
|
i18n: true,
|
|
28
24
|
type: true,
|
|
29
25
|
html: true,
|
package/src/custom_types.ts
CHANGED
package/src/errors.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AxiosResponse } from 'axios';
|
|
2
|
-
import type {
|
|
2
|
+
import type { APIError as Gen_APIError } from './types';
|
|
3
3
|
|
|
4
4
|
export const APIErrorCodes: Record<string, { name: string; retryable: boolean }> = {
|
|
5
5
|
'-1': { name: 'InternalSystemError', retryable: true },
|
|
@@ -66,6 +66,6 @@ export function isWSFailure(err: APIError): boolean {
|
|
|
66
66
|
|
|
67
67
|
export function isErrorResponse(
|
|
68
68
|
res: AxiosResponse<unknown>,
|
|
69
|
-
): res is AxiosResponse<
|
|
69
|
+
): res is AxiosResponse<Gen_APIError> {
|
|
70
70
|
return !res.status || res.status < 200 || 300 <= res.status;
|
|
71
71
|
}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import type { ChatApi, StreamResponse } from '../../gen-imports';
|
|
2
|
+
import type {
|
|
3
|
+
ChannelGetOrCreateRequest,
|
|
4
|
+
ChannelStateResponse,
|
|
5
|
+
ChannelStopWatchingRequest,
|
|
6
|
+
CreateDraftRequest,
|
|
7
|
+
CreateDraftResponse,
|
|
8
|
+
DeleteChannelResponse,
|
|
9
|
+
EventResponse,
|
|
10
|
+
GetDraftResponse,
|
|
11
|
+
GetManyMessagesResponse,
|
|
12
|
+
HideChannelRequest,
|
|
13
|
+
HideChannelResponse,
|
|
14
|
+
MarkReadRequest,
|
|
15
|
+
MarkReadResponse,
|
|
16
|
+
MarkUnreadRequest,
|
|
17
|
+
Response,
|
|
18
|
+
SendEventRequest,
|
|
19
|
+
SendMessageRequest,
|
|
20
|
+
SendMessageResponse,
|
|
21
|
+
ShowChannelRequest,
|
|
22
|
+
ShowChannelResponse,
|
|
23
|
+
TruncateChannelRequest,
|
|
24
|
+
TruncateChannelResponse,
|
|
25
|
+
UpdateChannelPartialRequest,
|
|
26
|
+
UpdateChannelPartialResponse,
|
|
27
|
+
UpdateChannelRequest,
|
|
28
|
+
UpdateChannelResponse,
|
|
29
|
+
UpdateMemberPartialRequest,
|
|
30
|
+
UpdateMemberPartialResponse,
|
|
31
|
+
UploadChannelFileRequest,
|
|
32
|
+
UploadChannelFileResponse,
|
|
33
|
+
UploadChannelRequest,
|
|
34
|
+
UploadChannelResponse,
|
|
35
|
+
} from '../models';
|
|
36
|
+
|
|
37
|
+
export class ChannelApi {
|
|
38
|
+
constructor(
|
|
39
|
+
protected chatApi: ChatApi,
|
|
40
|
+
public readonly type: string,
|
|
41
|
+
public id: string | undefined,
|
|
42
|
+
) {}
|
|
43
|
+
|
|
44
|
+
delete(request?: {
|
|
45
|
+
hard_delete?: boolean;
|
|
46
|
+
}): Promise<StreamResponse<DeleteChannelResponse>> {
|
|
47
|
+
if (!this.id) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return this.chatApi.deleteChannel({ id: this.id, type: this.type, ...request });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
updateChannelPartial(
|
|
57
|
+
request?: UpdateChannelPartialRequest,
|
|
58
|
+
): Promise<StreamResponse<UpdateChannelPartialResponse>> {
|
|
59
|
+
if (!this.id) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return this.chatApi.updateChannelPartial({
|
|
66
|
+
id: this.id,
|
|
67
|
+
type: this.type,
|
|
68
|
+
...request,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
update(request?: UpdateChannelRequest): Promise<StreamResponse<UpdateChannelResponse>> {
|
|
73
|
+
if (!this.id) {
|
|
74
|
+
throw new Error(
|
|
75
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return this.chatApi.updateChannel({ id: this.id, type: this.type, ...request });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
deleteDraft(request?: { parent_id?: string }): Promise<StreamResponse<Response>> {
|
|
83
|
+
if (!this.id) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return this.chatApi.deleteDraft({ id: this.id, type: this.type, ...request });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
getDraft(request?: { parent_id?: string }): Promise<StreamResponse<GetDraftResponse>> {
|
|
93
|
+
if (!this.id) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return this.chatApi.getDraft({ id: this.id, type: this.type, ...request });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
createDraft(request: CreateDraftRequest): Promise<StreamResponse<CreateDraftResponse>> {
|
|
103
|
+
if (!this.id) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return this.chatApi.createDraft({ id: this.id, type: this.type, ...request });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
sendEvent(request: SendEventRequest): Promise<StreamResponse<EventResponse>> {
|
|
113
|
+
if (!this.id) {
|
|
114
|
+
throw new Error(
|
|
115
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return this.chatApi.sendEvent({ id: this.id, type: this.type, ...request });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
deleteChannelFile(request?: { url?: string }): Promise<StreamResponse<Response>> {
|
|
123
|
+
if (!this.id) {
|
|
124
|
+
throw new Error(
|
|
125
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return this.chatApi.deleteChannelFile({ id: this.id, type: this.type, ...request });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
uploadChannelFile(
|
|
133
|
+
request?: UploadChannelFileRequest,
|
|
134
|
+
): Promise<StreamResponse<UploadChannelFileResponse>> {
|
|
135
|
+
if (!this.id) {
|
|
136
|
+
throw new Error(
|
|
137
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return this.chatApi.uploadChannelFile({ id: this.id, type: this.type, ...request });
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
hide(request?: HideChannelRequest): Promise<StreamResponse<HideChannelResponse>> {
|
|
145
|
+
if (!this.id) {
|
|
146
|
+
throw new Error(
|
|
147
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return this.chatApi.hideChannel({ id: this.id, type: this.type, ...request });
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
deleteChannelImage(request?: { url?: string }): Promise<StreamResponse<Response>> {
|
|
155
|
+
if (!this.id) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return this.chatApi.deleteChannelImage({ id: this.id, type: this.type, ...request });
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
uploadChannelImage(
|
|
165
|
+
request?: UploadChannelRequest,
|
|
166
|
+
): Promise<StreamResponse<UploadChannelResponse>> {
|
|
167
|
+
if (!this.id) {
|
|
168
|
+
throw new Error(
|
|
169
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return this.chatApi.uploadChannelImage({ id: this.id, type: this.type, ...request });
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
updateMemberPartial(
|
|
177
|
+
request?: UpdateMemberPartialRequest,
|
|
178
|
+
): Promise<StreamResponse<UpdateMemberPartialResponse>> {
|
|
179
|
+
if (!this.id) {
|
|
180
|
+
throw new Error(
|
|
181
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return this.chatApi.updateMemberPartial({ id: this.id, type: this.type, ...request });
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
sendMessage(request: SendMessageRequest): Promise<StreamResponse<SendMessageResponse>> {
|
|
189
|
+
if (!this.id) {
|
|
190
|
+
throw new Error(
|
|
191
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return this.chatApi.sendMessage({ id: this.id, type: this.type, ...request });
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
getManyMessages(request: {
|
|
199
|
+
ids: Array<string>;
|
|
200
|
+
}): Promise<StreamResponse<GetManyMessagesResponse>> {
|
|
201
|
+
if (!this.id) {
|
|
202
|
+
throw new Error(
|
|
203
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return this.chatApi.getManyMessages({ id: this.id, type: this.type, ...request });
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
getOrCreate(
|
|
211
|
+
request?: ChannelGetOrCreateRequest & { connection_id?: string },
|
|
212
|
+
): Promise<StreamResponse<ChannelStateResponse>> {
|
|
213
|
+
if (!this.id) {
|
|
214
|
+
throw new Error(
|
|
215
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return this.chatApi.getOrCreateChannel({ id: this.id, type: this.type, ...request });
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
markRead(request?: MarkReadRequest): Promise<StreamResponse<MarkReadResponse>> {
|
|
223
|
+
if (!this.id) {
|
|
224
|
+
throw new Error(
|
|
225
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return this.chatApi.markRead({ id: this.id, type: this.type, ...request });
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
show(request?: ShowChannelRequest): Promise<StreamResponse<ShowChannelResponse>> {
|
|
233
|
+
if (!this.id) {
|
|
234
|
+
throw new Error(
|
|
235
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return this.chatApi.showChannel({ id: this.id, type: this.type, ...request });
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
stopWatching(
|
|
243
|
+
request?: ChannelStopWatchingRequest & { connection_id?: string },
|
|
244
|
+
): Promise<StreamResponse<Response>> {
|
|
245
|
+
if (!this.id) {
|
|
246
|
+
throw new Error(
|
|
247
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return this.chatApi.stopWatchingChannel({ id: this.id, type: this.type, ...request });
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
truncate(
|
|
255
|
+
request?: TruncateChannelRequest,
|
|
256
|
+
): Promise<StreamResponse<TruncateChannelResponse>> {
|
|
257
|
+
if (!this.id) {
|
|
258
|
+
throw new Error(
|
|
259
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return this.chatApi.truncateChannel({ id: this.id, type: this.type, ...request });
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
markUnread(request?: MarkUnreadRequest): Promise<StreamResponse<Response>> {
|
|
267
|
+
if (!this.id) {
|
|
268
|
+
throw new Error(
|
|
269
|
+
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return this.chatApi.markUnread({ id: this.id, type: this.type, ...request });
|
|
274
|
+
}
|
|
275
|
+
}
|