stream-chat 10.0.0-rc.8 → 10.0.0
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/README.md +7 -6
- package/dist/cjs/index.browser.js +22095 -22290
- package/dist/cjs/index.browser.js.map +4 -4
- package/dist/cjs/index.node.js +22143 -22298
- package/dist/cjs/index.node.js.map +4 -4
- package/dist/esm/index.mjs +22093 -22288
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/ChannelManager.d.ts +216 -135
- package/dist/types/CooldownTimer.d.ts +16 -27
- package/dist/types/EventHandlerPipeline.d.ts +18 -38
- package/dist/types/LiveLocationManager.d.ts +25 -47
- package/dist/types/api-client.d.ts +17 -5
- package/dist/types/channel.d.ts +435 -500
- package/dist/types/channel_state.d.ts +72 -112
- package/dist/types/client.d.ts +323 -440
- package/dist/types/client_state.d.ts +1 -3
- package/dist/types/configuration/ConfigController.d.ts +31 -125
- package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +32 -124
- 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 +64 -79
- package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +14 -36
- 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 +45 -0
- package/dist/types/connection/ConnectionRecoveryManager.d.ts +84 -0
- package/dist/types/connection/index.d.ts +4 -0
- package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +82 -0
- package/dist/types/connection/networkConnection/index.d.ts +3 -0
- package/dist/types/connection/networkConnection/reporters.d.ts +20 -0
- package/dist/types/connection/networkConnection/types.d.ts +40 -0
- package/dist/types/connection/wsConnection/StableWSConnection.d.ts +137 -0
- package/dist/types/connection/wsConnection/WSConnection.d.ts +105 -0
- package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +47 -0
- package/dist/types/connection/wsConnection/config.d.ts +31 -0
- package/dist/types/connection/wsConnection/index.d.ts +4 -0
- package/dist/types/connection/wsConnection/types.d.ts +46 -0
- package/dist/types/constants.d.ts +3 -1
- package/dist/types/custom_types.d.ts +0 -2
- package/dist/types/entityStore/EntityStore.d.ts +226 -65
- package/dist/types/entityStore/StoreBackedItemIndex.d.ts +19 -33
- package/dist/types/entityStore/index.d.ts +0 -1
- package/dist/types/errors.d.ts +16 -19
- package/dist/types/formatMessageMemo.d.ts +5 -0
- package/dist/types/gen/chat/ChannelApi.d.ts +5 -1
- package/dist/types/gen/chat/ChatApi.d.ts +149 -105
- package/dist/types/gen/models/index.d.ts +2540 -698
- package/dist/types/gen/models/timestamp-guard.d.ts +22 -0
- package/dist/types/gen/moderation/ModerationApi.d.ts +37 -14
- package/dist/types/index.d.ts +10 -5
- package/dist/types/{i18n/languageNames.d.ts → languageNames.d.ts} +9 -24
- package/dist/types/logger.d.ts +1 -3
- package/dist/types/messageComposer/CustomDataManager.d.ts +7 -1
- package/dist/types/messageComposer/LocationComposer.d.ts +8 -2
- package/dist/types/messageComposer/attachmentIdentity.d.ts +24 -0
- package/dist/types/messageComposer/attachmentManager.d.ts +52 -24
- package/dist/types/messageComposer/attachmentUtils.d.ts +23 -0
- package/dist/types/messageComposer/configuration/configuration.d.ts +2 -5
- package/dist/types/messageComposer/configuration/types.d.ts +38 -50
- package/dist/types/messageComposer/index.d.ts +1 -0
- package/dist/types/messageComposer/linkPreviewsManager.d.ts +12 -9
- package/dist/types/messageComposer/messageComposer.d.ts +60 -123
- package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +10 -1
- package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +4 -0
- package/dist/types/messageComposer/middleware/messageComposer/commandInjection.d.ts +5 -0
- package/dist/types/messageComposer/middleware/messageComposer/index.d.ts +2 -0
- package/dist/types/messageComposer/middleware/messageComposer/pollOnly.d.ts +6 -0
- package/dist/types/messageComposer/middleware/messageComposer/userDataInjection.d.ts +5 -0
- 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/commandUtils.d.ts +4 -0
- package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +11 -2
- package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +20 -19
- 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 +15 -5
- package/dist/types/messageComposer/textComposer.d.ts +14 -7
- package/dist/types/messageComposer/types.d.ts +27 -7
- package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +27 -80
- package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +43 -73
- package/dist/types/messageOperations/FailedSendCache.d.ts +29 -0
- package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +16 -22
- package/dist/types/messageOperations/MessageOperations.d.ts +63 -34
- package/dist/types/messageOperations/applyReactionLocally.d.ts +15 -0
- package/dist/types/messageOperations/createMessageOperations.d.ts +9 -0
- package/dist/types/messageOperations/index.d.ts +6 -4
- package/dist/types/messageOperations/reflectReactionEvent.d.ts +16 -0
- package/dist/types/messageOperations/sendOrdering.d.ts +14 -0
- package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +20 -0
- package/dist/types/messageOperations/types.d.ts +43 -14
- package/dist/types/middleware.d.ts +10 -0
- package/dist/types/moderation.d.ts +21 -14
- package/dist/types/notifications/NotificationManager.d.ts +10 -23
- package/dist/types/notifications/types.d.ts +21 -57
- package/dist/types/offline-support/offline_support_api.d.ts +150 -528
- package/dist/types/offline-support/offline_sync_manager.d.ts +21 -42
- package/dist/types/offline-support/queueableOperations.d.ts +35 -37
- package/dist/types/offline-support/types.d.ts +40 -185
- package/dist/types/pagination/FilterBuilder.d.ts +1 -18
- 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 +4 -5
- package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +19 -5
- package/dist/types/pagination/index.d.ts +1 -0
- package/dist/types/pagination/paginators/BasePaginator.d.ts +604 -550
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +123 -106
- package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +576 -327
- package/dist/types/pagination/paginators/MessagePaginator.d.ts +237 -131
- package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +15 -26
- package/dist/types/pagination/paginators/ReminderPaginator.d.ts +4 -3
- package/dist/types/pagination/paginators/ThreadPaginator.d.ts +44 -0
- package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +5 -8
- package/dist/types/pagination/paginators/index.d.ts +1 -0
- package/dist/types/pagination/sortCompiler.d.ts +11 -22
- package/dist/types/pagination/utility.normalization.d.ts +8 -13
- package/dist/types/pagination/utility.search.d.ts +3 -8
- package/dist/types/poll.d.ts +35 -8
- package/dist/types/poll_manager.d.ts +12 -2
- package/dist/types/poll_optimistic_votes.d.ts +57 -0
- package/dist/types/reminders/Reminder.d.ts +17 -7
- package/dist/types/reminders/ReminderManager.d.ts +13 -25
- package/dist/types/search/BaseSearchSource.d.ts +10 -8
- package/dist/types/search/ChannelSearchSource.d.ts +16 -0
- package/dist/types/search/MessageSearchSource.d.ts +17 -0
- package/dist/types/search/SearchController.d.ts +26 -28
- package/dist/types/search/types.d.ts +6 -10
- package/dist/types/signing.d.ts +12 -3
- package/dist/types/thread.d.ts +67 -129
- package/dist/types/thread_manager.d.ts +95 -66
- package/dist/types/token_manager.d.ts +8 -13
- package/dist/types/types.d.ts +81 -197
- package/dist/types/types.utility.d.ts +3 -3
- package/dist/types/upload-utils.d.ts +5 -10
- package/dist/types/uploadManager.d.ts +31 -11
- package/dist/types/utils/FixedSizeQueueCache.d.ts +8 -11
- package/dist/types/utils/WithSubscriptions.d.ts +6 -16
- package/dist/types/utils/abort.d.ts +17 -0
- package/dist/types/utils/concurrency.d.ts +12 -20
- 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 +45 -0
- package/dist/types/utils.d.ts +74 -93
- package/package.json +14 -40
- package/src/ChannelManager.ts +494 -303
- package/src/CooldownTimer.ts +46 -59
- package/src/EventHandlerPipeline.ts +22 -45
- package/src/LiveLocationManager.ts +99 -91
- package/src/api-client.ts +113 -50
- package/src/campaign.ts +1 -1
- package/src/channel.ts +1098 -1351
- package/src/channel_batch_updater.ts +1 -1
- package/src/channel_state.ts +81 -174
- package/src/client.ts +755 -970
- package/src/client_state.ts +3 -8
- package/src/configuration/ConfigController.ts +42 -158
- package/src/configuration/InstanceConfigurationRegistry.ts +43 -172
- package/src/configuration/index.ts +1 -1
- package/src/configuration/keys.ts +13 -32
- package/src/configuration/shape.ts +169 -59
- package/src/configuration/types.ts +69 -92
- package/src/configuration/utils/applyInstanceConfiguration.ts +22 -54
- 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 +111 -0
- package/src/connection/ConnectionRecoveryManager.ts +257 -0
- package/src/connection/index.ts +4 -0
- package/src/connection/networkConnection/NetworkConnectionObserver.ts +204 -0
- package/src/connection/networkConnection/index.ts +3 -0
- package/src/connection/networkConnection/reporters.ts +58 -0
- package/src/connection/networkConnection/types.ts +45 -0
- package/src/{connection.ts → connection/wsConnection/StableWSConnection.ts} +230 -231
- package/src/connection/wsConnection/WSConnection.ts +270 -0
- package/src/connection/wsConnection/WSConnectionFallback.ts +250 -0
- package/src/connection/wsConnection/config.ts +73 -0
- package/src/connection/wsConnection/index.ts +4 -0
- package/src/connection/wsConnection/types.ts +48 -0
- package/src/constants.ts +7 -5
- package/src/custom_types.ts +0 -1
- package/src/entityStore/EntityStore.ts +415 -79
- package/src/entityStore/StoreBackedItemIndex.ts +37 -41
- package/src/entityStore/index.ts +0 -1
- package/src/errors.ts +39 -20
- package/src/formatMessageMemo.ts +17 -0
- package/src/gen/chat/ChannelApi.ts +122 -36
- package/src/gen/chat/ChatApi.ts +578 -1752
- package/src/gen/models/index.ts +2566 -3440
- package/src/gen/models/timestamp-guard.ts +27 -0
- package/src/gen/moderation/ModerationApi.ts +183 -406
- package/src/index.ts +32 -10
- package/src/languageNames.ts +88 -0
- package/src/logger.ts +1 -3
- package/src/messageComposer/CustomDataManager.ts +19 -6
- package/src/messageComposer/LocationComposer.ts +49 -9
- package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -2
- package/src/messageComposer/attachmentIdentity.ts +54 -0
- package/src/messageComposer/attachmentManager.ts +170 -185
- package/src/messageComposer/attachmentUtils.ts +44 -0
- package/src/messageComposer/configuration/configuration.ts +15 -8
- package/src/messageComposer/configuration/types.ts +38 -50
- package/src/messageComposer/fileUtils.ts +1 -1
- package/src/messageComposer/index.ts +1 -0
- package/src/messageComposer/linkPreviewsManager.ts +18 -21
- package/src/messageComposer/messageComposer.ts +234 -179
- package/src/messageComposer/middleware/attachmentManager/postUpload/AttachmentPostUploadMiddlewareExecutor.ts +1 -1
- package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +46 -33
- package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +4 -1
- package/src/messageComposer/middleware/attachmentManager/preUpload/blockedUploadNotification.ts +1 -1
- package/src/messageComposer/middleware/messageComposer/MessageComposerMiddlewareExecutor.ts +6 -0
- package/src/messageComposer/middleware/messageComposer/attachments.ts +76 -5
- package/src/messageComposer/middleware/messageComposer/commandInjection.ts +10 -4
- package/src/messageComposer/middleware/messageComposer/customData.ts +17 -5
- package/src/messageComposer/middleware/messageComposer/index.ts +2 -0
- package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +22 -12
- package/src/messageComposer/middleware/messageComposer/pollOnly.ts +9 -1
- package/src/messageComposer/middleware/messageComposer/sharedLocation.ts +7 -2
- package/src/messageComposer/middleware/messageComposer/textComposer.ts +1 -1
- package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +12 -12
- 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 +8 -6
- package/src/messageComposer/middleware/textComposer/commandUtils.ts +10 -3
- 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 +21 -9
- package/src/messageComposer/textComposer.ts +37 -57
- package/src/messageComposer/types.ts +39 -11
- package/src/messageDelivery/MessageDeliveryReporter.ts +86 -124
- package/src/messageDelivery/MessageReceiptsTracker.ts +122 -139
- package/src/messageOperations/FailedSendCache.ts +85 -0
- package/src/messageOperations/MessageOperationStatePolicy.ts +124 -116
- package/src/messageOperations/MessageOperations.ts +297 -175
- package/src/{entityStore → messageOperations}/applyReactionLocally.ts +13 -25
- package/src/messageOperations/createMessageOperations.ts +176 -0
- package/src/messageOperations/index.ts +6 -14
- package/src/messageOperations/reflectReactionEvent.ts +43 -0
- package/src/messageOperations/sendOrdering.ts +25 -0
- package/src/messageOperations/settlePendingAttachmentUploads.ts +98 -0
- package/src/messageOperations/types.ts +51 -13
- package/src/middleware.ts +13 -5
- package/src/moderation.ts +25 -21
- package/src/notifications/NotificationManager.ts +19 -28
- package/src/notifications/types.ts +21 -57
- package/src/offline-support/offline_support_api.ts +231 -681
- package/src/offline-support/offline_sync_manager.ts +51 -90
- package/src/offline-support/queueableOperations.ts +98 -73
- package/src/offline-support/types.ts +43 -185
- package/src/pagination/FilterBuilder.ts +1 -22
- package/src/pagination/ItemIndex.ts +4 -12
- package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +29 -0
- package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +17 -62
- package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
- package/src/pagination/cursorDerivation/linearPaginationFlags.ts +53 -33
- package/src/pagination/filterCompiler.ts +11 -25
- package/src/pagination/index.ts +1 -0
- package/src/pagination/paginators/BasePaginator.ts +1415 -1041
- package/src/pagination/paginators/ChannelPaginator.ts +481 -219
- package/src/pagination/paginators/MessageIntervalPaginator.ts +1362 -775
- package/src/pagination/paginators/MessagePaginator.ts +521 -240
- package/src/pagination/paginators/PinnedMessagePaginator.ts +32 -40
- package/src/pagination/paginators/ReminderPaginator.ts +21 -16
- package/src/pagination/paginators/ThreadPaginator.ts +170 -0
- package/src/pagination/paginators/UserGroupPaginator.ts +18 -15
- package/src/pagination/paginators/index.ts +1 -0
- package/src/pagination/paginators/stateThrottling.ts +5 -10
- package/src/pagination/sortCompiler.ts +23 -50
- package/src/pagination/utility.normalization.ts +17 -24
- package/src/pagination/utility.search.ts +4 -11
- package/src/poll.ts +183 -102
- package/src/poll_manager.ts +24 -22
- package/src/poll_optimistic_votes.ts +335 -0
- package/src/reminders/Reminder.ts +33 -16
- package/src/reminders/ReminderManager.ts +23 -56
- package/src/reminders/ReminderTimer.ts +6 -6
- package/src/search/BaseSearchSource.ts +19 -25
- package/src/search/ChannelSearchSource.ts +43 -1
- package/src/search/MessageSearchSource.ts +77 -13
- package/src/search/SearchController.ts +39 -36
- package/src/search/types.ts +6 -10
- package/src/segment.ts +1 -1
- package/src/signing.ts +23 -3
- package/src/thread.ts +430 -712
- package/src/thread_manager.ts +300 -234
- package/src/token_manager.ts +12 -22
- package/src/types.ts +102 -214
- package/src/types.utility.ts +3 -3
- package/src/upload-utils.ts +5 -10
- package/src/uploadManager.ts +64 -18
- package/src/utils/FixedSizeQueueCache.ts +18 -21
- package/src/utils/WithSubscriptions.ts +6 -16
- package/src/utils/abort.ts +45 -0
- 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 +64 -0
- package/src/utils.ts +227 -174
- package/codegen/i18n/callSites.ts +0 -126
- package/codegen/i18n/generate.ts +0 -226
- package/codegen/i18n/guards.ts +0 -178
- package/codegen/i18n/index.ts +0 -29
- package/codegen/i18n/stringMaps.ts +0 -91
- package/codegen/i18n/types.ts +0 -100
- package/dist/cjs/i18n.browser.js +0 -1131
- package/dist/cjs/i18n.browser.js.map +0 -7
- package/dist/cjs/i18n.node.js +0 -1160
- package/dist/cjs/i18n.node.js.map +0 -7
- package/dist/esm/i18n-codegen.mjs +0 -409
- package/dist/esm/i18n-codegen.mjs.map +0 -7
- package/dist/esm/i18n.mjs +0 -1098
- package/dist/esm/i18n.mjs.map +0 -7
- package/dist/types/ConnectionRecoveryManager.d.ts +0 -156
- package/dist/types/connection.d.ts +0 -139
- package/dist/types/entityStore/applyReactionLocally.d.ts +0 -26
- package/dist/types/gen/model-decoders/decoders.d.ts +0 -3
- package/dist/types/gen/model-decoders/event-decoder-mapping.d.ts +0 -6
- package/dist/types/i18n/Streami18n.d.ts +0 -168
- package/dist/types/i18n/TranslationBuilder.d.ts +0 -70
- package/dist/types/i18n/TranslationStore.d.ts +0 -57
- package/dist/types/i18n/dayjs.d.ts +0 -104
- package/dist/types/i18n/formatters.d.ts +0 -91
- package/dist/types/i18n/index.d.ts +0 -15
- package/dist/types/i18n/translator.d.ts +0 -29
- package/dist/types/i18n/types.d.ts +0 -262
- package/dist/types/i18n-codegen/callSites.d.ts +0 -10
- package/dist/types/i18n-codegen/generate.d.ts +0 -15
- package/dist/types/i18n-codegen/guards.d.ts +0 -61
- package/dist/types/i18n-codegen/index.d.ts +0 -29
- package/dist/types/i18n-codegen/stringMaps.d.ts +0 -14
- package/dist/types/i18n-codegen/types.d.ts +0 -94
- package/dist/types/insights.d.ts +0 -56
- package/dist/types/messageOperations/optimistic.d.ts +0 -118
- package/dist/types/messageOperations/persistence.d.ts +0 -21
- package/dist/types/pagination/utility.queryChannel.d.ts +0 -26
- package/dist/types/store.d.ts +0 -125
- package/src/ConnectionRecoveryManager.ts +0 -293
- package/src/gen/model-decoders/decoders.ts +0 -2710
- package/src/gen/model-decoders/event-decoder-mapping.ts +0 -198
- package/src/i18n/Streami18n.ts +0 -520
- package/src/i18n/TranslationBuilder.ts +0 -176
- package/src/i18n/TranslationStore.ts +0 -96
- package/src/i18n/dayjs.ts +0 -228
- package/src/i18n/formatters.ts +0 -461
- package/src/i18n/index.ts +0 -15
- package/src/i18n/languageNames.ts +0 -103
- package/src/i18n/translator.ts +0 -76
- package/src/i18n/types.ts +0 -375
- package/src/insights.ts +0 -82
- package/src/messageOperations/optimistic.ts +0 -249
- package/src/messageOperations/persistence.ts +0 -40
- package/src/pagination/utility.queryChannel.ts +0 -84
- package/src/store.ts +0 -304
package/src/token_manager.ts
CHANGED
|
@@ -6,11 +6,7 @@ import type { TokenOrProvider } from './types';
|
|
|
6
6
|
const logger = chatLoggerSystem.getLogger('token-manager');
|
|
7
7
|
|
|
8
8
|
export type TokenManagerMinimalUser = { id: string; anon?: boolean };
|
|
9
|
-
/**
|
|
10
|
-
* TokenManager
|
|
11
|
-
*
|
|
12
|
-
* Handles all the operations around user token.
|
|
13
|
-
*/
|
|
9
|
+
/** Holds the user token, either static or loaded from a provider. */
|
|
14
10
|
export class TokenManager {
|
|
15
11
|
loadTokenPromise: Promise<string> | null;
|
|
16
12
|
type: 'static' | 'provider';
|
|
@@ -18,9 +14,6 @@ export class TokenManager {
|
|
|
18
14
|
tokenProvider?: TokenOrProvider;
|
|
19
15
|
user?: TokenManagerMinimalUser;
|
|
20
16
|
private _isAnonymous = false;
|
|
21
|
-
/**
|
|
22
|
-
* Initializes the token manager.
|
|
23
|
-
*/
|
|
24
17
|
constructor() {
|
|
25
18
|
this.loadTokenPromise = null;
|
|
26
19
|
|
|
@@ -32,11 +25,11 @@ export class TokenManager {
|
|
|
32
25
|
}
|
|
33
26
|
|
|
34
27
|
/**
|
|
35
|
-
* Sets
|
|
36
|
-
* or a promise that resolves to a token string.
|
|
28
|
+
* Sets a static token or a token provider, then loads the token.
|
|
37
29
|
*
|
|
38
|
-
* @param tokenOrProvider - A token string or an async provider that
|
|
30
|
+
* @param tokenOrProvider - A token string, or an async provider that resolves to one.
|
|
39
31
|
* @param user - The user the token belongs to.
|
|
32
|
+
* @throws When the token is not a string or function, or a string token does not match `user.id`.
|
|
40
33
|
*/
|
|
41
34
|
setTokenOrProvider = async (
|
|
42
35
|
tokenOrProvider: TokenOrProvider,
|
|
@@ -60,8 +53,10 @@ export class TokenManager {
|
|
|
60
53
|
};
|
|
61
54
|
|
|
62
55
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
56
|
+
* Clears the token, the provider and the user. Called by the client on `disconnectUser()` and
|
|
57
|
+
* after an anonymous `createGuest()`.
|
|
58
|
+
*
|
|
59
|
+
* @internal
|
|
65
60
|
*/
|
|
66
61
|
reset = () => {
|
|
67
62
|
this._isAnonymous = false;
|
|
@@ -72,9 +67,8 @@ export class TokenManager {
|
|
|
72
67
|
this.loadTokenPromise = null;
|
|
73
68
|
};
|
|
74
69
|
|
|
75
|
-
// Validates the user token.
|
|
76
70
|
validateToken = (tokenOrProvider: TokenOrProvider, user: TokenManagerMinimalUser) => {
|
|
77
|
-
//
|
|
71
|
+
// Anonymous users may have an empty token.
|
|
78
72
|
if (user && user.anon && !tokenOrProvider) return;
|
|
79
73
|
|
|
80
74
|
if (
|
|
@@ -86,7 +80,6 @@ export class TokenManager {
|
|
|
86
80
|
}
|
|
87
81
|
|
|
88
82
|
if (typeof tokenOrProvider === 'string') {
|
|
89
|
-
// Allow empty token for anonymous users
|
|
90
83
|
if (user.anon && tokenOrProvider === '') return;
|
|
91
84
|
|
|
92
85
|
const tokenUserId = UserFromToken(tokenOrProvider);
|
|
@@ -101,12 +94,10 @@ export class TokenManager {
|
|
|
101
94
|
}
|
|
102
95
|
};
|
|
103
96
|
|
|
104
|
-
//
|
|
105
|
-
// case a function should wait.
|
|
97
|
+
// The in-flight token load, for callers that must wait for it.
|
|
106
98
|
tokenReady = () => this.loadTokenPromise;
|
|
107
99
|
|
|
108
|
-
// Fetches
|
|
109
|
-
// In case of static token, it will simply resolve to static token.
|
|
100
|
+
// Fetches the token from the provider and stores it. A static token resolves as is.
|
|
110
101
|
loadToken = () => {
|
|
111
102
|
// eslint-disable-next-line no-async-promise-executor
|
|
112
103
|
this.loadTokenPromise = new Promise(async (resolve, reject) => {
|
|
@@ -132,7 +123,6 @@ export class TokenManager {
|
|
|
132
123
|
return this.loadTokenPromise;
|
|
133
124
|
};
|
|
134
125
|
|
|
135
|
-
// Returns a current token
|
|
136
126
|
getToken = () => {
|
|
137
127
|
if (this.token) {
|
|
138
128
|
return this.token;
|
|
@@ -143,7 +133,7 @@ export class TokenManager {
|
|
|
143
133
|
}
|
|
144
134
|
|
|
145
135
|
throw new Error(
|
|
146
|
-
`
|
|
136
|
+
`User token is not set. Either client.connectUser wasn't called or client.disconnectUser was called`,
|
|
147
137
|
);
|
|
148
138
|
};
|
|
149
139
|
|
package/src/types.ts
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { StableWSConnection } from './connection';
|
|
1
|
+
import type { AxiosResponse } from 'axios';
|
|
3
2
|
import type { CustomEventTypes } from './custom_types';
|
|
4
|
-
import type { NotificationManager } from './notifications';
|
|
5
|
-
import type { InstanceConfigTree } from './configuration/types';
|
|
6
|
-
import type { DeepPartial } from './types.utility';
|
|
7
3
|
import type {
|
|
8
4
|
APIError,
|
|
9
5
|
Attachment,
|
|
10
6
|
BanRequest,
|
|
11
7
|
ChannelConfigWithInfo,
|
|
12
|
-
|
|
8
|
+
ChannelMemberRequest,
|
|
13
9
|
ChannelStateResponseFields,
|
|
14
10
|
CreateDeviceRequest,
|
|
15
11
|
CreatePollRequest,
|
|
12
|
+
CustomEvent,
|
|
16
13
|
DraftPayloadResponse,
|
|
17
14
|
FlagRequest,
|
|
18
15
|
Images,
|
|
16
|
+
MessageRequest,
|
|
19
17
|
MessageResponse,
|
|
20
18
|
OwnUserResponse,
|
|
21
19
|
QueryChannelsRequest,
|
|
22
20
|
QueryMembersPayload,
|
|
23
21
|
QueryPollsRequest,
|
|
24
22
|
QueryPollVotesRequest,
|
|
23
|
+
QueryReactionsRequest,
|
|
25
24
|
QueryRemindersRequest,
|
|
26
25
|
QueryThreadsRequest,
|
|
27
26
|
QueryUsersPayload,
|
|
@@ -30,6 +29,7 @@ import type {
|
|
|
30
29
|
SendMessageRequest,
|
|
31
30
|
SendMessageResponse,
|
|
32
31
|
SharedLocationResponseData,
|
|
32
|
+
TimestampNS,
|
|
33
33
|
TranslateMessageRequest,
|
|
34
34
|
UpdateChannelRequest,
|
|
35
35
|
UpdateMessageRequest,
|
|
@@ -41,9 +41,6 @@ import type {
|
|
|
41
41
|
|
|
42
42
|
import type { ChatApi } from './gen-imports';
|
|
43
43
|
|
|
44
|
-
/**
|
|
45
|
-
* Utility Types
|
|
46
|
-
*/
|
|
47
44
|
export type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Omit<T, Keys> &
|
|
48
45
|
{
|
|
49
46
|
[K in Keys]-?: Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, undefined>>;
|
|
@@ -53,24 +50,9 @@ export type RequireAtLeastOne<T> = {
|
|
|
53
50
|
[K in keyof T]-?: Required<Pick<T, K>> & Partial<Omit<T, K>>;
|
|
54
51
|
}[keyof T];
|
|
55
52
|
|
|
56
|
-
export type Unpacked<T> = T extends (infer U)[]
|
|
57
|
-
? U
|
|
58
|
-
: T extends (...args: any[]) => infer U
|
|
59
|
-
? U
|
|
60
|
-
: T extends Promise<infer U>
|
|
61
|
-
? U
|
|
62
|
-
: T;
|
|
63
|
-
|
|
64
53
|
/**
|
|
65
|
-
*
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Legacy response envelope. Every generated response already carries `duration`, and the
|
|
70
|
-
* transport wraps results in `StreamResponse<T>`, which also carries `metadata`.
|
|
71
|
-
*
|
|
72
|
-
* Only still referenced by the hand-written `/moderation/*` methods on `StreamChat` that
|
|
73
|
-
* bypass the generated client. Delete this together with those.
|
|
54
|
+
* Used only by `StreamChat.unbanUser`, a hand-written `/moderation/*` call that bypasses the
|
|
55
|
+
* generated client.
|
|
74
56
|
*/
|
|
75
57
|
export type APIResponse = {
|
|
76
58
|
duration: string;
|
|
@@ -78,6 +60,33 @@ export type APIResponse = {
|
|
|
78
60
|
|
|
79
61
|
export type ChannelUpdateOptions = Omit<UpdateChannelRequest, 'message'>;
|
|
80
62
|
|
|
63
|
+
/**
|
|
64
|
+
* A channel update that adds or removes items (members, invitees, filter tags): the items, a message
|
|
65
|
+
* notifying the channel members, and any other `update()` option.
|
|
66
|
+
*/
|
|
67
|
+
type ChannelItemsUpdate<Key extends string, Item> = Record<Key, Item[]> & {
|
|
68
|
+
/** Message object for channel members notification (optional). */
|
|
69
|
+
message?: MessageRequest;
|
|
70
|
+
} & ChannelUpdateOptions;
|
|
71
|
+
|
|
72
|
+
/** Request of `channel.addMembers`: user IDs, or member requests with a role or custom data. */
|
|
73
|
+
export type AddMembersRequest = ChannelItemsUpdate<
|
|
74
|
+
'members',
|
|
75
|
+
string | ChannelMemberRequest
|
|
76
|
+
>;
|
|
77
|
+
|
|
78
|
+
/** Request of `channel.inviteMembers`. */
|
|
79
|
+
export type InviteMembersRequest = ChannelItemsUpdate<
|
|
80
|
+
'members',
|
|
81
|
+
string | Required<Omit<ChannelMemberRequest, 'channel_role'>>
|
|
82
|
+
>;
|
|
83
|
+
|
|
84
|
+
/** Request of `channel.removeMembers`: the user IDs to remove. */
|
|
85
|
+
export type RemoveMembersRequest = ChannelItemsUpdate<'members', string>;
|
|
86
|
+
|
|
87
|
+
/** Request of `channel.addFilterTags` and `channel.removeFilterTags`. */
|
|
88
|
+
export type FilterTagsRequest = ChannelItemsUpdate<'tags', string>;
|
|
89
|
+
|
|
81
90
|
export type ConnectAPIResponse = Promise<void | ConnectionOpen>;
|
|
82
91
|
|
|
83
92
|
export type LocalMessage = MessageResponse & {
|
|
@@ -86,49 +95,43 @@ export type LocalMessage = MessageResponse & {
|
|
|
86
95
|
user_id?: string;
|
|
87
96
|
};
|
|
88
97
|
|
|
89
|
-
export type GetThreadOptions =
|
|
98
|
+
export type GetThreadOptions = NonNullable<Parameters<ChatApi['getThread']>[1]>;
|
|
99
|
+
|
|
100
|
+
/** Options of `client.pinMessage`. */
|
|
101
|
+
export type PinMessageOptions = {
|
|
102
|
+
/** When the pin expires; `null` or leaving it out pins without expiry. */
|
|
103
|
+
pin_expires?: Date | string | null;
|
|
104
|
+
/** The pin time, which orders the pinned messages. Defaults to now. */
|
|
105
|
+
pinned_at?: Date | string;
|
|
106
|
+
};
|
|
90
107
|
|
|
91
108
|
/**
|
|
92
|
-
* The fields
|
|
93
|
-
* `
|
|
94
|
-
*
|
|
95
|
-
* Derived, never hand-listed: `client._handleUserEvent` uses this set (through
|
|
96
|
-
* `isOwnUserBaseProperty`) to decide which keys survive a `user.updated` event, so a field
|
|
97
|
-
* missing from it is silently deleted off `client.user`. Deriving it means a spec change
|
|
98
|
-
* cannot desynchronise the two.
|
|
109
|
+
* The fields of `OwnUserResponse` that a plain `UserResponse` lacks. `client._handleUserEvent` uses
|
|
110
|
+
* it (through `isOwnUserBaseProperty`) to decide which keys survive a `user.updated` event.
|
|
99
111
|
*/
|
|
100
112
|
export type OwnUserBase = Pick<
|
|
101
113
|
OwnUserResponse,
|
|
102
114
|
Exclude<keyof OwnUserResponse, keyof UserResponse>
|
|
103
115
|
>;
|
|
104
116
|
|
|
105
|
-
// Thumb URL(thumb_url) is added considering video attachments as the backend will return the thumbnail in the response.
|
|
106
117
|
export type BanUserOptions = Omit<BanRequest, 'target_user_id'>;
|
|
107
118
|
|
|
108
119
|
/**
|
|
109
120
|
* Everything `queryChannels()` accepts apart from the filter and the sort.
|
|
110
121
|
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* if the predefined filter has its own stored sort template that template wins and the request
|
|
116
|
-
* `sort` is ignored; if it does not, the request `sort` is used. `sort_values` interpolates the
|
|
117
|
-
* stored sort template's placeholders. All three are only read when `predefined_filter` is set.
|
|
122
|
+
* `predefined_filter` names a backend filter template, interpolated with `filter_values`. If that
|
|
123
|
+
* template has its own stored sort, it wins over the request `sort` and `sort_values` fills its
|
|
124
|
+
* placeholders; otherwise the request `sort` is used. `filter_values` and `sort_values` are sent
|
|
125
|
+
* only when `predefined_filter` is set.
|
|
118
126
|
*/
|
|
119
127
|
export type ChannelOptions = Omit<QueryChannelsRequest, 'filter_conditions' | 'sort'>;
|
|
120
128
|
|
|
121
129
|
export type ChannelStateOptions = {
|
|
122
130
|
offlineMode?: boolean;
|
|
123
|
-
skipInitialization?: string[];
|
|
124
131
|
skipHydration?: boolean;
|
|
125
132
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* This is a compatibility bridge for internal callers that need response level
|
|
129
|
-
* metadata such as `predefined_filter`. The default `queryChannels()` return value
|
|
130
|
-
* remains `Channel[]` to avoid a breaking change. This should be folded into a
|
|
131
|
-
* single full response API in the next major release.
|
|
133
|
+
* Makes `queryChannelsAndHydrate()` return the full query response (with hydrated `channels`,
|
|
134
|
+
* plus metadata such as `predefined_filter`) instead of `Channel[]`.
|
|
132
135
|
*/
|
|
133
136
|
withResponse?: boolean;
|
|
134
137
|
};
|
|
@@ -139,81 +142,12 @@ export type Automod = ChannelConfigWithInfo['automod'];
|
|
|
139
142
|
export type AutomodBehavior = ChannelConfigWithInfo['automod_behavior'];
|
|
140
143
|
|
|
141
144
|
export type PinnedMessagePaginationOptions = Omit<
|
|
142
|
-
Parameters<ChatApi['getPinnedMessages']>[
|
|
143
|
-
'
|
|
145
|
+
NonNullable<Parameters<ChatApi['getPinnedMessages']>[1]>,
|
|
146
|
+
'sort'
|
|
144
147
|
>;
|
|
145
148
|
|
|
146
149
|
export type QueryMembersOptions = Partial<Omit<QueryMembersPayload, 'filter_conditions'>>;
|
|
147
150
|
|
|
148
|
-
export type StreamChatOptions = {
|
|
149
|
-
/**
|
|
150
|
-
* Used to disable warnings that are triggered by using connectUser or connectAnonymousUser server-side.
|
|
151
|
-
*/
|
|
152
|
-
allowServerSideConnect?: boolean;
|
|
153
|
-
axiosRequestConfig?: AxiosRequestConfig;
|
|
154
|
-
/**
|
|
155
|
-
* Base url to use for API
|
|
156
|
-
* such as https://chat-proxy-dublin.stream-io-api.com
|
|
157
|
-
*/
|
|
158
|
-
baseURL?: string;
|
|
159
|
-
browser?: boolean;
|
|
160
|
-
/**
|
|
161
|
-
* Disables the hydration of all caches within the JS Client. This includes this.activeChannels,
|
|
162
|
-
* this.polls.pollCache and this.config.
|
|
163
|
-
* It is mainly meant to be used for integrations where stream-chat is used as a server-side service
|
|
164
|
-
* interacting with Stream's REST API, not depending on any state and purely serving as a wrapper
|
|
165
|
-
* around HTTP requests. Using this property on either the client side or a backend implementation
|
|
166
|
-
* that also relies on WS events will break these functionalities, so please use carefully.
|
|
167
|
-
*/
|
|
168
|
-
disableCache?: boolean;
|
|
169
|
-
enableInsights?: boolean;
|
|
170
|
-
/**
|
|
171
|
-
* When true, maintains a client-local unread count on channels that have read events disabled
|
|
172
|
-
* (e.g. livestreams). The count increments on incoming messages and is reset via
|
|
173
|
-
* `channel.markReadLocally()`. It is never sent to the backend, but is persisted to the offline DB.
|
|
174
|
-
*/
|
|
175
|
-
isLocalUnreadCountEnabled?: boolean;
|
|
176
|
-
/**
|
|
177
|
-
* Custom notification manager service to use for the client.
|
|
178
|
-
* If not provided, a default notification manager will be created.
|
|
179
|
-
* Notifications are used to communicate events like errors, warnings, info, etc. Other services can publish notifications or subscribe to the NotificationManager state changes.
|
|
180
|
-
*/
|
|
181
|
-
notifications?: NotificationManager;
|
|
182
|
-
/**
|
|
183
|
-
* Declarative configuration for instances the SDK creates on your behalf, seeded before the client's
|
|
184
|
-
* own managers are constructed.
|
|
185
|
-
*
|
|
186
|
-
* Equivalent to calling `client.config.set(tree)` immediately after construction, except for the
|
|
187
|
-
* `client` subtree — the configuration registry is created inside the constructor, so this is the only
|
|
188
|
-
* way to configure `reminders` / `notifications` before they are built.
|
|
189
|
-
*/
|
|
190
|
-
config?: DeepPartial<InstanceConfigTree>;
|
|
191
|
-
/**
|
|
192
|
-
* When true, user will be persisted on client. Otherwise if `connectUser` call fails, then you need to
|
|
193
|
-
* call `connectUser` again to retry.
|
|
194
|
-
* This is mainly useful for chat application working in offline mode, where you will need client.user to
|
|
195
|
-
* persist even if connectUser call fails.
|
|
196
|
-
*/
|
|
197
|
-
persistUserOnConnectionFailure?: boolean;
|
|
198
|
-
warmUp?: boolean;
|
|
199
|
-
/**
|
|
200
|
-
* Sets the instance of `StableWSConnection` on the chat client. Intended purely for testing and
|
|
201
|
-
* should not be used in production apps.
|
|
202
|
-
*/
|
|
203
|
-
wsConnection?: StableWSConnection;
|
|
204
|
-
/**
|
|
205
|
-
* Overrides the `WebSocket` constructor used by `StableWSConnection`. Intended purely for
|
|
206
|
-
* testing so a mock/drivable WebSocket can be swapped in; production code should leave this
|
|
207
|
-
* unset and rely on the platform's global `WebSocket`.
|
|
208
|
-
*/
|
|
209
|
-
WebSocketImpl?: typeof WebSocket;
|
|
210
|
-
/**
|
|
211
|
-
* Sets a suffix to the wsUrl when it is being built in `wsConnection`. Is meant to be
|
|
212
|
-
* used purely in testing suites and should not be used in production apps.
|
|
213
|
-
*/
|
|
214
|
-
wsUrlParams?: URLSearchParams;
|
|
215
|
-
};
|
|
216
|
-
|
|
217
151
|
export type UnBanUserOptions = {
|
|
218
152
|
client_id?: string;
|
|
219
153
|
connection_id?: string;
|
|
@@ -227,6 +161,13 @@ export type UnBanUserOptions = {
|
|
|
227
161
|
/** Everything `queryUsers()` accepts apart from the filter and the sort. */
|
|
228
162
|
export type UserOptions = Omit<QueryUsersPayload, 'filter_conditions' | 'sort'>;
|
|
229
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Which connection a status refers to: `'network'` is the device's network (reported by the
|
|
166
|
+
* platform reporter installed on `client.networkConnection`), `'ws'` is this client's WebSocket.
|
|
167
|
+
* They can disagree, so each has its own store.
|
|
168
|
+
*/
|
|
169
|
+
export type ConnectionType = 'network' | 'ws';
|
|
170
|
+
|
|
230
171
|
type LocalEvent = (
|
|
231
172
|
| ({ type: 'live_location_sharing.started' } & { message: MessageResponse })
|
|
232
173
|
| ({ type: 'live_location_sharing.stopped' } & {
|
|
@@ -238,54 +179,50 @@ type LocalEvent = (
|
|
|
238
179
|
isLatestMessageSet: boolean;
|
|
239
180
|
};
|
|
240
181
|
})
|
|
241
|
-
| ({ type: 'connection.changed' } & { online: boolean })
|
|
242
182
|
| { type: 'connection.recovered' }
|
|
183
|
+
// `enableWSFallback` switched from the WebSocket to long-polling.
|
|
184
|
+
| ({ type: 'connection.fallback_activated' } & { mode: string })
|
|
243
185
|
| ({ type: 'offline_reactions.queried' } & {
|
|
244
186
|
offlineReactions: ReactionResponse[];
|
|
245
187
|
})
|
|
246
|
-
| ({ type: 'capabilities.changed' } & {
|
|
247
|
-
cid: string;
|
|
248
|
-
own_capabilities: ChannelOwnCapability[];
|
|
249
|
-
})
|
|
250
188
|
| ({ type: 'message.read_locally' } & {
|
|
251
189
|
channel_type: string;
|
|
252
190
|
cid: string;
|
|
253
|
-
created_at:
|
|
191
|
+
created_at: TimestampNS;
|
|
254
192
|
channel_id?: string;
|
|
255
193
|
last_read_message_id?: string;
|
|
256
194
|
team?: string;
|
|
257
195
|
user?: UserResponse;
|
|
258
196
|
})
|
|
259
|
-
) & { received_at?:
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
export type Event = WSEvent | ConnectedEvent | LocalEvent | keyof CustomEventTypes;
|
|
197
|
+
) & { received_at?: TimestampNS };
|
|
198
|
+
|
|
199
|
+
// Two WS events miss `received_at` in API spec, so we add it to typedef here. The spec's custom-event
|
|
200
|
+
// placeholder (`{ type: '*' } & CustomEvent`) is left out: nothing is dispatched under `'*'` (a
|
|
201
|
+
// custom event arrives under its own name, declared through `CustomEventTypes`), so it is neither an
|
|
202
|
+
// event a handler receives nor a name `on()` / `off()` accept.
|
|
203
|
+
export type Event =
|
|
204
|
+
| (Exclude<WSEvent, { type: '*' }> & { received_at?: TimestampNS })
|
|
205
|
+
| LocalEvent
|
|
206
|
+
| CustomEventTypeUnion;
|
|
207
|
+
|
|
208
|
+
// One member per key augmented into `CustomEventTypes`; `never` when none are declared.
|
|
209
|
+
type CustomEventTypeUnion = {
|
|
210
|
+
[K in keyof CustomEventTypes]: { type: K } & Omit<CustomEvent, 'type'> & {
|
|
211
|
+
received_at?: TimestampNS;
|
|
212
|
+
};
|
|
213
|
+
}[keyof CustomEventTypes];
|
|
278
214
|
export type EventType = Event['type'] | 'all';
|
|
279
215
|
|
|
280
|
-
export type EventHandler<T = string> = (event: Extract<Event, { type: T }>) => void;
|
|
281
|
-
|
|
282
216
|
/**
|
|
283
|
-
*
|
|
217
|
+
* A listener for events of type `T`. `'all'` (the default) receives every event, any other type the
|
|
218
|
+
* event members declaring it. Custom event types have to be declared by augmenting
|
|
219
|
+
* `CustomEventTypes`; an undeclared name is not an `EventType`.
|
|
284
220
|
*/
|
|
221
|
+
export type EventHandler<T extends EventType = 'all'> = (
|
|
222
|
+
event: T extends 'all' ? Event : Extract<Event, { type: T }>,
|
|
223
|
+
) => void;
|
|
285
224
|
|
|
286
|
-
export type ReactionFilters = NonNullable<
|
|
287
|
-
|
|
288
|
-
export type QueryReactionsRequestWithId = Parameters<ChatApi['queryReactions']>[0];
|
|
225
|
+
export type ReactionFilters = NonNullable<QueryReactionsRequest['filter']>;
|
|
289
226
|
|
|
290
227
|
export type ChannelFilters = NonNullable<QueryChannelsRequest['filter_conditions']>;
|
|
291
228
|
|
|
@@ -299,25 +236,6 @@ export type QueryVotesFilters = NonNullable<QueryPollVotesRequest['filter']>;
|
|
|
299
236
|
|
|
300
237
|
export type MessageFilters = NonNullable<SearchPayload['message_filter_conditions']>;
|
|
301
238
|
|
|
302
|
-
export type PrimitiveFilter<ObjectType> = ObjectType | null;
|
|
303
|
-
|
|
304
|
-
export type QueryFilter<ObjectType = string> =
|
|
305
|
-
NonNullable<ObjectType> extends string | number | boolean | Date
|
|
306
|
-
? {
|
|
307
|
-
$eq?: PrimitiveFilter<ObjectType>;
|
|
308
|
-
$exists?: boolean;
|
|
309
|
-
$gt?: PrimitiveFilter<ObjectType>;
|
|
310
|
-
$gte?: PrimitiveFilter<ObjectType>;
|
|
311
|
-
$in?: PrimitiveFilter<ObjectType>[];
|
|
312
|
-
$lt?: PrimitiveFilter<ObjectType>;
|
|
313
|
-
$lte?: PrimitiveFilter<ObjectType>;
|
|
314
|
-
}
|
|
315
|
-
: {
|
|
316
|
-
$eq?: PrimitiveFilter<ObjectType>;
|
|
317
|
-
$exists?: boolean;
|
|
318
|
-
$in?: PrimitiveFilter<Unpacked<ObjectType>>[];
|
|
319
|
-
};
|
|
320
|
-
|
|
321
239
|
export type UserFilters = QueryUsersPayload['filter_conditions'];
|
|
322
240
|
|
|
323
241
|
export type MemberFilters = QueryMembersPayload['filter_conditions'];
|
|
@@ -327,20 +245,16 @@ export type OGAttachment = RequireLiteral<Attachment, 'og_scrape_url'>;
|
|
|
327
245
|
export type PushProvider = CreateDeviceRequest['push_provider'];
|
|
328
246
|
|
|
329
247
|
/**
|
|
330
|
-
* Server-provided channel configuration, keyed by
|
|
331
|
-
*
|
|
332
|
-
*
|
|
248
|
+
* Server-provided channel configuration, keyed by cid (`messaging:general`). Keyed per channel
|
|
249
|
+
* because a channel's `config_overrides` can narrow its type's config. Read it via
|
|
250
|
+
* `channel.serverConfig`.
|
|
333
251
|
*/
|
|
334
252
|
export type Configs = Record<string, ChannelConfigWithInfo | undefined>;
|
|
335
253
|
|
|
336
254
|
export type ConnectionOpen = EventPayload<'health.check'> | EventPayload<'connection.ok'>;
|
|
337
255
|
|
|
338
256
|
/**
|
|
339
|
-
* The message `type` values the server can return.
|
|
340
|
-
*
|
|
341
|
-
* Hand-written because there is no generated equivalent: `MessageResponse['type']` is a bare
|
|
342
|
-
* `string`, so deriving it would widen rather than narrow. Both the React and React Native
|
|
343
|
-
* SDKs use this as a discriminant (RN types its SQLite message rows with it).
|
|
257
|
+
* The message `type` values the server can return (`MessageResponse['type']` is a bare `string`).
|
|
344
258
|
*/
|
|
345
259
|
export type MessageLabel =
|
|
346
260
|
| 'deleted'
|
|
@@ -356,8 +270,6 @@ export type TokenOrProvider = null | string | TokenProvider | undefined;
|
|
|
356
270
|
|
|
357
271
|
export type TokenProvider = () => Promise<string>;
|
|
358
272
|
|
|
359
|
-
export type MessageSetType = 'latest' | 'current' | 'new';
|
|
360
|
-
|
|
361
273
|
export class StreamAPIError<T = APIError> extends Error {
|
|
362
274
|
public code: number | undefined;
|
|
363
275
|
public status: number | undefined;
|
|
@@ -370,13 +282,9 @@ export class StreamAPIError<T = APIError> extends Error {
|
|
|
370
282
|
status,
|
|
371
283
|
response,
|
|
372
284
|
}: {
|
|
373
|
-
/**
|
|
374
|
-
* Stream error code (`APIError.code`)
|
|
375
|
-
*/
|
|
285
|
+
/** Stream error code (`APIError.code`) */
|
|
376
286
|
code: StreamAPIError<T>['code'];
|
|
377
|
-
/**
|
|
378
|
-
* HTTP status code
|
|
379
|
-
*/
|
|
287
|
+
/** HTTP status code */
|
|
380
288
|
status: StreamAPIError<T>['status'];
|
|
381
289
|
response: StreamAPIError<T>['response'];
|
|
382
290
|
},
|
|
@@ -424,9 +332,6 @@ export class StreamAPIError<T = APIError> extends Error {
|
|
|
424
332
|
}
|
|
425
333
|
}
|
|
426
334
|
|
|
427
|
-
/**
|
|
428
|
-
* Poll vote visibility. Derived from the generated request shape so it tracks the spec.
|
|
429
|
-
*/
|
|
430
335
|
export type VotingVisibility = NonNullable<CreatePollRequest['voting_visibility']>;
|
|
431
336
|
|
|
432
337
|
export type PartialPollUpdate = {
|
|
@@ -434,10 +339,7 @@ export type PartialPollUpdate = {
|
|
|
434
339
|
unset?: Array<keyof UpdatePollRequest>;
|
|
435
340
|
};
|
|
436
341
|
|
|
437
|
-
/**
|
|
438
|
-
* Options accepted by `moderation.flagUser` / `moderation.flagMessage` on top of the
|
|
439
|
-
* entity they resolve and the `reason` they take positionally.
|
|
440
|
-
*/
|
|
342
|
+
/** Options of `moderation.flagUser` / `moderation.flagMessage` besides the entity and `reason`. */
|
|
441
343
|
export type ModerationFlagOptions = Omit<
|
|
442
344
|
FlagRequest,
|
|
443
345
|
'entity_id' | 'entity_type' | 'reason'
|
|
@@ -461,26 +363,17 @@ export const AIStates = {
|
|
|
461
363
|
Thinking: 'AI_STATE_THINKING',
|
|
462
364
|
} as const satisfies Record<string, AIState>;
|
|
463
365
|
|
|
464
|
-
/**
|
|
465
|
-
* An identifier containing information about the downstream SDK using stream-chat. It
|
|
466
|
-
* is used to resolve the user agent.
|
|
467
|
-
*/
|
|
366
|
+
/** The downstream SDK using stream-chat, used to resolve the user agent. */
|
|
468
367
|
export type SdkIdentifier = {
|
|
469
368
|
name: 'react' | 'react-native' | 'expo' | 'angular';
|
|
470
369
|
version: string;
|
|
471
370
|
};
|
|
472
371
|
|
|
473
|
-
/**
|
|
474
|
-
* An identifier containing information about the downstream device using stream-chat, if
|
|
475
|
-
* available. Is used by the react-native SDKs to enrich the user agent further.
|
|
476
|
-
*/
|
|
372
|
+
/** The downstream device, used by the React Native SDKs to enrich the user agent. */
|
|
477
373
|
export type DeviceIdentifier = { os: string; model?: string };
|
|
478
374
|
|
|
479
375
|
/**
|
|
480
|
-
*
|
|
481
|
-
* stream-chat, if available. `name` is reported as `app` and `version` as `app_version`
|
|
482
|
-
* in the user agent. Distinct from the SDK ({@link SdkIdentifier}) and device
|
|
483
|
-
* ({@link DeviceIdentifier}) identifiers.
|
|
376
|
+
* The downstream app: `name` is reported as `app` and `version` as `app_version` in the user agent.
|
|
484
377
|
*/
|
|
485
378
|
export type AppIdentifier = { name: string; version?: string };
|
|
486
379
|
|
|
@@ -504,8 +397,6 @@ export type SharedLiveLocationResponse = RequireLiteral<
|
|
|
504
397
|
|
|
505
398
|
export type ThreadFilters = NonNullable<QueryThreadsRequest['filter']>;
|
|
506
399
|
|
|
507
|
-
export type CreateReminderOptions = Parameters<ChatApi['createReminder']>[0];
|
|
508
|
-
|
|
509
400
|
export type ReminderFilters = NonNullable<QueryRemindersRequest['filter']>;
|
|
510
401
|
|
|
511
402
|
export type ListUserGroupsOptions = NonNullable<Parameters<ChatApi['listUserGroups']>[0]>;
|
|
@@ -540,14 +431,10 @@ export type PartializeAllBut<T, K extends keyof T> = {
|
|
|
540
431
|
[P in K]-?: T[P];
|
|
541
432
|
} & { [P in Exclude<keyof T, K>]?: T[P] };
|
|
542
433
|
|
|
543
|
-
export type DeleteMessageOptions =
|
|
434
|
+
export type DeleteMessageOptions = NonNullable<Parameters<ChatApi['deleteMessage']>[1]>;
|
|
544
435
|
export type SendMessageAPIResponse = StreamResponse<SendMessageResponse>;
|
|
545
436
|
export type UpdateMessageOptions = Omit<UpdateMessageRequest, 'message'>;
|
|
546
437
|
export type UpdateMessageAPIResponse = StreamResponse<UpdateMessageResponse>;
|
|
547
|
-
/**
|
|
548
|
-
* The Giphy rendition names, derived from the generated `Images` shape so the two cannot
|
|
549
|
-
* drift. Consumed by the React and React Native SDKs to pick a rendition size.
|
|
550
|
-
*/
|
|
551
438
|
export type GiphyVersions = keyof Images;
|
|
552
439
|
export type TranslationLanguage = TranslateMessageRequest['language'];
|
|
553
440
|
|
|
@@ -560,8 +447,7 @@ export type FileReferenceBase = {
|
|
|
560
447
|
export type FileUploadInput = File | Blob | FileReferenceBase | string;
|
|
561
448
|
|
|
562
449
|
/**
|
|
563
|
-
* Structural subset of axios' `AxiosProgressEvent`,
|
|
564
|
-
* public surface does not depend on axios.
|
|
450
|
+
* Structural subset of axios' `AxiosProgressEvent`, so the public surface does not depend on axios.
|
|
565
451
|
*/
|
|
566
452
|
export type StreamProgressEvent = {
|
|
567
453
|
loaded: number;
|
|
@@ -574,6 +460,8 @@ export type StreamRequestOptions = {
|
|
|
574
460
|
signal?: AbortSignal;
|
|
575
461
|
/** Only meaningful for upload (multipart) requests; ignored everywhere else. */
|
|
576
462
|
onUploadProgress?: (event: StreamProgressEvent) => void;
|
|
463
|
+
/** Milliseconds before this request is aborted. */
|
|
464
|
+
timeout?: number;
|
|
577
465
|
};
|
|
578
466
|
|
|
579
467
|
export * from './gen/models';
|
package/src/types.utility.ts
CHANGED
|
@@ -3,9 +3,9 @@ export type DeepPartial<T> = {
|
|
|
3
3
|
};
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* The keys of every union member, not only those common to all
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* The keys of every union member, not only those common to all (`keyof (A | B)`). Distribution
|
|
7
|
+
* needs the naked type parameter: the same conditional inline over a concrete union yields the
|
|
8
|
+
* common keys.
|
|
9
9
|
*/
|
|
10
10
|
export type KeysOfUnion<T> = T extends unknown ? keyof T : never;
|
|
11
11
|
|
package/src/upload-utils.ts
CHANGED
|
@@ -9,17 +9,15 @@ const isFileReferenceBase = (value: unknown): value is FileReferenceBase =>
|
|
|
9
9
|
typeof (value as FileReferenceBase).uri === 'string';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* Wraps a bare URI string in a {@link FileReferenceBase}; `File`, `Blob` and picker objects pass
|
|
13
|
+
* through.
|
|
14
14
|
*/
|
|
15
15
|
export const normalizeUploadFile = (file?: FileUploadInput) =>
|
|
16
16
|
typeof file === 'string' ? { uri: file } : file;
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Appends one request-body entry to a multipart form
|
|
20
|
-
*
|
|
21
|
-
* Callers must pass **raw** values - objects and arrays are JSON-encoded here (that is what
|
|
22
|
-
* the API expects for `user` and `upload_sizes`), so pre-stringifying them double-encodes.
|
|
19
|
+
* Appends one request-body entry to a multipart form. Pass **raw** values: objects and arrays are
|
|
20
|
+
* JSON-encoded here, so pre-stringifying them double-encodes.
|
|
23
21
|
*/
|
|
24
22
|
export function appendToFormData(data: FormData, key: string, value: unknown) {
|
|
25
23
|
if (value === undefined || value === null) return;
|
|
@@ -42,10 +40,7 @@ export function appendToFormData(data: FormData, key: string, value: unknown) {
|
|
|
42
40
|
}
|
|
43
41
|
}
|
|
44
42
|
|
|
45
|
-
/**
|
|
46
|
-
* Encodes a request body as `multipart/form-data`. Used by `ApiClient.sendRequest` for every
|
|
47
|
-
* generated operation declaring that content type.
|
|
48
|
-
*/
|
|
43
|
+
/** Encodes a request body as `multipart/form-data`. */
|
|
49
44
|
export function toFormData(body: Record<string, unknown>) {
|
|
50
45
|
const data = new FormData();
|
|
51
46
|
for (const [key, value] of Object.entries(body)) appendToFormData(data, key, value);
|