stream-chat 10.0.0-rc.21 → 10.0.0-rc.23
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 +2196 -3902
- package/dist/cjs/index.browser.js.map +3 -3
- package/dist/cjs/index.node.js +2197 -3902
- package/dist/cjs/index.node.js.map +3 -3
- package/dist/esm/index.mjs +2199 -3905
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/ChannelManager.d.ts +120 -233
- package/dist/types/CooldownTimer.d.ts +8 -23
- package/dist/types/EventHandlerPipeline.d.ts +17 -37
- package/dist/types/LiveLocationManager.d.ts +22 -50
- package/dist/types/api-client.d.ts +9 -14
- package/dist/types/channel.d.ts +253 -448
- package/dist/types/channel_state.d.ts +48 -95
- package/dist/types/client.d.ts +245 -370
- package/dist/types/client_state.d.ts +1 -3
- package/dist/types/configuration/ConfigController.d.ts +30 -124
- package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +31 -123
- package/dist/types/configuration/keys.d.ts +5 -19
- package/dist/types/configuration/shape.d.ts +12 -29
- package/dist/types/configuration/types.d.ts +59 -87
- package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +13 -35
- package/dist/types/configuration/utils/copyConfigPatch.d.ts +8 -0
- package/dist/types/configuration/utils/declarativeSlices.d.ts +5 -16
- package/dist/types/configuration/utils/deepFreezeConfig.d.ts +3 -17
- package/dist/types/configuration/utils/serverAuthority.d.ts +9 -29
- package/dist/types/connection/ConnectionIdManager.d.ts +18 -40
- package/dist/types/connection/ConnectionRecoveryManager.d.ts +29 -120
- package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +32 -103
- package/dist/types/connection/networkConnection/reporters.d.ts +9 -32
- package/dist/types/connection/networkConnection/types.d.ts +12 -27
- package/dist/types/connection/wsConnection/StableWSConnection.d.ts +37 -116
- package/dist/types/connection/wsConnection/WSConnection.d.ts +41 -104
- package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +8 -16
- package/dist/types/connection/wsConnection/config.d.ts +8 -28
- package/dist/types/connection/wsConnection/types.d.ts +17 -70
- package/dist/types/entityStore/EntityStore.d.ts +153 -113
- package/dist/types/entityStore/StoreBackedItemIndex.d.ts +13 -46
- package/dist/types/errors.d.ts +7 -19
- package/dist/types/gen/chat/ChannelApi.d.ts +2 -1
- package/dist/types/gen/chat/ChatApi.d.ts +28 -14
- package/dist/types/gen/models/index.d.ts +769 -86
- package/dist/types/gen/moderation/ModerationApi.d.ts +4 -4
- package/dist/types/index.d.ts +2 -4
- package/dist/types/languageNames.d.ts +9 -24
- package/dist/types/logger.d.ts +1 -3
- package/dist/types/messageComposer/LocationComposer.d.ts +1 -1
- package/dist/types/messageComposer/attachmentIdentity.d.ts +1 -6
- package/dist/types/messageComposer/attachmentManager.d.ts +10 -32
- package/dist/types/messageComposer/attachmentUtils.d.ts +3 -14
- package/dist/types/messageComposer/configuration/configuration.d.ts +2 -5
- package/dist/types/messageComposer/configuration/types.d.ts +29 -56
- package/dist/types/messageComposer/linkPreviewsManager.d.ts +6 -9
- package/dist/types/messageComposer/messageComposer.d.ts +30 -164
- package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +4 -14
- package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +2 -9
- package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +2 -4
- package/dist/types/messageComposer/middleware/pollComposer/validation.d.ts +7 -19
- package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +9 -0
- package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +11 -18
- package/dist/types/messageComposer/middleware/textComposer/textMiddlewareUtils.d.ts +9 -3
- package/dist/types/messageComposer/middleware/textComposer/types.d.ts +1 -6
- package/dist/types/messageComposer/pollComposer.d.ts +8 -4
- package/dist/types/messageComposer/textComposer.d.ts +3 -9
- package/dist/types/messageComposer/types.d.ts +5 -8
- package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +25 -79
- package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +15 -82
- package/dist/types/messageOperations/FailedSendCache.d.ts +4 -9
- package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +10 -20
- package/dist/types/messageOperations/MessageOperations.d.ts +20 -40
- package/dist/types/messageOperations/applyReactionLocally.d.ts +5 -22
- package/dist/types/messageOperations/createMessageOperations.d.ts +3 -5
- package/dist/types/messageOperations/reflectReactionEvent.d.ts +5 -13
- package/dist/types/messageOperations/sendOrdering.d.ts +4 -7
- package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +7 -15
- package/dist/types/messageOperations/types.d.ts +15 -30
- package/dist/types/middleware.d.ts +7 -5
- package/dist/types/moderation.d.ts +21 -14
- package/dist/types/notifications/NotificationManager.d.ts +8 -31
- package/dist/types/notifications/types.d.ts +19 -59
- package/dist/types/offline-support/offline_support_api.d.ts +145 -539
- package/dist/types/offline-support/offline_sync_manager.d.ts +18 -42
- package/dist/types/offline-support/queueableOperations.d.ts +24 -52
- package/dist/types/offline-support/types.d.ts +24 -187
- package/dist/types/pagination/ItemIndex.d.ts +4 -12
- package/dist/types/pagination/cursorDerivation/aroundPaginationFlags.d.ts +13 -0
- package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +2 -4
- package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +2 -3
- package/dist/types/pagination/paginators/BasePaginator.d.ts +235 -622
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +67 -125
- package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +133 -292
- package/dist/types/pagination/paginators/MessagePaginator.d.ts +69 -118
- package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +7 -26
- package/dist/types/pagination/paginators/ReminderPaginator.d.ts +2 -2
- package/dist/types/pagination/paginators/ThreadPaginator.d.ts +15 -23
- package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +2 -6
- package/dist/types/pagination/sortCompiler.d.ts +11 -22
- package/dist/types/pagination/utility.normalization.d.ts +5 -23
- package/dist/types/pagination/utility.search.d.ts +3 -8
- package/dist/types/poll.d.ts +14 -14
- package/dist/types/poll_manager.d.ts +11 -2
- package/dist/types/poll_optimistic_votes.d.ts +10 -14
- package/dist/types/reminders/Reminder.d.ts +4 -4
- package/dist/types/reminders/ReminderManager.d.ts +7 -20
- package/dist/types/search/BaseSearchSource.d.ts +7 -12
- package/dist/types/search/ChannelSearchSource.d.ts +7 -7
- package/dist/types/search/MessageSearchSource.d.ts +7 -9
- package/dist/types/search/SearchController.d.ts +17 -22
- package/dist/types/search/types.d.ts +6 -10
- package/dist/types/signing.d.ts +12 -3
- package/dist/types/thread.d.ts +23 -71
- package/dist/types/thread_manager.d.ts +45 -70
- package/dist/types/token_manager.d.ts +8 -13
- package/dist/types/types.d.ts +64 -125
- package/dist/types/types.utility.d.ts +3 -3
- package/dist/types/upload-utils.d.ts +5 -10
- package/dist/types/uploadManager.d.ts +17 -45
- package/dist/types/utils/FixedSizeQueueCache.d.ts +6 -11
- package/dist/types/utils/WithSubscriptions.d.ts +5 -15
- package/dist/types/utils/concurrency.d.ts +11 -19
- package/dist/types/utils/mergeWith/mergeWith.d.ts +8 -11
- package/dist/types/utils/mergeWith/mergeWithCore.d.ts +5 -13
- package/dist/types/utils/mergeWith/mergeWithDiff.d.ts +22 -0
- package/dist/types/utils/objectPath.d.ts +6 -41
- package/dist/types/utils/retryable.d.ts +8 -12
- package/dist/types/utils/throttling/throttle.d.ts +8 -23
- package/dist/types/utils/time.d.ts +24 -64
- package/dist/types/utils.d.ts +40 -86
- package/package.json +7 -2
- package/src/ChannelManager.ts +159 -300
- package/src/CooldownTimer.ts +11 -29
- package/src/EventHandlerPipeline.ts +21 -44
- package/src/LiveLocationManager.ts +35 -74
- package/src/api-client.ts +43 -61
- package/src/campaign.ts +1 -1
- package/src/channel.ts +396 -749
- package/src/channel_batch_updater.ts +1 -1
- package/src/channel_state.ts +50 -105
- package/src/client.ts +360 -588
- package/src/client_state.ts +1 -6
- package/src/configuration/ConfigController.ts +41 -157
- package/src/configuration/InstanceConfigurationRegistry.ts +42 -171
- package/src/configuration/index.ts +1 -1
- package/src/configuration/keys.ts +13 -32
- package/src/configuration/shape.ts +67 -70
- package/src/configuration/types.ts +60 -100
- package/src/configuration/utils/applyInstanceConfiguration.ts +21 -53
- package/src/configuration/utils/copyConfigPatch.ts +11 -32
- package/src/configuration/utils/declarativeSlices.ts +9 -39
- package/src/configuration/utils/deepFreezeConfig.ts +3 -17
- package/src/configuration/utils/index.ts +2 -4
- package/src/configuration/utils/serverAuthority.ts +20 -68
- package/src/connection/ConnectionIdManager.ts +20 -49
- package/src/connection/ConnectionRecoveryManager.ts +51 -178
- package/src/connection/networkConnection/NetworkConnectionObserver.ts +37 -114
- package/src/connection/networkConnection/reporters.ts +9 -36
- package/src/connection/networkConnection/types.ts +12 -27
- package/src/connection/wsConnection/StableWSConnection.ts +73 -193
- package/src/connection/wsConnection/WSConnection.ts +56 -131
- package/src/connection/wsConnection/WSConnectionFallback.ts +22 -31
- package/src/connection/wsConnection/config.ts +13 -48
- package/src/connection/wsConnection/types.ts +17 -70
- package/src/constants.ts +4 -4
- package/src/entityStore/EntityStore.ts +162 -167
- package/src/entityStore/StoreBackedItemIndex.ts +14 -47
- package/src/errors.ts +7 -19
- package/src/formatMessageMemo.ts +3 -9
- package/src/gen/chat/ChannelApi.ts +19 -0
- package/src/gen/chat/ChatApi.ts +87 -13
- package/src/gen/models/index.ts +793 -71
- package/src/gen/moderation/ModerationApi.ts +0 -4
- package/src/index.ts +10 -14
- package/src/languageNames.ts +9 -24
- package/src/logger.ts +1 -3
- package/src/messageComposer/LocationComposer.ts +7 -23
- package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -2
- package/src/messageComposer/attachmentIdentity.ts +2 -13
- package/src/messageComposer/attachmentManager.ts +17 -63
- package/src/messageComposer/attachmentUtils.ts +3 -17
- package/src/messageComposer/configuration/configuration.ts +5 -8
- package/src/messageComposer/configuration/types.ts +29 -56
- package/src/messageComposer/fileUtils.ts +1 -1
- package/src/messageComposer/linkPreviewsManager.ts +8 -20
- package/src/messageComposer/messageComposer.ts +54 -222
- package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +4 -16
- package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +1 -2
- package/src/messageComposer/middleware/messageComposer/attachments.ts +14 -40
- package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +3 -4
- package/src/messageComposer/middleware/messageComposer/textComposer.ts +1 -1
- package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +4 -11
- package/src/messageComposer/middleware/pollComposer/state.ts +2 -2
- package/src/messageComposer/middleware/pollComposer/types.ts +2 -4
- package/src/messageComposer/middleware/pollComposer/validation.ts +8 -26
- package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +1 -6
- package/src/messageComposer/middleware/textComposer/commandUtils.ts +1 -2
- package/src/messageComposer/middleware/textComposer/commands.ts +11 -16
- package/src/messageComposer/middleware/textComposer/mentions.ts +32 -70
- package/src/messageComposer/middleware/textComposer/textMiddlewareUtils.ts +10 -4
- package/src/messageComposer/middleware/textComposer/types.ts +1 -6
- package/src/messageComposer/pollComposer.ts +11 -8
- package/src/messageComposer/textComposer.ts +9 -59
- package/src/messageComposer/types.ts +9 -12
- package/src/messageDelivery/MessageDeliveryReporter.ts +60 -113
- package/src/messageDelivery/MessageReceiptsTracker.ts +21 -105
- package/src/messageOperations/FailedSendCache.ts +4 -9
- package/src/messageOperations/MessageOperationStatePolicy.ts +40 -67
- package/src/messageOperations/MessageOperations.ts +33 -62
- package/src/messageOperations/applyReactionLocally.ts +9 -28
- package/src/messageOperations/createMessageOperations.ts +17 -33
- package/src/messageOperations/reflectReactionEvent.ts +5 -13
- package/src/messageOperations/sendOrdering.ts +4 -7
- package/src/messageOperations/settlePendingAttachmentUploads.ts +10 -21
- package/src/messageOperations/types.ts +15 -30
- package/src/middleware.ts +7 -10
- package/src/moderation.ts +25 -21
- package/src/notifications/NotificationManager.ts +11 -35
- package/src/notifications/types.ts +19 -59
- package/src/offline-support/offline_support_api.ts +178 -608
- package/src/offline-support/offline_sync_manager.ts +25 -69
- package/src/offline-support/queueableOperations.ts +31 -84
- package/src/offline-support/types.ts +25 -188
- package/src/pagination/ItemIndex.ts +4 -12
- package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +29 -0
- package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +13 -62
- package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
- package/src/pagination/cursorDerivation/linearPaginationFlags.ts +4 -6
- package/src/pagination/filterCompiler.ts +11 -25
- package/src/pagination/paginators/BasePaginator.ts +422 -976
- package/src/pagination/paginators/ChannelPaginator.ts +130 -190
- package/src/pagination/paginators/MessageIntervalPaginator.ts +226 -457
- package/src/pagination/paginators/MessagePaginator.ts +135 -175
- package/src/pagination/paginators/PinnedMessagePaginator.ts +13 -38
- package/src/pagination/paginators/ReminderPaginator.ts +12 -15
- package/src/pagination/paginators/ThreadPaginator.ts +16 -26
- package/src/pagination/paginators/UserGroupPaginator.ts +6 -17
- package/src/pagination/paginators/stateThrottling.ts +5 -10
- package/src/pagination/sortCompiler.ts +23 -50
- package/src/pagination/utility.normalization.ts +8 -30
- package/src/pagination/utility.search.ts +4 -11
- package/src/poll.ts +19 -19
- package/src/poll_manager.ts +16 -20
- package/src/poll_optimistic_votes.ts +17 -22
- package/src/reminders/Reminder.ts +5 -6
- package/src/reminders/ReminderManager.ts +9 -34
- package/src/reminders/ReminderTimer.ts +1 -2
- package/src/search/BaseSearchSource.ts +14 -29
- package/src/search/ChannelSearchSource.ts +8 -8
- package/src/search/MessageSearchSource.ts +19 -25
- package/src/search/SearchController.ts +18 -24
- package/src/search/types.ts +6 -10
- package/src/segment.ts +1 -1
- package/src/signing.ts +23 -3
- package/src/thread.ts +72 -173
- package/src/thread_manager.ts +59 -76
- package/src/token_manager.ts +11 -21
- package/src/types.ts +78 -126
- package/src/types.utility.ts +3 -3
- package/src/upload-utils.ts +5 -10
- package/src/uploadManager.ts +22 -54
- package/src/utils/FixedSizeQueueCache.ts +13 -21
- package/src/utils/WithSubscriptions.ts +5 -15
- package/src/utils/concurrency.ts +16 -55
- package/src/utils/mergeWith/mergeWith.ts +10 -13
- package/src/utils/mergeWith/mergeWithCore.ts +24 -81
- package/src/utils/mergeWith/mergeWithDiff.ts +15 -33
- package/src/utils/objectPath.ts +6 -41
- package/src/utils/retryable.ts +10 -14
- package/src/utils/throttling/throttle.ts +9 -25
- package/src/utils/time.ts +26 -66
- package/src/utils.ts +72 -128
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,
|
|
@@ -23,15 +23,11 @@ const MULTIPART_CONTENT_TYPE = 'multipart/form-data';
|
|
|
23
23
|
const LONG_POLL_PATH = '/api/v2/longpoll';
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
* caps - either would abort a large or slow upload.
|
|
26
|
+
* Uploads must not inherit the axios instance timeout (3s by default) or the size caps.
|
|
28
27
|
*
|
|
29
|
-
* The
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* integrator's global `axiosRequestConfig.headers`. If that precedence is ever reversed, an
|
|
33
|
-
* upload turns into `JSON.stringify(formDataToJSON(form))` - the file silently disappears and
|
|
34
|
-
* the request still returns 2xx.
|
|
28
|
+
* The request's `multipart/form-data` header must win over the global `axiosRequestConfig.headers`
|
|
29
|
+
* (see `populateRequestConfigWithDefaults`): under a JSON content type axios serializes the form to
|
|
30
|
+
* JSON, the file silently disappears and the request still returns 2xx.
|
|
35
31
|
*/
|
|
36
32
|
const UPLOAD_REQUEST_DEFAULTS: AxiosRequestConfig = {
|
|
37
33
|
timeout: 0,
|
|
@@ -51,11 +47,9 @@ export class ApiClient {
|
|
|
51
47
|
}
|
|
52
48
|
|
|
53
49
|
/**
|
|
54
|
-
* The transport of the generated API classes
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* `async` so that a synchronous throw here (URL resolution, form encoding) still reaches the
|
|
58
|
-
* caller as a rejection - the generated methods return this promise without awaiting it.
|
|
50
|
+
* The transport of the generated API classes. Resolves to the response body with the request's
|
|
51
|
+
* `metadata` merged in. `async` so synchronous throws (URL resolution, form encoding) become
|
|
52
|
+
* rejections.
|
|
59
53
|
*/
|
|
60
54
|
async sendRequest<T>(
|
|
61
55
|
method: Method,
|
|
@@ -78,8 +72,7 @@ export class ApiClient {
|
|
|
78
72
|
params: queryParams,
|
|
79
73
|
headers: { 'Content-Type': requestContentType },
|
|
80
74
|
...(isMultipart ? UPLOAD_REQUEST_DEFAULTS : {}),
|
|
81
|
-
//
|
|
82
|
-
// the keys it owns, so it can never clobber the upload defaults above.
|
|
75
|
+
// Last, so a caller-supplied signal and timeout win over the upload defaults.
|
|
83
76
|
...toAxiosRequestConfig(options),
|
|
84
77
|
});
|
|
85
78
|
|
|
@@ -115,15 +108,12 @@ export class ApiClient {
|
|
|
115
108
|
return this._doRequest<T>('delete', url, null, { params }).then((r) => r.body);
|
|
116
109
|
}
|
|
117
110
|
|
|
118
|
-
// --- private ---
|
|
119
|
-
|
|
120
111
|
private resolveUrl(url: string, pathParams?: Record<string, string>): string {
|
|
121
112
|
let resolved = url;
|
|
122
113
|
if (pathParams) {
|
|
123
114
|
for (const [key, value] of Object.entries(pathParams)) {
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
// request would otherwise drop without a word.
|
|
115
|
+
// A key with no placeholder is a query or body field passed as a path param, which the
|
|
116
|
+
// request would otherwise drop silently.
|
|
127
117
|
if (!url.includes(`{${key}}`)) {
|
|
128
118
|
throw new Error(
|
|
129
119
|
`"${key}" is not a path parameter of ${url}; pass it in the request argument instead.`,
|
|
@@ -147,11 +137,12 @@ export class ApiClient {
|
|
|
147
137
|
additonalConfig: AxiosRequestConfig,
|
|
148
138
|
): AxiosRequestConfig {
|
|
149
139
|
const token = this._getToken();
|
|
140
|
+
const axiosRequestConfig = this.client.config.getConfig('client')?.axiosRequestConfig;
|
|
150
141
|
|
|
151
142
|
return {
|
|
152
143
|
...additonalConfig,
|
|
153
144
|
headers: {
|
|
154
|
-
...
|
|
145
|
+
...axiosRequestConfig?.headers,
|
|
155
146
|
...additonalConfig.headers,
|
|
156
147
|
Authorization: token,
|
|
157
148
|
'stream-auth-type': this.client.getAuthType(),
|
|
@@ -162,9 +153,9 @@ export class ApiClient {
|
|
|
162
153
|
params: {
|
|
163
154
|
user_id: this.client.userId,
|
|
164
155
|
api_key: this.client.key,
|
|
165
|
-
//
|
|
166
|
-
//
|
|
167
|
-
...
|
|
156
|
+
// Read per request (the rest of `axiosRequestConfig` is applied when the axios instance is
|
|
157
|
+
// created).
|
|
158
|
+
...axiosRequestConfig?.params,
|
|
168
159
|
...additonalConfig.params,
|
|
169
160
|
},
|
|
170
161
|
} satisfies AxiosRequestConfig;
|
|
@@ -183,8 +174,7 @@ export class ApiClient {
|
|
|
183
174
|
const remaining = headers['x-ratelimit-remaining'] as string | undefined;
|
|
184
175
|
if (remaining) rateLimit.rate_limit_remaining = parseInt(remaining, 10);
|
|
185
176
|
|
|
186
|
-
// Unix
|
|
187
|
-
// string as a date and is Invalid Date, so convert the number explicitly.
|
|
177
|
+
// Unix seconds: `new Date('1700000000')` is an Invalid Date, so convert the number explicitly.
|
|
188
178
|
const reset = Number(headers['x-ratelimit-reset']);
|
|
189
179
|
if (Number.isFinite(reset) && reset > 0)
|
|
190
180
|
rateLimit.rate_limit_reset = new Date(reset * 1000);
|
|
@@ -204,8 +194,8 @@ export class ApiClient {
|
|
|
204
194
|
additionalConfig: AxiosRequestConfig = {},
|
|
205
195
|
): Promise<{ body: T; metadata: RequestMetadata }> {
|
|
206
196
|
if (requiresConnectionId(additionalConfig.params, data)) {
|
|
207
|
-
//
|
|
208
|
-
//
|
|
197
|
+
// The axios signal type is structural: a task revived from the offline db can carry a plain
|
|
198
|
+
// object instead of an `AbortSignal`.
|
|
209
199
|
const signal = additionalConfig.signal as AbortSignal | undefined;
|
|
210
200
|
const connectionId = await this.client.connectionIdManager.getConnectionId(
|
|
211
201
|
typeof signal?.addEventListener === 'function' ? signal : undefined,
|
|
@@ -223,6 +213,11 @@ export class ApiClient {
|
|
|
223
213
|
'x-client-request-id'
|
|
224
214
|
] as string;
|
|
225
215
|
|
|
216
|
+
// Only a token provider can hand out a fresh token. A static token reloads to the same expired
|
|
217
|
+
// value, so its request fails immediately.
|
|
218
|
+
const canRefreshExpiredToken = (error: unknown) =>
|
|
219
|
+
isTokenExpiredError(error) && !this.client.tokenManager.isStatic();
|
|
220
|
+
|
|
226
221
|
try {
|
|
227
222
|
const response = await runWithRetry(
|
|
228
223
|
async () => {
|
|
@@ -249,7 +244,7 @@ export class ApiClient {
|
|
|
249
244
|
try {
|
|
250
245
|
requestResponse = await this.client.axiosInstance.request<T>(config);
|
|
251
246
|
} catch (error) {
|
|
252
|
-
if (
|
|
247
|
+
if (canRefreshExpiredToken(error)) {
|
|
253
248
|
logger
|
|
254
249
|
.withExtraTags('_doRequest')
|
|
255
250
|
.debug(
|
|
@@ -267,13 +262,7 @@ export class ApiClient {
|
|
|
267
262
|
{
|
|
268
263
|
delayBetweenRetries: (attemptNumber) => retryInterval(attemptNumber + 1),
|
|
269
264
|
retryAttempts: 10,
|
|
270
|
-
isRetryable:
|
|
271
|
-
if (!(error instanceof AxiosError)) return false;
|
|
272
|
-
|
|
273
|
-
if (error.status === 429 || isTokenExpiredError(error)) return true;
|
|
274
|
-
|
|
275
|
-
return false;
|
|
276
|
-
},
|
|
265
|
+
isRetryable: canRefreshExpiredToken,
|
|
277
266
|
},
|
|
278
267
|
)();
|
|
279
268
|
|
|
@@ -296,16 +285,13 @@ export class ApiClient {
|
|
|
296
285
|
}
|
|
297
286
|
|
|
298
287
|
/**
|
|
299
|
-
* Whether a request
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
* The server keys watches and presence by that id and answers `200` while registering nothing when it
|
|
303
|
-
* is missing, so a request that races the handshake yields a channel that never receives an event.
|
|
288
|
+
* Whether a request (one with a `watch` or `presence` flag) registers a server-side subscription
|
|
289
|
+
* and so must wait for the connection ID. Without it the server answers `200` but registers
|
|
290
|
+
* nothing, and the channel never receives an event.
|
|
304
291
|
*
|
|
305
|
-
*
|
|
306
|
-
* `
|
|
307
|
-
*
|
|
308
|
-
* surfaces there.
|
|
292
|
+
* Flagless operations that declare `connection_id` set it themselves (`stopWatchingChannel` through
|
|
293
|
+
* `StreamChat`'s override, `longPoll` through the fallback); `connectionIdEndpoints.test.ts` pins
|
|
294
|
+
* that set.
|
|
309
295
|
*/
|
|
310
296
|
export const requiresConnectionId = (
|
|
311
297
|
params: Record<string, unknown> | undefined,
|
|
@@ -327,35 +313,31 @@ export const requiresConnectionId = (
|
|
|
327
313
|
};
|
|
328
314
|
|
|
329
315
|
/**
|
|
330
|
-
* An `AbortSignal`
|
|
331
|
-
*
|
|
332
|
-
* `undefined` and `addEventListener` is gone. Axios reaches straight for
|
|
333
|
-
* `signal.addEventListener`, so handing it such an object throws a `TypeError` and takes the
|
|
334
|
-
* replay down with it. Only forward a signal that can still be listened to.
|
|
316
|
+
* An `AbortSignal` persisted as JSON (an offline-db task payload) revives as a plain `{}`, and
|
|
317
|
+
* axios throws a `TypeError` on it. Only forward a signal that can still be listened to.
|
|
335
318
|
*/
|
|
336
319
|
const isUsableAbortSignal = (signal: unknown): signal is AbortSignal =>
|
|
337
320
|
typeof (signal as AbortSignal | undefined)?.addEventListener === 'function';
|
|
338
321
|
|
|
339
|
-
/**
|
|
340
|
-
* Maps the SDK-level per-request options onto the axios request config they
|
|
341
|
-
* translate to. Extend this when a new option is added to `StreamRequestOptions`.
|
|
342
|
-
*/
|
|
322
|
+
/** Maps `StreamRequestOptions` onto the axios request config; extend it when an option is added. */
|
|
343
323
|
const toAxiosRequestConfig = ({
|
|
344
324
|
signal,
|
|
345
325
|
onUploadProgress,
|
|
346
326
|
timeout,
|
|
347
327
|
}: StreamRequestOptions = {}): AxiosRequestConfig => ({
|
|
348
328
|
signal: isUsableAbortSignal(signal) ? signal : undefined,
|
|
349
|
-
//
|
|
350
|
-
// offline-db task payload has lost its functions.
|
|
329
|
+
// Persisted offline-db options lose their functions.
|
|
351
330
|
onUploadProgress: typeof onUploadProgress === 'function' ? onUploadProgress : undefined,
|
|
352
|
-
// Only when set: an explicit `undefined` would clobber the upload defaults' `timeout: 0
|
|
353
|
-
// axios would fall back to the instance timeout.
|
|
331
|
+
// Only when set: an explicit `undefined` would clobber the upload defaults' `timeout: 0`.
|
|
354
332
|
...(typeof timeout === 'number' ? { timeout } : {}),
|
|
355
333
|
});
|
|
356
334
|
|
|
335
|
+
/**
|
|
336
|
+
* Uses `isAxiosError` (a flag check) rather than `instanceof AxiosError`, so errors raised by a
|
|
337
|
+
* second copy of axios (e.g. a React Native adapter) are wrapped with their Stream `code`.
|
|
338
|
+
*/
|
|
357
339
|
const errorIsApiError = (error: unknown): error is AxiosError<APIError> => {
|
|
358
|
-
if (!(error
|
|
340
|
+
if (!isAxiosError(error)) return false;
|
|
359
341
|
|
|
360
342
|
return (
|
|
361
343
|
typeof (error as AxiosError<APIError | undefined>).response?.data?.code === 'number'
|
package/src/campaign.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Campaigns are available in the server-side SDK.
|