stream-chat 9.40.0 → 9.41.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/dist/cjs/index.browser.js +115 -32
- package/dist/cjs/index.browser.js.map +2 -2
- package/dist/cjs/index.node.js +115 -32
- package/dist/cjs/index.node.js.map +2 -2
- package/dist/esm/index.mjs +115 -32
- package/dist/esm/index.mjs.map +2 -2
- package/dist/types/channel.d.ts +23 -2
- package/dist/types/client.d.ts +5 -3
- package/dist/types/messageComposer/attachmentManager.d.ts +3 -3
- package/dist/types/messageComposer/configuration/types.d.ts +11 -1
- package/dist/types/messageComposer/types.d.ts +2 -0
- package/package.json +1 -1
- package/src/channel.ts +25 -0
- package/src/client.ts +22 -2
- package/src/messageComposer/attachmentManager.ts +83 -16
- package/src/messageComposer/configuration/configuration.ts +1 -0
- package/src/messageComposer/configuration/types.ts +12 -0
- package/src/messageComposer/types.ts +2 -0
package/dist/esm/index.mjs
CHANGED
|
@@ -3213,12 +3213,18 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3213
3213
|
* Method to perform the default upload behavior without checking for custom upload functions
|
|
3214
3214
|
* to prevent recursive calls
|
|
3215
3215
|
*/
|
|
3216
|
-
this.doDefaultUploadRequest = async (fileLike) => {
|
|
3216
|
+
this.doDefaultUploadRequest = async (fileLike, options) => {
|
|
3217
|
+
const progressHandler = options?.onProgress ? (progressEvent) => {
|
|
3218
|
+
const percent = progressEvent.lengthComputable && progressEvent.total ? Math.round(progressEvent.loaded * 100 / progressEvent.total) : void 0;
|
|
3219
|
+
options.onProgress?.(percent);
|
|
3220
|
+
} : void 0;
|
|
3217
3221
|
if (isFileReference(fileLike)) {
|
|
3218
3222
|
return this.channel[isImageFile(fileLike) ? "sendImage" : "sendFile"](
|
|
3219
3223
|
fileLike.uri,
|
|
3220
3224
|
fileLike.name,
|
|
3221
|
-
fileLike.type
|
|
3225
|
+
fileLike.type,
|
|
3226
|
+
void 0,
|
|
3227
|
+
progressHandler ? { onUploadProgress: progressHandler } : void 0
|
|
3222
3228
|
);
|
|
3223
3229
|
}
|
|
3224
3230
|
const file = isFile(fileLike) ? fileLike : createFileFromBlobs({
|
|
@@ -3226,18 +3232,24 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3226
3232
|
fileName: generateFileName(fileLike.type),
|
|
3227
3233
|
mimeType: fileLike.type
|
|
3228
3234
|
});
|
|
3229
|
-
const { duration, ...result } = await this.channel[isImageFile(fileLike) ? "sendImage" : "sendFile"](
|
|
3235
|
+
const { duration, ...result } = await this.channel[isImageFile(fileLike) ? "sendImage" : "sendFile"](
|
|
3236
|
+
file,
|
|
3237
|
+
void 0,
|
|
3238
|
+
void 0,
|
|
3239
|
+
void 0,
|
|
3240
|
+
progressHandler ? { onUploadProgress: progressHandler } : void 0
|
|
3241
|
+
);
|
|
3230
3242
|
return result;
|
|
3231
3243
|
};
|
|
3232
3244
|
/**
|
|
3233
3245
|
* todo: docs how to customize the image and file upload by overriding do
|
|
3234
3246
|
*/
|
|
3235
|
-
this.doUploadRequest = async (fileLike) => {
|
|
3247
|
+
this.doUploadRequest = async (fileLike, options) => {
|
|
3236
3248
|
const customUploadFn = this.config.doUploadRequest;
|
|
3237
3249
|
if (customUploadFn) {
|
|
3238
|
-
return await customUploadFn(fileLike);
|
|
3250
|
+
return await customUploadFn(fileLike, options);
|
|
3239
3251
|
}
|
|
3240
|
-
return this.doDefaultUploadRequest(fileLike);
|
|
3252
|
+
return this.doDefaultUploadRequest(fileLike, options);
|
|
3241
3253
|
};
|
|
3242
3254
|
// @deprecated use attachmentManager.uploadFile(file)
|
|
3243
3255
|
this.uploadAttachment = async (attachment) => {
|
|
@@ -3261,25 +3273,41 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3261
3273
|
});
|
|
3262
3274
|
return localAttachment;
|
|
3263
3275
|
}
|
|
3264
|
-
this.
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
}
|
|
3276
|
+
const shouldTrackProgress = this.config.trackUploadProgress;
|
|
3277
|
+
const uploadingAttachment = {
|
|
3278
|
+
...attachment,
|
|
3279
|
+
localMetadata: {
|
|
3280
|
+
...attachment.localMetadata,
|
|
3281
|
+
uploadState: "uploading",
|
|
3282
|
+
...shouldTrackProgress && { uploadProgress: 0 }
|
|
3271
3283
|
}
|
|
3272
|
-
|
|
3284
|
+
};
|
|
3285
|
+
this.upsertAttachments([uploadingAttachment]);
|
|
3286
|
+
const uploadOptions = shouldTrackProgress ? {
|
|
3287
|
+
onProgress: (percent) => {
|
|
3288
|
+
this.updateAttachment({
|
|
3289
|
+
...uploadingAttachment,
|
|
3290
|
+
localMetadata: {
|
|
3291
|
+
...uploadingAttachment.localMetadata,
|
|
3292
|
+
uploadProgress: percent
|
|
3293
|
+
}
|
|
3294
|
+
});
|
|
3295
|
+
}
|
|
3296
|
+
} : void 0;
|
|
3273
3297
|
let response;
|
|
3274
3298
|
try {
|
|
3275
|
-
response = await this.doUploadRequest(
|
|
3299
|
+
response = await this.doUploadRequest(
|
|
3300
|
+
localAttachment.localMetadata.file,
|
|
3301
|
+
uploadOptions
|
|
3302
|
+
);
|
|
3276
3303
|
} catch (error) {
|
|
3277
3304
|
const reason = error instanceof Error ? error.message : "unknown error";
|
|
3278
3305
|
const failedAttachment = {
|
|
3279
3306
|
...attachment,
|
|
3280
3307
|
localMetadata: {
|
|
3281
3308
|
...attachment.localMetadata,
|
|
3282
|
-
uploadState: "failed"
|
|
3309
|
+
uploadState: "failed",
|
|
3310
|
+
uploadProgress: void 0
|
|
3283
3311
|
}
|
|
3284
3312
|
};
|
|
3285
3313
|
this.client.notifications.addError({
|
|
@@ -3305,7 +3333,8 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3305
3333
|
...attachment,
|
|
3306
3334
|
localMetadata: {
|
|
3307
3335
|
...attachment.localMetadata,
|
|
3308
|
-
uploadState: "finished"
|
|
3336
|
+
uploadState: "finished",
|
|
3337
|
+
uploadProgress: void 0
|
|
3309
3338
|
}
|
|
3310
3339
|
};
|
|
3311
3340
|
const previewUri = uploadedAttachment.localMetadata.previewUri;
|
|
@@ -3339,18 +3368,31 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3339
3368
|
this.upsertAttachments([attachment]);
|
|
3340
3369
|
return preUpload.state.attachment;
|
|
3341
3370
|
}
|
|
3371
|
+
const shouldTrackProgress = this.config.trackUploadProgress;
|
|
3342
3372
|
attachment = {
|
|
3343
3373
|
...attachment,
|
|
3344
3374
|
localMetadata: {
|
|
3345
3375
|
...attachment.localMetadata,
|
|
3346
|
-
uploadState: "uploading"
|
|
3376
|
+
uploadState: "uploading",
|
|
3377
|
+
...shouldTrackProgress && { uploadProgress: 0 }
|
|
3347
3378
|
}
|
|
3348
3379
|
};
|
|
3349
3380
|
this.upsertAttachments([attachment]);
|
|
3381
|
+
const uploadOptions = shouldTrackProgress ? {
|
|
3382
|
+
onProgress: (percent) => {
|
|
3383
|
+
this.updateAttachment({
|
|
3384
|
+
...attachment,
|
|
3385
|
+
localMetadata: {
|
|
3386
|
+
...attachment.localMetadata,
|
|
3387
|
+
uploadProgress: percent
|
|
3388
|
+
}
|
|
3389
|
+
});
|
|
3390
|
+
}
|
|
3391
|
+
} : void 0;
|
|
3350
3392
|
let response;
|
|
3351
3393
|
let error;
|
|
3352
3394
|
try {
|
|
3353
|
-
response = await this.doUploadRequest(file);
|
|
3395
|
+
response = await this.doUploadRequest(file, uploadOptions);
|
|
3354
3396
|
} catch (err) {
|
|
3355
3397
|
error = err instanceof Error ? err : void 0;
|
|
3356
3398
|
}
|
|
@@ -3361,7 +3403,8 @@ var _AttachmentManager = class _AttachmentManager {
|
|
|
3361
3403
|
...attachment,
|
|
3362
3404
|
localMetadata: {
|
|
3363
3405
|
...attachment.localMetadata,
|
|
3364
|
-
uploadState: error ? "failed" : "finished"
|
|
3406
|
+
uploadState: error ? "failed" : "finished",
|
|
3407
|
+
uploadProgress: void 0
|
|
3365
3408
|
}
|
|
3366
3409
|
},
|
|
3367
3410
|
error,
|
|
@@ -3529,7 +3572,8 @@ var DEFAULT_ATTACHMENT_MANAGER_CONFIG = {
|
|
|
3529
3572
|
acceptedFiles: [],
|
|
3530
3573
|
// an empty array means all files are accepted
|
|
3531
3574
|
fileUploadFilter: () => true,
|
|
3532
|
-
maxNumberOfFilesPerMessage: API_MAX_FILES_ALLOWED_PER_MESSAGE
|
|
3575
|
+
maxNumberOfFilesPerMessage: API_MAX_FILES_ALLOWED_PER_MESSAGE,
|
|
3576
|
+
trackUploadProgress: true
|
|
3533
3577
|
};
|
|
3534
3578
|
var DEFAULT_TEXT_COMPOSER_CONFIG = {
|
|
3535
3579
|
enabled: true,
|
|
@@ -7988,22 +8032,44 @@ var Channel = class {
|
|
|
7988
8032
|
}
|
|
7989
8033
|
return await this._sendMessage(message, options);
|
|
7990
8034
|
}
|
|
7991
|
-
|
|
8035
|
+
/**
|
|
8036
|
+
* Upload a file to this channel’s file endpoint (multipart). Forwards to the client’s `sendFile` implementation.
|
|
8037
|
+
*
|
|
8038
|
+
* @param uri File source: URL string, `File`, `Buffer`, or readable stream (Node).
|
|
8039
|
+
* @param name File name sent in the multipart body.
|
|
8040
|
+
* @param contentType MIME type; defaults are applied when omitted.
|
|
8041
|
+
* @param user Optional user payload appended to the form as JSON.
|
|
8042
|
+
* @param axiosRequestConfig Optional Axios per-request config, merged after upload defaults (e.g. `onUploadProgress`, `signal` from `AbortController`).
|
|
8043
|
+
* @return Promise resolving to `{ file: string, ... }` with the CDN URL.
|
|
8044
|
+
*/
|
|
8045
|
+
sendFile(uri, name, contentType, user, axiosRequestConfig) {
|
|
7992
8046
|
return this.getClient().sendFile(
|
|
7993
8047
|
`${this._channelURL()}/file`,
|
|
7994
8048
|
uri,
|
|
7995
8049
|
name,
|
|
7996
8050
|
contentType,
|
|
7997
|
-
user
|
|
8051
|
+
user,
|
|
8052
|
+
axiosRequestConfig
|
|
7998
8053
|
);
|
|
7999
8054
|
}
|
|
8000
|
-
|
|
8055
|
+
/**
|
|
8056
|
+
* Upload an image to this channel’s image endpoint (multipart). Uses the same transport as `sendFile`.
|
|
8057
|
+
*
|
|
8058
|
+
* @param uri Image source: URL string, `File`, or readable stream (Node). For `Buffer` uploads, use `sendFile` toward the channel file endpoint instead.
|
|
8059
|
+
* @param name File name sent in the multipart body.
|
|
8060
|
+
* @param contentType MIME type.
|
|
8061
|
+
* @param user Optional user payload appended to the form as JSON.
|
|
8062
|
+
* @param axiosRequestConfig Optional Axios per-request config, merged after upload defaults (e.g. `onUploadProgress`, `signal`).
|
|
8063
|
+
* @return Promise resolving to `{ file: string, ... }` with the CDN URL.
|
|
8064
|
+
*/
|
|
8065
|
+
sendImage(uri, name, contentType, user, axiosRequestConfig) {
|
|
8001
8066
|
return this.getClient().sendFile(
|
|
8002
8067
|
`${this._channelURL()}/image`,
|
|
8003
8068
|
uri,
|
|
8004
8069
|
name,
|
|
8005
8070
|
contentType,
|
|
8006
|
-
user
|
|
8071
|
+
user,
|
|
8072
|
+
axiosRequestConfig
|
|
8007
8073
|
);
|
|
8008
8074
|
}
|
|
8009
8075
|
deleteFile(url) {
|
|
@@ -13544,7 +13610,7 @@ var StreamChat = class _StreamChat {
|
|
|
13544
13610
|
delete(url, params) {
|
|
13545
13611
|
return this.doAxiosRequest("delete", url, null, { params });
|
|
13546
13612
|
}
|
|
13547
|
-
sendFile(url, uri, name, contentType, user) {
|
|
13613
|
+
sendFile(url, uri, name, contentType, user, axiosRequestConfig) {
|
|
13548
13614
|
const data = addFileToFormData(uri, name, contentType || "multipart/form-data");
|
|
13549
13615
|
if (user != null) data.append("user", JSON.stringify(user));
|
|
13550
13616
|
return this.doAxiosRequest("postForm", url, data, {
|
|
@@ -13553,7 +13619,8 @@ var StreamChat = class _StreamChat {
|
|
|
13553
13619
|
config: {
|
|
13554
13620
|
timeout: 0,
|
|
13555
13621
|
maxContentLength: Infinity,
|
|
13556
|
-
maxBodyLength: Infinity
|
|
13622
|
+
maxBodyLength: Infinity,
|
|
13623
|
+
...axiosRequestConfig
|
|
13557
13624
|
}
|
|
13558
13625
|
});
|
|
13559
13626
|
}
|
|
@@ -14982,7 +15049,7 @@ var StreamChat = class _StreamChat {
|
|
|
14982
15049
|
if (this.userAgent) {
|
|
14983
15050
|
return this.userAgent;
|
|
14984
15051
|
}
|
|
14985
|
-
const version = "9.
|
|
15052
|
+
const version = "9.41.0";
|
|
14986
15053
|
const clientBundle = "browser-esm";
|
|
14987
15054
|
let userAgentString = "";
|
|
14988
15055
|
if (this.sdkIdentifier) {
|
|
@@ -16120,11 +16187,19 @@ var StreamChat = class _StreamChat {
|
|
|
16120
16187
|
* @param {string} [name] The name of the file
|
|
16121
16188
|
* @param {string} [contentType] The content type of the file
|
|
16122
16189
|
* @param {UserResponse} [user] Optional user information
|
|
16190
|
+
* @param {AxiosRequestConfig} [axiosRequestConfig] Optional axios config (e.g. onUploadProgress for progress tracking)
|
|
16123
16191
|
*
|
|
16124
16192
|
* @return {Promise<SendFileAPIResponse>} Response containing the file URL
|
|
16125
16193
|
*/
|
|
16126
|
-
uploadFile(uri, name, contentType, user) {
|
|
16127
|
-
return this.sendFile(
|
|
16194
|
+
uploadFile(uri, name, contentType, user, axiosRequestConfig) {
|
|
16195
|
+
return this.sendFile(
|
|
16196
|
+
`${this.baseURL}/uploads/file`,
|
|
16197
|
+
uri,
|
|
16198
|
+
name,
|
|
16199
|
+
contentType,
|
|
16200
|
+
user,
|
|
16201
|
+
axiosRequestConfig
|
|
16202
|
+
);
|
|
16128
16203
|
}
|
|
16129
16204
|
/**
|
|
16130
16205
|
* uploadImage - Uploads an image to the configured storage (defaults to Stream CDN)
|
|
@@ -16133,11 +16208,19 @@ var StreamChat = class _StreamChat {
|
|
|
16133
16208
|
* @param {string} [name] The name of the image
|
|
16134
16209
|
* @param {string} [contentType] The content type of the image
|
|
16135
16210
|
* @param {UserResponse} [user] Optional user information
|
|
16211
|
+
* @param {AxiosRequestConfig} [axiosRequestConfig] Optional axios config (e.g. onUploadProgress for progress tracking)
|
|
16136
16212
|
*
|
|
16137
16213
|
* @return {Promise<SendFileAPIResponse>} Response containing the image URL
|
|
16138
16214
|
*/
|
|
16139
|
-
uploadImage(uri, name, contentType, user) {
|
|
16140
|
-
return this.sendFile(
|
|
16215
|
+
uploadImage(uri, name, contentType, user, axiosRequestConfig) {
|
|
16216
|
+
return this.sendFile(
|
|
16217
|
+
`${this.baseURL}/uploads/image`,
|
|
16218
|
+
uri,
|
|
16219
|
+
name,
|
|
16220
|
+
contentType,
|
|
16221
|
+
user,
|
|
16222
|
+
axiosRequestConfig
|
|
16223
|
+
);
|
|
16141
16224
|
}
|
|
16142
16225
|
/**
|
|
16143
16226
|
* deleteFile - Deletes a file from the configured storage
|