@liveblocks/node 3.23.0-exp2 → 3.23.0-exp4
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/index.cjs +349 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -3
- package/dist/index.d.ts +35 -3
- package/dist/index.js +322 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@ var _core = require('@liveblocks/core');
|
|
|
3
3
|
|
|
4
4
|
// src/version.ts
|
|
5
5
|
var PKG_NAME = "@liveblocks/node";
|
|
6
|
-
var PKG_VERSION = "3.23.0-
|
|
6
|
+
var PKG_VERSION = "3.23.0-exp4";
|
|
7
7
|
var PKG_FORMAT = "cjs";
|
|
8
8
|
|
|
9
9
|
// src/client.ts
|
|
@@ -24,6 +24,12 @@ var PKG_FORMAT = "cjs";
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
27
33
|
|
|
28
34
|
|
|
29
35
|
|
|
@@ -64,8 +70,8 @@ var LineStream = class extends TransformStream {
|
|
|
64
70
|
constructor() {
|
|
65
71
|
let buffer = "";
|
|
66
72
|
super({
|
|
67
|
-
transform(
|
|
68
|
-
buffer +=
|
|
73
|
+
transform(chunk2, controller) {
|
|
74
|
+
buffer += chunk2;
|
|
69
75
|
if (buffer.includes("\n")) {
|
|
70
76
|
const lines = buffer.split("\n");
|
|
71
77
|
for (let i = 0; i < lines.length - 1; i++) {
|
|
@@ -289,6 +295,158 @@ var Session = (_class = class {
|
|
|
289
295
|
}, _class);
|
|
290
296
|
|
|
291
297
|
// src/client.ts
|
|
298
|
+
var ROOM_FILE_PART_SIZE = 5 * 1024 * 1024;
|
|
299
|
+
var ROOM_FILE_RETRY_ATTEMPTS = 10;
|
|
300
|
+
var ROOM_FILE_RETRY_DELAYS = [
|
|
301
|
+
2e3,
|
|
302
|
+
2e3,
|
|
303
|
+
2e3,
|
|
304
|
+
2e3,
|
|
305
|
+
2e3,
|
|
306
|
+
2e3,
|
|
307
|
+
2e3,
|
|
308
|
+
2e3,
|
|
309
|
+
2e3,
|
|
310
|
+
2e3
|
|
311
|
+
];
|
|
312
|
+
async function uploadRoomFile({
|
|
313
|
+
file,
|
|
314
|
+
signal,
|
|
315
|
+
abortErrorMessage,
|
|
316
|
+
retryMultipartCompletion,
|
|
317
|
+
uploadSingle,
|
|
318
|
+
createMultipartUpload,
|
|
319
|
+
uploadMultipartPart,
|
|
320
|
+
completeMultipartUpload,
|
|
321
|
+
abortMultipartUpload
|
|
322
|
+
}) {
|
|
323
|
+
const abortError = createAbortError(abortErrorMessage);
|
|
324
|
+
if (_optionalChain([signal, 'optionalAccess', _2 => _2.aborted])) {
|
|
325
|
+
throw abortError;
|
|
326
|
+
}
|
|
327
|
+
const handleRetryError = (err) => {
|
|
328
|
+
if (_optionalChain([signal, 'optionalAccess', _3 => _3.aborted])) {
|
|
329
|
+
throw abortError;
|
|
330
|
+
}
|
|
331
|
+
return err instanceof LiveblocksError && err.status >= 400 && err.status < 500;
|
|
332
|
+
};
|
|
333
|
+
if (file.size <= ROOM_FILE_PART_SIZE) {
|
|
334
|
+
return _core.autoRetry.call(void 0,
|
|
335
|
+
uploadSingle,
|
|
336
|
+
ROOM_FILE_RETRY_ATTEMPTS,
|
|
337
|
+
ROOM_FILE_RETRY_DELAYS,
|
|
338
|
+
handleRetryError
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
let uploadId;
|
|
342
|
+
const uploadedParts = [];
|
|
343
|
+
const multipartUpload = await _core.autoRetry.call(void 0,
|
|
344
|
+
createMultipartUpload,
|
|
345
|
+
ROOM_FILE_RETRY_ATTEMPTS,
|
|
346
|
+
ROOM_FILE_RETRY_DELAYS,
|
|
347
|
+
handleRetryError
|
|
348
|
+
);
|
|
349
|
+
const partUploadController = new AbortController();
|
|
350
|
+
const partUploadSignal = partUploadController.signal;
|
|
351
|
+
const abortPartUploads = (reason) => {
|
|
352
|
+
partUploadController.abort(reason);
|
|
353
|
+
};
|
|
354
|
+
const handleExternalAbort = () => abortPartUploads();
|
|
355
|
+
if (_optionalChain([signal, 'optionalAccess', _4 => _4.aborted])) {
|
|
356
|
+
handleExternalAbort();
|
|
357
|
+
} else {
|
|
358
|
+
_optionalChain([signal, 'optionalAccess', _5 => _5.addEventListener, 'call', _6 => _6("abort", handleExternalAbort, { once: true })]);
|
|
359
|
+
}
|
|
360
|
+
try {
|
|
361
|
+
uploadId = multipartUpload.uploadId;
|
|
362
|
+
if (_optionalChain([signal, 'optionalAccess', _7 => _7.aborted])) {
|
|
363
|
+
throw abortError;
|
|
364
|
+
}
|
|
365
|
+
const batches = _core.chunk.call(void 0, splitRoomFileIntoParts(file), 5);
|
|
366
|
+
for (const parts of batches) {
|
|
367
|
+
const firstPartUploadFailure = {};
|
|
368
|
+
const partUploads$ = [];
|
|
369
|
+
for (const { part, partNumber } of parts) {
|
|
370
|
+
partUploads$.push(
|
|
371
|
+
_core.autoRetry.call(void 0,
|
|
372
|
+
() => uploadMultipartPart(
|
|
373
|
+
multipartUpload.uploadId,
|
|
374
|
+
partNumber,
|
|
375
|
+
part,
|
|
376
|
+
partUploadSignal
|
|
377
|
+
),
|
|
378
|
+
ROOM_FILE_RETRY_ATTEMPTS,
|
|
379
|
+
ROOM_FILE_RETRY_DELAYS,
|
|
380
|
+
(error) => {
|
|
381
|
+
if (_optionalChain([signal, 'optionalAccess', _8 => _8.aborted])) {
|
|
382
|
+
throw abortError;
|
|
383
|
+
}
|
|
384
|
+
return partUploadSignal.aborted || handleRetryError(error);
|
|
385
|
+
}
|
|
386
|
+
).catch((error) => {
|
|
387
|
+
if (firstPartUploadFailure.value === void 0) {
|
|
388
|
+
firstPartUploadFailure.value = { error };
|
|
389
|
+
abortPartUploads(error);
|
|
390
|
+
}
|
|
391
|
+
throw error;
|
|
392
|
+
})
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
const settledPartUploads = await Promise.allSettled(partUploads$);
|
|
396
|
+
if (firstPartUploadFailure.value !== void 0) {
|
|
397
|
+
throw firstPartUploadFailure.value.error;
|
|
398
|
+
}
|
|
399
|
+
for (const settledPartUpload of settledPartUploads) {
|
|
400
|
+
if (settledPartUpload.status === "fulfilled") {
|
|
401
|
+
uploadedParts.push(settledPartUpload.value);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (_optionalChain([signal, 'optionalAccess', _9 => _9.aborted])) {
|
|
406
|
+
throw abortError;
|
|
407
|
+
}
|
|
408
|
+
const sortedParts = uploadedParts.sort(
|
|
409
|
+
(a, b) => a.partNumber - b.partNumber
|
|
410
|
+
);
|
|
411
|
+
return retryMultipartCompletion ? _core.autoRetry.call(void 0,
|
|
412
|
+
() => completeMultipartUpload(multipartUpload.uploadId, sortedParts),
|
|
413
|
+
ROOM_FILE_RETRY_ATTEMPTS,
|
|
414
|
+
ROOM_FILE_RETRY_DELAYS,
|
|
415
|
+
handleRetryError
|
|
416
|
+
) : completeMultipartUpload(uploadId, sortedParts);
|
|
417
|
+
} catch (err) {
|
|
418
|
+
if (uploadId) {
|
|
419
|
+
try {
|
|
420
|
+
await abortMultipartUpload(uploadId);
|
|
421
|
+
} catch (e2) {
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
throw err;
|
|
425
|
+
} finally {
|
|
426
|
+
_optionalChain([signal, 'optionalAccess', _10 => _10.removeEventListener, 'call', _11 => _11("abort", handleExternalAbort)]);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
function splitRoomFileIntoParts(file) {
|
|
430
|
+
const parts = [];
|
|
431
|
+
let start = 0;
|
|
432
|
+
while (start < file.size) {
|
|
433
|
+
const end = Math.min(start + ROOM_FILE_PART_SIZE, file.size);
|
|
434
|
+
parts.push({
|
|
435
|
+
partNumber: parts.length + 1,
|
|
436
|
+
part: file.slice(start, end)
|
|
437
|
+
});
|
|
438
|
+
start = end;
|
|
439
|
+
}
|
|
440
|
+
return parts;
|
|
441
|
+
}
|
|
442
|
+
function createAbortError(message) {
|
|
443
|
+
if (typeof DOMException === "function") {
|
|
444
|
+
return new DOMException(message, "AbortError");
|
|
445
|
+
}
|
|
446
|
+
const err = new Error(message);
|
|
447
|
+
err.name = "AbortError";
|
|
448
|
+
return err;
|
|
449
|
+
}
|
|
292
450
|
function inflateRoomData(room) {
|
|
293
451
|
const createdAt = new Date(room.createdAt);
|
|
294
452
|
const lastConnectionAt = room.lastConnectionAt ? new Date(room.lastConnectionAt) : void 0;
|
|
@@ -359,8 +517,8 @@ var Liveblocks = class {
|
|
|
359
517
|
this.#baseUrl = new URL(getBaseUrl(options.baseUrl));
|
|
360
518
|
this.#localDev = !!options.baseUrl && /^https?:\/\/localhost[:/]/.test(options.baseUrl);
|
|
361
519
|
}
|
|
362
|
-
async #post(path, json, options) {
|
|
363
|
-
const url3 = _core.urljoin.call(void 0, this.#baseUrl, path);
|
|
520
|
+
async #post(path, json, options, params) {
|
|
521
|
+
const url3 = _core.urljoin.call(void 0, this.#baseUrl, path, params);
|
|
364
522
|
const headers = {
|
|
365
523
|
Authorization: `Bearer ${this.#secret}`,
|
|
366
524
|
"Content-Type": "application/json"
|
|
@@ -370,11 +528,17 @@ var Liveblocks = class {
|
|
|
370
528
|
method: "POST",
|
|
371
529
|
headers,
|
|
372
530
|
body: JSON.stringify(json),
|
|
373
|
-
signal: _optionalChain([options, 'optionalAccess',
|
|
531
|
+
signal: _optionalChain([options, 'optionalAccess', _12 => _12.signal])
|
|
374
532
|
});
|
|
375
533
|
xwarn(res, "POST", path);
|
|
376
534
|
return res;
|
|
377
535
|
}
|
|
536
|
+
async #readJsonResponse(res) {
|
|
537
|
+
if (!res.ok) {
|
|
538
|
+
throw await LiveblocksError.from(res);
|
|
539
|
+
}
|
|
540
|
+
return await res.json();
|
|
541
|
+
}
|
|
378
542
|
async #patch(path, json, options) {
|
|
379
543
|
const url3 = _core.urljoin.call(void 0, this.#baseUrl, path);
|
|
380
544
|
const headers = {
|
|
@@ -386,7 +550,7 @@ var Liveblocks = class {
|
|
|
386
550
|
method: "PATCH",
|
|
387
551
|
headers,
|
|
388
552
|
body: JSON.stringify(json),
|
|
389
|
-
signal: _optionalChain([options, 'optionalAccess',
|
|
553
|
+
signal: _optionalChain([options, 'optionalAccess', _13 => _13.signal])
|
|
390
554
|
});
|
|
391
555
|
xwarn(res, "PATCH", path);
|
|
392
556
|
return res;
|
|
@@ -402,7 +566,23 @@ var Liveblocks = class {
|
|
|
402
566
|
method: "PUT",
|
|
403
567
|
headers,
|
|
404
568
|
body,
|
|
405
|
-
signal: _optionalChain([options, 'optionalAccess',
|
|
569
|
+
signal: _optionalChain([options, 'optionalAccess', _14 => _14.signal])
|
|
570
|
+
});
|
|
571
|
+
xwarn(res, "PUT", path);
|
|
572
|
+
return res;
|
|
573
|
+
}
|
|
574
|
+
async #putBlob(path, body, params, options) {
|
|
575
|
+
const url3 = _core.urljoin.call(void 0, this.#baseUrl, path, params);
|
|
576
|
+
const headers = {
|
|
577
|
+
Authorization: `Bearer ${this.#secret}`,
|
|
578
|
+
"Content-Type": "application/octet-stream"
|
|
579
|
+
};
|
|
580
|
+
const fetch = await fetchPolyfill();
|
|
581
|
+
const res = await fetch(url3, {
|
|
582
|
+
method: "PUT",
|
|
583
|
+
headers,
|
|
584
|
+
body,
|
|
585
|
+
signal: _optionalChain([options, 'optionalAccess', _15 => _15.signal])
|
|
406
586
|
});
|
|
407
587
|
xwarn(res, "PUT", path);
|
|
408
588
|
return res;
|
|
@@ -416,7 +596,7 @@ var Liveblocks = class {
|
|
|
416
596
|
const res = await fetch(url3, {
|
|
417
597
|
method: "DELETE",
|
|
418
598
|
headers,
|
|
419
|
-
signal: _optionalChain([options, 'optionalAccess',
|
|
599
|
+
signal: _optionalChain([options, 'optionalAccess', _16 => _16.signal])
|
|
420
600
|
});
|
|
421
601
|
xwarn(res, "DELETE", path);
|
|
422
602
|
return res;
|
|
@@ -430,7 +610,7 @@ var Liveblocks = class {
|
|
|
430
610
|
const res = await fetch(url3, {
|
|
431
611
|
method: "GET",
|
|
432
612
|
headers,
|
|
433
|
-
signal: _optionalChain([options, 'optionalAccess',
|
|
613
|
+
signal: _optionalChain([options, 'optionalAccess', _17 => _17.signal])
|
|
434
614
|
});
|
|
435
615
|
xwarn(res, "GET", path);
|
|
436
616
|
return res;
|
|
@@ -461,8 +641,8 @@ var Liveblocks = class {
|
|
|
461
641
|
return new Session(
|
|
462
642
|
this.#post.bind(this),
|
|
463
643
|
userId,
|
|
464
|
-
_optionalChain([options, 'optionalAccess',
|
|
465
|
-
_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
644
|
+
_optionalChain([options, 'optionalAccess', _18 => _18.userInfo]),
|
|
645
|
+
_nullishCoalesce(_optionalChain([options, 'optionalAccess', _19 => _19.organizationId]), () => ( _optionalChain([options, 'optionalAccess', _20 => _20.tenantId]))),
|
|
466
646
|
this.#localDev
|
|
467
647
|
);
|
|
468
648
|
}
|
|
@@ -512,7 +692,7 @@ var Liveblocks = class {
|
|
|
512
692
|
const body = {
|
|
513
693
|
userId,
|
|
514
694
|
groupIds,
|
|
515
|
-
userInfo: _optionalChain([options, 'optionalAccess',
|
|
695
|
+
userInfo: _optionalChain([options, 'optionalAccess', _21 => _21.userInfo])
|
|
516
696
|
};
|
|
517
697
|
if (organizationId !== void 0) {
|
|
518
698
|
body.organizationId = organizationId;
|
|
@@ -598,7 +778,7 @@ var Liveblocks = class {
|
|
|
598
778
|
*/
|
|
599
779
|
async *iterRooms(criteria, options) {
|
|
600
780
|
const { signal } = _nullishCoalesce(options, () => ( {}));
|
|
601
|
-
const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
781
|
+
const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess', _22 => _22.pageSize]), () => ( 40)), 20);
|
|
602
782
|
let cursor = void 0;
|
|
603
783
|
while (true) {
|
|
604
784
|
const { nextCursor, data } = await this.getRooms(
|
|
@@ -648,7 +828,7 @@ var Liveblocks = class {
|
|
|
648
828
|
body.organizationId = tenantId;
|
|
649
829
|
}
|
|
650
830
|
const res = await this.#post(
|
|
651
|
-
_optionalChain([options, 'optionalAccess',
|
|
831
|
+
_optionalChain([options, 'optionalAccess', _23 => _23.idempotent]) ? _core.url`/v2/rooms?idempotent` : _core.url`/v2/rooms`,
|
|
652
832
|
body,
|
|
653
833
|
options
|
|
654
834
|
);
|
|
@@ -1174,6 +1354,7 @@ var Liveblocks = class {
|
|
|
1174
1354
|
* @param params.data.userId The user ID of the user who is set to create the comment.
|
|
1175
1355
|
* @param params.data.createdAt (optional) The date the comment is set to be created.
|
|
1176
1356
|
* @param params.data.body The body of the comment.
|
|
1357
|
+
* @param params.data.attachmentIds (optional) The attachment IDs to add to the comment.
|
|
1177
1358
|
* @param params.data.metadata (optional) The metadata for the comment.
|
|
1178
1359
|
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1179
1360
|
* @returns The created comment.
|
|
@@ -1184,7 +1365,7 @@ var Liveblocks = class {
|
|
|
1184
1365
|
_core.url`/v2/rooms/${roomId}/threads/${threadId}/comments`,
|
|
1185
1366
|
{
|
|
1186
1367
|
...data,
|
|
1187
|
-
createdAt: _optionalChain([data, 'access',
|
|
1368
|
+
createdAt: _optionalChain([data, 'access', _24 => _24.createdAt, 'optionalAccess', _25 => _25.toISOString, 'call', _26 => _26()])
|
|
1188
1369
|
},
|
|
1189
1370
|
options
|
|
1190
1371
|
);
|
|
@@ -1199,6 +1380,7 @@ var Liveblocks = class {
|
|
|
1199
1380
|
* @param params.threadId The thread ID to edit the comment in.
|
|
1200
1381
|
* @param params.commentId The comment ID to edit.
|
|
1201
1382
|
* @param params.data.body The body of the comment.
|
|
1383
|
+
* @param params.data.attachmentIds (optional) The IDs of every attachment that should remain on the comment.
|
|
1202
1384
|
* @param params.data.metadata (optional) The metadata for the comment. Value must be a string, boolean or number. Use null to delete a key.
|
|
1203
1385
|
* @param params.data.editedAt (optional) The date the comment was edited.
|
|
1204
1386
|
* @param options.signal (optional) An abort signal to cancel the request.
|
|
@@ -1210,7 +1392,8 @@ var Liveblocks = class {
|
|
|
1210
1392
|
_core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}`,
|
|
1211
1393
|
{
|
|
1212
1394
|
body: data.body,
|
|
1213
|
-
editedAt: _optionalChain([data, 'access',
|
|
1395
|
+
editedAt: _optionalChain([data, 'access', _27 => _27.editedAt, 'optionalAccess', _28 => _28.toISOString, 'call', _29 => _29()]),
|
|
1396
|
+
attachmentIds: data.attachmentIds,
|
|
1214
1397
|
metadata: data.metadata
|
|
1215
1398
|
},
|
|
1216
1399
|
options
|
|
@@ -1258,6 +1441,137 @@ var Liveblocks = class {
|
|
|
1258
1441
|
}
|
|
1259
1442
|
return await res.json();
|
|
1260
1443
|
}
|
|
1444
|
+
/**
|
|
1445
|
+
* Uploads an attachment that can be added to a comment.
|
|
1446
|
+
*
|
|
1447
|
+
* @param params.roomId The room ID to upload the attachment to.
|
|
1448
|
+
* @param params.userId The user ID of the user uploading the attachment.
|
|
1449
|
+
* @param params.file The file to upload.
|
|
1450
|
+
* @param options.signal (optional) An abort signal to cancel the upload.
|
|
1451
|
+
* @returns The uploaded attachment.
|
|
1452
|
+
*/
|
|
1453
|
+
async uploadAttachment(params, options) {
|
|
1454
|
+
const { roomId, userId, file } = params;
|
|
1455
|
+
const attachmentId = _core.createCommentAttachmentId.call(void 0, );
|
|
1456
|
+
return await uploadRoomFile({
|
|
1457
|
+
file,
|
|
1458
|
+
signal: _optionalChain([options, 'optionalAccess', _30 => _30.signal]),
|
|
1459
|
+
abortErrorMessage: `Upload of attachment ${attachmentId} was aborted.`,
|
|
1460
|
+
retryMultipartCompletion: false,
|
|
1461
|
+
uploadSingle: async () => {
|
|
1462
|
+
const res = await this.#putBlob(
|
|
1463
|
+
_core.url`/v2/rooms/${roomId}/attachments/${attachmentId}/upload/${file.name}`,
|
|
1464
|
+
file,
|
|
1465
|
+
{ fileSize: file.size, userId },
|
|
1466
|
+
options
|
|
1467
|
+
);
|
|
1468
|
+
return await this.#readJsonResponse(res);
|
|
1469
|
+
},
|
|
1470
|
+
createMultipartUpload: async () => {
|
|
1471
|
+
const res = await this.#post(
|
|
1472
|
+
_core.url`/v2/rooms/${roomId}/attachments/${attachmentId}/multipart/${file.name}`,
|
|
1473
|
+
void 0,
|
|
1474
|
+
options,
|
|
1475
|
+
{ fileSize: file.size }
|
|
1476
|
+
);
|
|
1477
|
+
return await this.#readJsonResponse(res);
|
|
1478
|
+
},
|
|
1479
|
+
uploadMultipartPart: async (uploadId, partNumber, part, signal) => {
|
|
1480
|
+
const res = await this.#putBlob(
|
|
1481
|
+
_core.url`/v2/rooms/${roomId}/attachments/${attachmentId}/multipart/${uploadId}/${String(partNumber)}`,
|
|
1482
|
+
part,
|
|
1483
|
+
void 0,
|
|
1484
|
+
{ signal }
|
|
1485
|
+
);
|
|
1486
|
+
return await this.#readJsonResponse(res);
|
|
1487
|
+
},
|
|
1488
|
+
completeMultipartUpload: async (uploadId, parts) => {
|
|
1489
|
+
const res = await this.#post(
|
|
1490
|
+
_core.url`/v2/rooms/${roomId}/attachments/${attachmentId}/multipart/${uploadId}/complete`,
|
|
1491
|
+
{ parts },
|
|
1492
|
+
options,
|
|
1493
|
+
{ userId }
|
|
1494
|
+
);
|
|
1495
|
+
return await this.#readJsonResponse(res);
|
|
1496
|
+
},
|
|
1497
|
+
abortMultipartUpload: async (uploadId) => {
|
|
1498
|
+
const res = await this.#delete(
|
|
1499
|
+
_core.url`/v2/rooms/${roomId}/attachments/${attachmentId}/multipart/${uploadId}`
|
|
1500
|
+
);
|
|
1501
|
+
if (!res.ok) {
|
|
1502
|
+
throw await LiveblocksError.from(res);
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
});
|
|
1506
|
+
}
|
|
1507
|
+
async uploadFile(params, options) {
|
|
1508
|
+
const { roomId, file } = params;
|
|
1509
|
+
const fileId = _core.createStorageFileId.call(void 0, );
|
|
1510
|
+
const fileData = await uploadRoomFile({
|
|
1511
|
+
file,
|
|
1512
|
+
signal: _optionalChain([options, 'optionalAccess', _31 => _31.signal]),
|
|
1513
|
+
abortErrorMessage: `Upload of file ${fileId} was aborted.`,
|
|
1514
|
+
retryMultipartCompletion: true,
|
|
1515
|
+
uploadSingle: async () => {
|
|
1516
|
+
const res = await this.#putBlob(
|
|
1517
|
+
_core.url`/v2/rooms/${roomId}/storage/files/${fileId}/upload/${file.name}`,
|
|
1518
|
+
file,
|
|
1519
|
+
{ fileSize: file.size },
|
|
1520
|
+
options
|
|
1521
|
+
);
|
|
1522
|
+
return await this.#readJsonResponse(res);
|
|
1523
|
+
},
|
|
1524
|
+
createMultipartUpload: async () => {
|
|
1525
|
+
const res = await this.#post(
|
|
1526
|
+
_core.url`/v2/rooms/${roomId}/storage/files/${fileId}/multipart/${file.name}`,
|
|
1527
|
+
void 0,
|
|
1528
|
+
options,
|
|
1529
|
+
{ fileSize: file.size }
|
|
1530
|
+
);
|
|
1531
|
+
return await this.#readJsonResponse(res);
|
|
1532
|
+
},
|
|
1533
|
+
uploadMultipartPart: async (uploadId, partNumber, part, signal) => {
|
|
1534
|
+
const res = await this.#putBlob(
|
|
1535
|
+
_core.url`/v2/rooms/${roomId}/storage/files/${fileId}/multipart/${uploadId}/${String(partNumber)}`,
|
|
1536
|
+
part,
|
|
1537
|
+
void 0,
|
|
1538
|
+
{ signal }
|
|
1539
|
+
);
|
|
1540
|
+
return await this.#readJsonResponse(res);
|
|
1541
|
+
},
|
|
1542
|
+
completeMultipartUpload: async (uploadId, parts) => {
|
|
1543
|
+
const res = await this.#post(
|
|
1544
|
+
_core.url`/v2/rooms/${roomId}/storage/files/${fileId}/multipart/${uploadId}/complete`,
|
|
1545
|
+
{ parts },
|
|
1546
|
+
options
|
|
1547
|
+
);
|
|
1548
|
+
return await this.#readJsonResponse(res);
|
|
1549
|
+
},
|
|
1550
|
+
abortMultipartUpload: async (uploadId) => {
|
|
1551
|
+
const res = await this.#delete(
|
|
1552
|
+
_core.url`/v2/rooms/${roomId}/storage/files/${fileId}/multipart/${uploadId}`
|
|
1553
|
+
);
|
|
1554
|
+
if (!res.ok) {
|
|
1555
|
+
throw await LiveblocksError.from(res);
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
});
|
|
1559
|
+
return new (0, _core.LiveFile)(fileData);
|
|
1560
|
+
}
|
|
1561
|
+
async getFileUrl(params, options) {
|
|
1562
|
+
const { roomId, file } = params;
|
|
1563
|
+
const fileId = _core.getLiveFileId.call(void 0, file);
|
|
1564
|
+
const res = await this.#get(
|
|
1565
|
+
_core.url`/v2/rooms/${roomId}/storage/files/${fileId}`,
|
|
1566
|
+
void 0,
|
|
1567
|
+
options
|
|
1568
|
+
);
|
|
1569
|
+
const storageFile = await this.#readJsonResponse(res);
|
|
1570
|
+
return {
|
|
1571
|
+
url: storageFile.url,
|
|
1572
|
+
expiresAt: storageFile.expiresAt
|
|
1573
|
+
};
|
|
1574
|
+
}
|
|
1261
1575
|
/**
|
|
1262
1576
|
* Creates a new thread. The thread will be created with the specified comment as its first comment.
|
|
1263
1577
|
* If the thread already exists, a `LiveblocksError` will be thrown with status code 409.
|
|
@@ -1266,6 +1580,7 @@ var Liveblocks = class {
|
|
|
1266
1580
|
* @param params.thread.comment.userId The user ID of the user who created the comment.
|
|
1267
1581
|
* @param params.thread.comment.createdAt (optional) The date the comment was created.
|
|
1268
1582
|
* @param params.thread.comment.body The body of the comment.
|
|
1583
|
+
* @param params.thread.comment.attachmentIds (optional) The attachment IDs to add to the comment.
|
|
1269
1584
|
* @param params.thread.comment.metadata (optional) The metadata for the comment.
|
|
1270
1585
|
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1271
1586
|
* @returns The created thread. The thread will be created with the specified comment as its first comment.
|
|
@@ -1278,7 +1593,7 @@ var Liveblocks = class {
|
|
|
1278
1593
|
...data,
|
|
1279
1594
|
comment: {
|
|
1280
1595
|
...data.comment,
|
|
1281
|
-
createdAt: _optionalChain([data, 'access',
|
|
1596
|
+
createdAt: _optionalChain([data, 'access', _32 => _32.comment, 'access', _33 => _33.createdAt, 'optionalAccess', _34 => _34.toISOString, 'call', _35 => _35()])
|
|
1282
1597
|
}
|
|
1283
1598
|
},
|
|
1284
1599
|
options
|
|
@@ -1401,7 +1716,7 @@ var Liveblocks = class {
|
|
|
1401
1716
|
_core.url`/v2/rooms/${roomId}/threads/${threadId}/metadata`,
|
|
1402
1717
|
{
|
|
1403
1718
|
...data,
|
|
1404
|
-
updatedAt: _optionalChain([data, 'access',
|
|
1719
|
+
updatedAt: _optionalChain([data, 'access', _36 => _36.updatedAt, 'optionalAccess', _37 => _37.toISOString, 'call', _38 => _38()])
|
|
1405
1720
|
},
|
|
1406
1721
|
options
|
|
1407
1722
|
);
|
|
@@ -1427,7 +1742,7 @@ var Liveblocks = class {
|
|
|
1427
1742
|
_core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}/metadata`,
|
|
1428
1743
|
{
|
|
1429
1744
|
...data,
|
|
1430
|
-
updatedAt: _optionalChain([data, 'access',
|
|
1745
|
+
updatedAt: _optionalChain([data, 'access', _39 => _39.updatedAt, 'optionalAccess', _40 => _40.toISOString, 'call', _41 => _41()])
|
|
1431
1746
|
},
|
|
1432
1747
|
options
|
|
1433
1748
|
);
|
|
@@ -1453,7 +1768,7 @@ var Liveblocks = class {
|
|
|
1453
1768
|
_core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}/add-reaction`,
|
|
1454
1769
|
{
|
|
1455
1770
|
...data,
|
|
1456
|
-
createdAt: _optionalChain([data, 'access',
|
|
1771
|
+
createdAt: _optionalChain([data, 'access', _42 => _42.createdAt, 'optionalAccess', _43 => _43.toISOString, 'call', _44 => _44()])
|
|
1457
1772
|
},
|
|
1458
1773
|
options
|
|
1459
1774
|
);
|
|
@@ -1479,7 +1794,7 @@ var Liveblocks = class {
|
|
|
1479
1794
|
_core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${params.commentId}/remove-reaction`,
|
|
1480
1795
|
{
|
|
1481
1796
|
...data,
|
|
1482
|
-
removedAt: _optionalChain([data, 'access',
|
|
1797
|
+
removedAt: _optionalChain([data, 'access', _45 => _45.removedAt, 'optionalAccess', _46 => _46.toISOString, 'call', _47 => _47()])
|
|
1483
1798
|
},
|
|
1484
1799
|
options
|
|
1485
1800
|
);
|
|
@@ -1560,7 +1875,7 @@ var Liveblocks = class {
|
|
|
1560
1875
|
*/
|
|
1561
1876
|
async *iterInboxNotifications(criteria, options) {
|
|
1562
1877
|
const { signal } = _nullishCoalesce(options, () => ( {}));
|
|
1563
|
-
const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1878
|
+
const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess', _48 => _48.pageSize]), () => ( 50)), 10);
|
|
1564
1879
|
let cursor = void 0;
|
|
1565
1880
|
while (true) {
|
|
1566
1881
|
const { nextCursor, data } = await this.getInboxNotifications(
|
|
@@ -1907,7 +2222,7 @@ var Liveblocks = class {
|
|
|
1907
2222
|
async getGroups(params, options) {
|
|
1908
2223
|
const res = await this.#get(
|
|
1909
2224
|
_core.url`/v2/groups`,
|
|
1910
|
-
{ startingAfter: _optionalChain([params, 'optionalAccess',
|
|
2225
|
+
{ startingAfter: _optionalChain([params, 'optionalAccess', _49 => _49.startingAfter]), limit: _optionalChain([params, 'optionalAccess', _50 => _50.limit]) },
|
|
1911
2226
|
options
|
|
1912
2227
|
);
|
|
1913
2228
|
if (!res.ok) {
|
|
@@ -1969,7 +2284,7 @@ var Liveblocks = class {
|
|
|
1969
2284
|
async massMutateStorage(criteria, callback, massOptions) {
|
|
1970
2285
|
const concurrency = _core.checkBounds.call(void 0,
|
|
1971
2286
|
"concurrency",
|
|
1972
|
-
_nullishCoalesce(_optionalChain([massOptions, 'optionalAccess',
|
|
2287
|
+
_nullishCoalesce(_optionalChain([massOptions, 'optionalAccess', _51 => _51.concurrency]), () => ( 8)),
|
|
1973
2288
|
1,
|
|
1974
2289
|
20
|
|
1975
2290
|
);
|
|
@@ -1985,7 +2300,7 @@ var Liveblocks = class {
|
|
|
1985
2300
|
}
|
|
1986
2301
|
async #_mutateOneRoom(roomId, room, callback, options) {
|
|
1987
2302
|
const debounceInterval = 200;
|
|
1988
|
-
const { signal, abort } = _core.makeAbortController.call(void 0, _optionalChain([options, 'optionalAccess',
|
|
2303
|
+
const { signal, abort } = _core.makeAbortController.call(void 0, _optionalChain([options, 'optionalAccess', _52 => _52.signal]));
|
|
1989
2304
|
let opsBuffer = [];
|
|
1990
2305
|
let outstandingFlush$ = void 0;
|
|
1991
2306
|
let lastFlush = performance.now();
|
|
@@ -2051,7 +2366,7 @@ var Liveblocks = class {
|
|
|
2051
2366
|
const res = await this.#post(
|
|
2052
2367
|
_core.url`/v2/rooms/${roomId}/send-message`,
|
|
2053
2368
|
{ messages },
|
|
2054
|
-
{ signal: _optionalChain([options, 'optionalAccess',
|
|
2369
|
+
{ signal: _optionalChain([options, 'optionalAccess', _53 => _53.signal]) }
|
|
2055
2370
|
);
|
|
2056
2371
|
if (!res.ok) {
|
|
2057
2372
|
throw await LiveblocksError.from(res);
|
|
@@ -2188,7 +2503,7 @@ var Liveblocks = class {
|
|
|
2188
2503
|
"Content-Type": params.file.type,
|
|
2189
2504
|
"Content-Length": String(params.file.size)
|
|
2190
2505
|
},
|
|
2191
|
-
signal: _optionalChain([options, 'optionalAccess',
|
|
2506
|
+
signal: _optionalChain([options, 'optionalAccess', _54 => _54.signal])
|
|
2192
2507
|
}
|
|
2193
2508
|
);
|
|
2194
2509
|
if (!res.ok) {
|
|
@@ -2535,7 +2850,7 @@ ${this.details}`;
|
|
|
2535
2850
|
let text;
|
|
2536
2851
|
try {
|
|
2537
2852
|
text = await res.text();
|
|
2538
|
-
} catch (
|
|
2853
|
+
} catch (e3) {
|
|
2539
2854
|
text = FALLBACK;
|
|
2540
2855
|
}
|
|
2541
2856
|
const obj = _nullishCoalesce(_core.tryParseJson.call(void 0, text), () => ( { message: text }));
|
|
@@ -2564,7 +2879,7 @@ var WHITESPACE_REGEX = /\s/;
|
|
|
2564
2879
|
var MarkedCustomTokenizer = class extends _marked.Tokenizer {
|
|
2565
2880
|
url(src) {
|
|
2566
2881
|
const token = super.url(src);
|
|
2567
|
-
if (_optionalChain([token, 'optionalAccess',
|
|
2882
|
+
if (_optionalChain([token, 'optionalAccess', _55 => _55.href, 'access', _56 => _56.startsWith, 'call', _57 => _57("mailto:")])) {
|
|
2568
2883
|
return void 0;
|
|
2569
2884
|
}
|
|
2570
2885
|
return token;
|
|
@@ -2744,7 +3059,7 @@ function tokensToCommentBodyInlines(tokens, formatting = {}) {
|
|
|
2744
3059
|
case "escape":
|
|
2745
3060
|
case "html":
|
|
2746
3061
|
case "text": {
|
|
2747
|
-
if (token.type === "text" && _optionalChain([token, 'access',
|
|
3062
|
+
if (token.type === "text" && _optionalChain([token, 'access', _58 => _58.tokens, 'optionalAccess', _59 => _59.length])) {
|
|
2748
3063
|
appendFormattedInlinesFromTokens(inlines, token.tokens, formatting);
|
|
2749
3064
|
} else {
|
|
2750
3065
|
appendTextWithMentions(inlines, token.text, formatting);
|
|
@@ -3083,6 +3398,7 @@ function isCustomNotificationEvent(event) {
|
|
|
3083
3398
|
|
|
3084
3399
|
|
|
3085
3400
|
|
|
3401
|
+
|
|
3086
3402
|
_core.detectDupes.call(void 0, PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
3087
3403
|
|
|
3088
3404
|
|
|
@@ -3098,5 +3414,6 @@ _core.detectDupes.call(void 0, PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
|
3098
3414
|
|
|
3099
3415
|
|
|
3100
3416
|
|
|
3101
|
-
|
|
3417
|
+
|
|
3418
|
+
exports.LiveFile = _core.LiveFile; exports.LiveList = _core.LiveList; exports.LiveMap = _core.LiveMap; exports.LiveObject = _core.LiveObject; exports.Liveblocks = Liveblocks; exports.LiveblocksError = LiveblocksError; exports.WebhookHandler = WebhookHandler; exports.getMentionsFromCommentBody = _core.getMentionsFromCommentBody; exports.isCustomNotificationEvent = isCustomNotificationEvent; exports.isNotificationChannelEnabled = _core.isNotificationChannelEnabled; exports.isTextMentionNotificationEvent = isTextMentionNotificationEvent; exports.isThreadNotificationEvent = isThreadNotificationEvent; exports.markdownToCommentBody = markdownToCommentBody; exports.stringifyCommentBody = _core.stringifyCommentBody;
|
|
3102
3419
|
//# sourceMappingURL=index.cjs.map
|