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.
Files changed (229) hide show
  1. package/dist/cjs/index.browser.js +18869 -13986
  2. package/dist/cjs/index.browser.js.map +4 -4
  3. package/dist/cjs/index.node.js +18888 -13992
  4. package/dist/cjs/index.node.js.map +4 -4
  5. package/dist/esm/index.mjs +18866 -13983
  6. package/dist/esm/index.mjs.map +4 -4
  7. package/dist/types/ChannelPaginatorsOrchestrator.d.ts +130 -0
  8. package/dist/types/EventHandlerPipeline.d.ts +104 -0
  9. package/dist/types/api-client.d.ts +26 -0
  10. package/dist/types/campaign.d.ts +0 -44
  11. package/dist/types/channel.d.ts +436 -480
  12. package/dist/types/channel_batch_updater.d.ts +0 -93
  13. package/dist/types/channel_manager.d.ts +8 -10
  14. package/dist/types/channel_state.d.ts +53 -201
  15. package/dist/types/client.d.ts +440 -1910
  16. package/dist/types/client_state.d.ts +4 -4
  17. package/dist/types/configuration/InstanceConfigurationService.d.ts +26 -0
  18. package/dist/types/configuration/index.d.ts +1 -0
  19. package/dist/types/configuration/types.d.ts +53 -0
  20. package/dist/types/connection.d.ts +49 -41
  21. package/dist/types/connection_fallback.d.ts +6 -4
  22. package/dist/types/constants.d.ts +0 -4
  23. package/dist/types/custom_types.d.ts +2 -0
  24. package/dist/types/errors.d.ts +2 -2
  25. package/dist/types/gen/chat/ChannelApi.d.ts +45 -0
  26. package/dist/types/gen/chat/ChatApi.d.ts +334 -0
  27. package/dist/types/gen/model-decoders/decoders.d.ts +3 -0
  28. package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts +6 -0
  29. package/dist/types/gen/models/index.d.ts +8836 -0
  30. package/dist/types/gen/moderation/ModerationApi.d.ts +50 -0
  31. package/dist/types/gen-imports.d.ts +3 -0
  32. package/dist/types/index.d.ts +5 -5
  33. package/dist/types/insights.d.ts +7 -6
  34. package/dist/types/logger.d.ts +9 -0
  35. package/dist/types/messageComposer/LocationComposer.d.ts +7 -4
  36. package/dist/types/messageComposer/attachmentIdentity.d.ts +2 -2
  37. package/dist/types/messageComposer/attachmentManager.d.ts +8 -4
  38. package/dist/types/messageComposer/configuration/types.d.ts +11 -11
  39. package/dist/types/messageComposer/linkPreviewsManager.d.ts +25 -13
  40. package/dist/types/messageComposer/messageComposer.d.ts +10 -10
  41. package/dist/types/messageComposer/middleware/messageComposer/types.d.ts +3 -3
  42. package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +4 -7
  43. package/dist/types/messageComposer/middleware/textComposer/commandUtils.d.ts +3 -3
  44. package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +7 -7
  45. package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +218 -4
  46. package/dist/types/messageComposer/middleware/textComposer/types.d.ts +9 -4
  47. package/dist/types/messageComposer/pollComposer.d.ts +5 -4
  48. package/dist/types/messageComposer/textComposer.d.ts +8 -3
  49. package/dist/types/messageComposer/types.d.ts +6 -28
  50. package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +40 -25
  51. package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +53 -12
  52. package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +19 -0
  53. package/dist/types/messageOperations/MessageOperations.d.ts +17 -0
  54. package/dist/types/messageOperations/index.d.ts +3 -0
  55. package/dist/types/messageOperations/types.d.ts +49 -0
  56. package/dist/types/moderation.d.ts +21 -203
  57. package/dist/types/notifications/types.d.ts +8 -7
  58. package/dist/types/offline-support/offline_support_api.d.ts +110 -87
  59. package/dist/types/offline-support/types.d.ts +19 -23
  60. package/dist/types/offline-support/util.d.ts +4 -2
  61. package/dist/types/pagination/FilterBuilder.d.ts +1 -1
  62. package/dist/types/pagination/ItemIndex.d.ts +82 -0
  63. package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +9 -0
  64. package/dist/types/pagination/cursorDerivation/idAroundPaginationFlags.d.ts +6 -0
  65. package/dist/types/pagination/cursorDerivation/index.d.ts +1 -0
  66. package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +6 -0
  67. package/dist/types/pagination/filterCompiler.d.ts +7 -0
  68. package/dist/types/pagination/index.d.ts +1 -3
  69. package/dist/types/pagination/paginators/BasePaginator.d.ts +709 -0
  70. package/dist/types/pagination/paginators/ChannelPaginator.d.ts +58 -0
  71. package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +260 -0
  72. package/dist/types/pagination/paginators/MessagePaginator.d.ts +208 -0
  73. package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +39 -0
  74. package/dist/types/pagination/paginators/ReminderPaginator.d.ts +19 -0
  75. package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +24 -0
  76. package/dist/types/pagination/paginators/index.d.ts +7 -0
  77. package/dist/types/pagination/sortCompiler.d.ts +49 -0
  78. package/dist/types/pagination/types.normalization.d.ts +11 -0
  79. package/dist/types/pagination/utility.normalization.d.ts +18 -0
  80. package/dist/types/pagination/utility.queryChannel.d.ts +26 -0
  81. package/dist/types/pagination/utility.search.d.ts +13 -0
  82. package/dist/types/permissions.d.ts +1 -1
  83. package/dist/types/poll.d.ts +29 -32
  84. package/dist/types/poll_manager.d.ts +2 -2
  85. package/dist/types/reminders/Reminder.d.ts +2 -5
  86. package/dist/types/reminders/ReminderManager.d.ts +2 -9
  87. package/dist/types/search/MessageSearchSource.d.ts +4 -4
  88. package/dist/types/search/UserSearchSource.d.ts +1 -1
  89. package/dist/types/search/types.d.ts +3 -3
  90. package/dist/types/segment.d.ts +0 -34
  91. package/dist/types/signing.d.ts +105 -65
  92. package/dist/types/store.d.ts +1 -0
  93. package/dist/types/thread.d.ts +51 -34
  94. package/dist/types/thread_manager.d.ts +3 -3
  95. package/dist/types/token_manager.d.ts +15 -10
  96. package/dist/types/types.d.ts +196 -3384
  97. package/dist/types/utils/FixedSizeQueueCache.d.ts +12 -6
  98. package/dist/types/utils/WithSubscriptions.d.ts +2 -1
  99. package/dist/types/utils/concurrency.d.ts +4 -4
  100. package/dist/types/utils/mergeWith/mergeWith.d.ts +3 -3
  101. package/dist/types/utils/mergeWith/mergeWithCore.d.ts +8 -3
  102. package/dist/types/utils/retryable.d.ts +34 -0
  103. package/dist/types/utils.d.ts +104 -137
  104. package/package.json +7 -3
  105. package/src/ChannelPaginatorsOrchestrator.ts +545 -0
  106. package/src/CooldownTimer.ts +2 -2
  107. package/src/EventHandlerPipeline.ts +228 -0
  108. package/src/LiveLocationManager.ts +12 -11
  109. package/src/api-client.ts +275 -0
  110. package/src/campaign.ts +1 -77
  111. package/src/channel.ts +1262 -1277
  112. package/src/channel_batch_updater.ts +1 -211
  113. package/src/channel_manager.ts +92 -88
  114. package/src/channel_state.ts +144 -1013
  115. package/src/client.ts +888 -3944
  116. package/src/client_state.ts +4 -4
  117. package/src/configuration/InstanceConfigurationService.ts +73 -0
  118. package/src/configuration/index.ts +1 -0
  119. package/src/configuration/types.ts +81 -0
  120. package/src/connection.ts +145 -94
  121. package/src/connection_fallback.ts +29 -27
  122. package/src/constants.ts +1 -5
  123. package/src/custom_types.ts +4 -1
  124. package/src/errors.ts +2 -2
  125. package/src/gen/chat/ChannelApi.ts +275 -0
  126. package/src/gen/chat/ChatApi.ts +2554 -0
  127. package/src/gen/model-decoders/decoders.ts +2680 -0
  128. package/src/gen/model-decoders/event-decoder-mapping.ts +198 -0
  129. package/src/gen/models/index.ts +12673 -0
  130. package/src/gen/moderation/ModerationApi.ts +607 -0
  131. package/src/gen-imports.ts +3 -0
  132. package/src/index.ts +5 -10
  133. package/src/insights.ts +6 -5
  134. package/src/logger.ts +28 -0
  135. package/src/messageComposer/LocationComposer.ts +9 -5
  136. package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -0
  137. package/src/messageComposer/attachmentIdentity.ts +16 -9
  138. package/src/messageComposer/attachmentManager.ts +13 -8
  139. package/src/messageComposer/configuration/types.ts +11 -11
  140. package/src/messageComposer/linkPreviewsManager.ts +9 -10
  141. package/src/messageComposer/messageComposer.ts +57 -53
  142. package/src/messageComposer/middleware/messageComposer/attachments.ts +1 -2
  143. package/src/messageComposer/middleware/messageComposer/cleanData.ts +1 -1
  144. package/src/messageComposer/middleware/messageComposer/compositionValidation.ts +2 -2
  145. package/src/messageComposer/middleware/messageComposer/messageComposerState.ts +2 -2
  146. package/src/messageComposer/middleware/messageComposer/sharedLocation.ts +4 -3
  147. package/src/messageComposer/middleware/messageComposer/textComposer.ts +2 -2
  148. package/src/messageComposer/middleware/messageComposer/types.ts +3 -4
  149. package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +9 -5
  150. package/src/messageComposer/middleware/pollComposer/state.ts +0 -2
  151. package/src/messageComposer/middleware/pollComposer/types.ts +4 -7
  152. package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +10 -1
  153. package/src/messageComposer/middleware/textComposer/commandEffects.ts +4 -4
  154. package/src/messageComposer/middleware/textComposer/commandUtils.ts +3 -6
  155. package/src/messageComposer/middleware/textComposer/commands.ts +3 -3
  156. package/src/messageComposer/middleware/textComposer/mentionUtils.ts +1 -1
  157. package/src/messageComposer/middleware/textComposer/mentions.ts +31 -15
  158. package/src/messageComposer/middleware/textComposer/types.ts +9 -4
  159. package/src/messageComposer/pollComposer.ts +6 -8
  160. package/src/messageComposer/textComposer.ts +27 -2
  161. package/src/messageComposer/types.ts +6 -28
  162. package/src/messageDelivery/MessageDeliveryReporter.ts +101 -45
  163. package/src/messageDelivery/MessageReceiptsTracker.ts +294 -21
  164. package/src/messageOperations/MessageOperationStatePolicy.ts +77 -0
  165. package/src/messageOperations/MessageOperations.ts +212 -0
  166. package/src/messageOperations/index.ts +10 -0
  167. package/src/messageOperations/types.ts +64 -0
  168. package/src/moderation.ts +38 -431
  169. package/src/notifications/types.ts +8 -7
  170. package/src/offline-support/offline_support_api.ts +198 -132
  171. package/src/offline-support/offline_sync_manager.ts +17 -7
  172. package/src/offline-support/types.ts +23 -26
  173. package/src/offline-support/util.ts +5 -4
  174. package/src/pagination/FilterBuilder.ts +4 -1
  175. package/src/pagination/ItemIndex.ts +112 -0
  176. package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +73 -0
  177. package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +53 -0
  178. package/src/pagination/cursorDerivation/index.ts +1 -0
  179. package/src/pagination/cursorDerivation/linearPaginationFlags.ts +86 -0
  180. package/src/pagination/filterCompiler.ts +196 -0
  181. package/src/pagination/index.ts +1 -3
  182. package/src/pagination/paginators/BasePaginator.ts +2393 -0
  183. package/src/pagination/paginators/ChannelPaginator.ts +427 -0
  184. package/src/pagination/paginators/MessageIntervalPaginator.ts +1073 -0
  185. package/src/pagination/paginators/MessagePaginator.ts +496 -0
  186. package/src/pagination/paginators/PinnedMessagePaginator.ts +105 -0
  187. package/src/pagination/paginators/ReminderPaginator.ts +105 -0
  188. package/src/pagination/paginators/UserGroupPaginator.ts +125 -0
  189. package/src/pagination/paginators/index.ts +7 -0
  190. package/src/pagination/sortCompiler.ts +178 -0
  191. package/src/pagination/types.normalization.ts +14 -0
  192. package/src/pagination/utility.normalization.ts +106 -0
  193. package/src/pagination/utility.queryChannel.ts +84 -0
  194. package/src/pagination/utility.search.ts +80 -0
  195. package/src/permissions.ts +7 -8
  196. package/src/poll.ts +101 -110
  197. package/src/poll_manager.ts +14 -8
  198. package/src/reminders/Reminder.ts +2 -5
  199. package/src/reminders/ReminderManager.ts +19 -21
  200. package/src/search/BaseSearchSource.ts +0 -3
  201. package/src/search/ChannelMemberSearchSource.ts +7 -1
  202. package/src/search/ChannelSearchSource.ts +10 -3
  203. package/src/search/MessageSearchSource.ts +29 -30
  204. package/src/search/UserSearchSource.ts +12 -8
  205. package/src/search/types.ts +3 -4
  206. package/src/segment.ts +1 -95
  207. package/src/signing.ts +107 -67
  208. package/src/store.ts +2 -1
  209. package/src/thread.ts +439 -236
  210. package/src/thread_manager.ts +36 -15
  211. package/src/token_manager.ts +21 -10
  212. package/src/types.ts +375 -4524
  213. package/src/uploadManager.ts +8 -0
  214. package/src/utils/FixedSizeQueueCache.ts +12 -6
  215. package/src/utils/WithSubscriptions.ts +2 -1
  216. package/src/utils/concurrency.ts +4 -4
  217. package/src/utils/mergeWith/mergeWith.ts +3 -3
  218. package/src/utils/mergeWith/mergeWithCore.ts +140 -164
  219. package/src/utils/mergeWith/mergeWithDiff.ts +3 -3
  220. package/src/utils/retryable.ts +117 -0
  221. package/src/utils.ts +133 -524
  222. package/dist/types/events.d.ts +0 -72
  223. package/dist/types/pagination/BasePaginator.d.ts +0 -69
  224. package/dist/types/pagination/ReminderPaginator.d.ts +0 -16
  225. package/dist/types/pagination/UserGroupPaginator.d.ts +0 -21
  226. package/src/events.ts +0 -75
  227. package/src/pagination/BasePaginator.ts +0 -184
  228. package/src/pagination/ReminderPaginator.ts +0 -56
  229. 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 type { ConnectionOpen, Event, LogLevel, UR } from './types';
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
- this._log(`_setState() - ${state}`);
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
- this._log(`_onlineStatusChanged() - ${event.type}`);
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
- this._log(`_req() - Retryable error, retrying request`);
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: Event[];
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
- this._log(`_poll() - axios canceled request`);
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
- this._log(`_poll() - ConnectionID error, connecting without ID...`);
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
- * @param reconnect should be false for first call and true for subsequent calls to keep the connection alive and call recoverState
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
- this._log('connect() - connecting already in progress', { reconnect }, 'warn');
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
- this._log('connect() - already connected and polling', { reconnect }, 'warn');
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
- this._log(`disconnect() - Closed connectionID`);
210
+ logger.withExtraTags('disconnect').info('Closed the connection ID.');
209
211
  } catch (err) {
210
- this._log(`disconnect() - Failed`, { err }, 'error');
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
- // Message text related fields that shouldn't be in update
22
+ // MessageRequest text related fields that shouldn't be in update
27
23
  i18n: true,
28
24
  type: true,
29
25
  html: true,
@@ -1,4 +1,7 @@
1
- export interface CustomAttachmentData {}
1
+ export interface CustomAttachmentData {
2
+ mime_type?: string;
3
+ file_size?: number;
4
+ }
2
5
  export interface CustomChannelData {}
3
6
  export interface CustomCommandData {}
4
7
  export interface CustomEventData {}
package/src/errors.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { AxiosResponse } from 'axios';
2
- import type { APIErrorResponse } from './types';
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<APIErrorResponse> {
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
+ }