@liveblocks/node 2.18.4-uns2 → 2.20.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/index.cjs +358 -244
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +108 -50
- package/dist/index.d.ts +108 -50
- package/dist/index.js +352 -238
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { detectDupes } from "@liveblocks/core";
|
|
|
3
3
|
|
|
4
4
|
// src/version.ts
|
|
5
5
|
var PKG_NAME = "@liveblocks/node";
|
|
6
|
-
var PKG_VERSION = "2.
|
|
6
|
+
var PKG_VERSION = "2.20.0";
|
|
7
7
|
var PKG_FORMAT = "esm";
|
|
8
8
|
|
|
9
9
|
// src/client.ts
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
convertToThreadData,
|
|
15
15
|
createUserNotificationSettings,
|
|
16
16
|
objectToQuery,
|
|
17
|
+
tryParseJson,
|
|
17
18
|
url as url2,
|
|
18
19
|
urljoin
|
|
19
20
|
} from "@liveblocks/core";
|
|
@@ -213,7 +214,7 @@ var Liveblocks = class {
|
|
|
213
214
|
this.#secret = secret;
|
|
214
215
|
this.#baseUrl = new URL(getBaseUrl(options.baseUrl));
|
|
215
216
|
}
|
|
216
|
-
async #post(path, json) {
|
|
217
|
+
async #post(path, json, options) {
|
|
217
218
|
const url3 = urljoin(this.#baseUrl, path);
|
|
218
219
|
const headers = {
|
|
219
220
|
Authorization: `Bearer ${this.#secret}`,
|
|
@@ -223,11 +224,12 @@ var Liveblocks = class {
|
|
|
223
224
|
const res = await fetch(url3, {
|
|
224
225
|
method: "POST",
|
|
225
226
|
headers,
|
|
226
|
-
body: JSON.stringify(json)
|
|
227
|
+
body: JSON.stringify(json),
|
|
228
|
+
signal: options?.signal
|
|
227
229
|
});
|
|
228
230
|
return res;
|
|
229
231
|
}
|
|
230
|
-
async #put(path, json) {
|
|
232
|
+
async #put(path, json, options) {
|
|
231
233
|
const url3 = urljoin(this.#baseUrl, path);
|
|
232
234
|
const headers = {
|
|
233
235
|
Authorization: `Bearer ${this.#secret}`,
|
|
@@ -237,34 +239,48 @@ var Liveblocks = class {
|
|
|
237
239
|
return await fetch(url3, {
|
|
238
240
|
method: "PUT",
|
|
239
241
|
headers,
|
|
240
|
-
body: JSON.stringify(json)
|
|
242
|
+
body: JSON.stringify(json),
|
|
243
|
+
signal: options?.signal
|
|
241
244
|
});
|
|
242
245
|
}
|
|
243
|
-
async #putBinary(path, body, params) {
|
|
246
|
+
async #putBinary(path, body, params, options) {
|
|
244
247
|
const url3 = urljoin(this.#baseUrl, path, params);
|
|
245
248
|
const headers = {
|
|
246
249
|
Authorization: `Bearer ${this.#secret}`,
|
|
247
250
|
"Content-Type": "application/octet-stream"
|
|
248
251
|
};
|
|
249
252
|
const fetch = await fetchPolyfill();
|
|
250
|
-
return await fetch(url3, {
|
|
253
|
+
return await fetch(url3, {
|
|
254
|
+
method: "PUT",
|
|
255
|
+
headers,
|
|
256
|
+
body,
|
|
257
|
+
signal: options?.signal
|
|
258
|
+
});
|
|
251
259
|
}
|
|
252
|
-
async #delete(path) {
|
|
260
|
+
async #delete(path, options) {
|
|
253
261
|
const url3 = urljoin(this.#baseUrl, path);
|
|
254
262
|
const headers = {
|
|
255
263
|
Authorization: `Bearer ${this.#secret}`
|
|
256
264
|
};
|
|
257
265
|
const fetch = await fetchPolyfill();
|
|
258
|
-
const res = await fetch(url3, {
|
|
266
|
+
const res = await fetch(url3, {
|
|
267
|
+
method: "DELETE",
|
|
268
|
+
headers,
|
|
269
|
+
signal: options?.signal
|
|
270
|
+
});
|
|
259
271
|
return res;
|
|
260
272
|
}
|
|
261
|
-
async #get(path, params) {
|
|
273
|
+
async #get(path, params, options) {
|
|
262
274
|
const url3 = urljoin(this.#baseUrl, path, params);
|
|
263
275
|
const headers = {
|
|
264
276
|
Authorization: `Bearer ${this.#secret}`
|
|
265
277
|
};
|
|
266
278
|
const fetch = await fetchPolyfill();
|
|
267
|
-
const res = await fetch(url3, {
|
|
279
|
+
const res = await fetch(url3, {
|
|
280
|
+
method: "GET",
|
|
281
|
+
headers,
|
|
282
|
+
signal: options?.signal
|
|
283
|
+
});
|
|
268
284
|
return res;
|
|
269
285
|
}
|
|
270
286
|
/* -------------------------------------------------------------------------------------------------
|
|
@@ -362,9 +378,10 @@ var Liveblocks = class {
|
|
|
362
378
|
* @param params.metadata (optional) A filter on metadata. Multiple metadata keys can be used to filter rooms.
|
|
363
379
|
* @param params.groupIds (optional) A filter on groups accesses. Multiple groups can be used.
|
|
364
380
|
* @param params.query (optional) A query to filter rooms by. It is based on our query language. You can filter by metadata and room ID.
|
|
381
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
365
382
|
* @returns A list of rooms.
|
|
366
383
|
*/
|
|
367
|
-
async getRooms(params = {}) {
|
|
384
|
+
async getRooms(params = {}, options) {
|
|
368
385
|
const path = url2`/v2/rooms`;
|
|
369
386
|
let query;
|
|
370
387
|
if (typeof params.query === "string") {
|
|
@@ -386,10 +403,9 @@ var Liveblocks = class {
|
|
|
386
403
|
),
|
|
387
404
|
query
|
|
388
405
|
};
|
|
389
|
-
const res = await this.#get(path, queryParams);
|
|
406
|
+
const res = await this.#get(path, queryParams, options);
|
|
390
407
|
if (!res.ok) {
|
|
391
|
-
|
|
392
|
-
throw new LiveblocksError(res.status, text);
|
|
408
|
+
throw await LiveblocksError.from(res);
|
|
393
409
|
}
|
|
394
410
|
const data = await res.json();
|
|
395
411
|
const rooms = data.data.map((room) => {
|
|
@@ -413,20 +429,24 @@ var Liveblocks = class {
|
|
|
413
429
|
* @param params.groupsAccesses (optional) The group accesses for the room. Can contain a maximum of 100 entries. Key length has a limit of 40 characters.
|
|
414
430
|
* @param params.usersAccesses (optional) The user accesses for the room. Can contain a maximum of 100 entries. Key length has a limit of 40 characters.
|
|
415
431
|
* @param params.metadata (optional) The metadata for the room. Supports upto a maximum of 50 entries. Key length has a limit of 40 characters. Value length has a limit of 256 characters.
|
|
432
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
416
433
|
* @returns The created room.
|
|
417
434
|
*/
|
|
418
|
-
async createRoom(roomId, params) {
|
|
435
|
+
async createRoom(roomId, params, options) {
|
|
419
436
|
const { defaultAccesses, groupsAccesses, usersAccesses, metadata } = params;
|
|
420
|
-
const res = await this.#post(
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
437
|
+
const res = await this.#post(
|
|
438
|
+
url2`/v2/rooms`,
|
|
439
|
+
{
|
|
440
|
+
id: roomId,
|
|
441
|
+
defaultAccesses,
|
|
442
|
+
groupsAccesses,
|
|
443
|
+
usersAccesses,
|
|
444
|
+
metadata
|
|
445
|
+
},
|
|
446
|
+
options
|
|
447
|
+
);
|
|
427
448
|
if (!res.ok) {
|
|
428
|
-
|
|
429
|
-
throw new LiveblocksError(res.status, text);
|
|
449
|
+
throw await LiveblocksError.from(res);
|
|
430
450
|
}
|
|
431
451
|
const data = await res.json();
|
|
432
452
|
const lastConnectionAt = data.lastConnectionAt ? new Date(data.lastConnectionAt) : void 0;
|
|
@@ -441,12 +461,12 @@ var Liveblocks = class {
|
|
|
441
461
|
* Returns a room with the given id.
|
|
442
462
|
* @param roomId The id of the room to return.
|
|
443
463
|
* @returns The room with the given id.
|
|
464
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
444
465
|
*/
|
|
445
|
-
async getRoom(roomId) {
|
|
446
|
-
const res = await this.#get(url2`/v2/rooms/${roomId}
|
|
466
|
+
async getRoom(roomId, options) {
|
|
467
|
+
const res = await this.#get(url2`/v2/rooms/${roomId}`, void 0, options);
|
|
447
468
|
if (!res.ok) {
|
|
448
|
-
|
|
449
|
-
throw new LiveblocksError(res.status, text);
|
|
469
|
+
throw await LiveblocksError.from(res);
|
|
450
470
|
}
|
|
451
471
|
const data = await res.json();
|
|
452
472
|
const lastConnectionAt = data.lastConnectionAt ? new Date(data.lastConnectionAt) : void 0;
|
|
@@ -465,19 +485,23 @@ var Liveblocks = class {
|
|
|
465
485
|
* @param params.groupsAccesses (optional) The group accesses for the room. Can contain a maximum of 100 entries. Key length has a limit of 40 characters.
|
|
466
486
|
* @param params.usersAccesses (optional) The user accesses for the room. Can contain a maximum of 100 entries. Key length has a limit of 40 characters.
|
|
467
487
|
* @param params.metadata (optional) The metadata for the room. Supports upto a maximum of 50 entries. Key length has a limit of 40 characters. Value length has a limit of 256 characters.
|
|
488
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
468
489
|
* @returns The updated room.
|
|
469
490
|
*/
|
|
470
|
-
async updateRoom(roomId, params) {
|
|
491
|
+
async updateRoom(roomId, params, options) {
|
|
471
492
|
const { defaultAccesses, groupsAccesses, usersAccesses, metadata } = params;
|
|
472
|
-
const res = await this.#post(
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
493
|
+
const res = await this.#post(
|
|
494
|
+
url2`/v2/rooms/${roomId}`,
|
|
495
|
+
{
|
|
496
|
+
defaultAccesses,
|
|
497
|
+
groupsAccesses,
|
|
498
|
+
usersAccesses,
|
|
499
|
+
metadata
|
|
500
|
+
},
|
|
501
|
+
options
|
|
502
|
+
);
|
|
478
503
|
if (!res.ok) {
|
|
479
|
-
|
|
480
|
-
throw new LiveblocksError(res.status, text);
|
|
504
|
+
throw await LiveblocksError.from(res);
|
|
481
505
|
}
|
|
482
506
|
const data = await res.json();
|
|
483
507
|
const lastConnectionAt = data.lastConnectionAt ? new Date(data.lastConnectionAt) : void 0;
|
|
@@ -491,24 +515,28 @@ var Liveblocks = class {
|
|
|
491
515
|
/**
|
|
492
516
|
* Deletes a room with the given id. A deleted room is no longer accessible from the API or the dashboard and it cannot be restored.
|
|
493
517
|
* @param roomId The id of the room to delete.
|
|
518
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
494
519
|
*/
|
|
495
|
-
async deleteRoom(roomId) {
|
|
496
|
-
const res = await this.#delete(url2`/v2/rooms/${roomId}
|
|
520
|
+
async deleteRoom(roomId, options) {
|
|
521
|
+
const res = await this.#delete(url2`/v2/rooms/${roomId}`, options);
|
|
497
522
|
if (!res.ok) {
|
|
498
|
-
|
|
499
|
-
throw new LiveblocksError(res.status, text);
|
|
523
|
+
throw await LiveblocksError.from(res);
|
|
500
524
|
}
|
|
501
525
|
}
|
|
502
526
|
/**
|
|
503
527
|
* Returns a list of users currently present in the requested room. For better performance, we recommand to call this endpoint every 10 seconds maximum. Duplicates can happen if a user is in the requested room with multiple browser tabs opened.
|
|
504
528
|
* @param roomId The id of the room to get the users from.
|
|
529
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
505
530
|
* @returns A list of users currently present in the requested room.
|
|
506
531
|
*/
|
|
507
|
-
async getActiveUsers(roomId) {
|
|
508
|
-
const res = await this.#get(
|
|
532
|
+
async getActiveUsers(roomId, options) {
|
|
533
|
+
const res = await this.#get(
|
|
534
|
+
url2`/v2/rooms/${roomId}/active_users`,
|
|
535
|
+
void 0,
|
|
536
|
+
options
|
|
537
|
+
);
|
|
509
538
|
if (!res.ok) {
|
|
510
|
-
|
|
511
|
-
throw new LiveblocksError(res.status, text);
|
|
539
|
+
throw await LiveblocksError.from(res);
|
|
512
540
|
}
|
|
513
541
|
return await res.json();
|
|
514
542
|
}
|
|
@@ -516,22 +544,26 @@ var Liveblocks = class {
|
|
|
516
544
|
* Boadcasts an event to a room without having to connect to it via the client from @liveblocks/client. The connectionId passed to event listeners is -1 when using this API.
|
|
517
545
|
* @param roomId The id of the room to broadcast the event to.
|
|
518
546
|
* @param message The message to broadcast. It can be any JSON serializable value.
|
|
547
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
519
548
|
*/
|
|
520
|
-
async broadcastEvent(roomId, message) {
|
|
549
|
+
async broadcastEvent(roomId, message, options) {
|
|
521
550
|
const res = await this.#post(
|
|
522
551
|
url2`/v2/rooms/${roomId}/broadcast_event`,
|
|
523
|
-
message
|
|
552
|
+
message,
|
|
553
|
+
options
|
|
524
554
|
);
|
|
525
555
|
if (!res.ok) {
|
|
526
|
-
|
|
527
|
-
throw new LiveblocksError(res.status, text);
|
|
556
|
+
throw await LiveblocksError.from(res);
|
|
528
557
|
}
|
|
529
558
|
}
|
|
530
|
-
async getStorageDocument(roomId, format = "plain-lson") {
|
|
531
|
-
const res = await this.#get(
|
|
559
|
+
async getStorageDocument(roomId, format = "plain-lson", options) {
|
|
560
|
+
const res = await this.#get(
|
|
561
|
+
url2`/v2/rooms/${roomId}/storage`,
|
|
562
|
+
{ format },
|
|
563
|
+
options
|
|
564
|
+
);
|
|
532
565
|
if (!res.ok) {
|
|
533
|
-
|
|
534
|
-
throw new LiveblocksError(res.status, text);
|
|
566
|
+
throw await LiveblocksError.from(res);
|
|
535
567
|
}
|
|
536
568
|
return await res.json();
|
|
537
569
|
}
|
|
@@ -541,25 +573,29 @@ var Liveblocks = class {
|
|
|
541
573
|
*
|
|
542
574
|
* @param roomId The id of the room to initialize the storage from.
|
|
543
575
|
* @param document The document to initialize the storage with.
|
|
576
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
544
577
|
* @returns The initialized storage document. It is of the same format as the one passed in.
|
|
545
578
|
*/
|
|
546
|
-
async initializeStorageDocument(roomId, document) {
|
|
547
|
-
const res = await this.#post(
|
|
579
|
+
async initializeStorageDocument(roomId, document, options) {
|
|
580
|
+
const res = await this.#post(
|
|
581
|
+
url2`/v2/rooms/${roomId}/storage`,
|
|
582
|
+
document,
|
|
583
|
+
options
|
|
584
|
+
);
|
|
548
585
|
if (!res.ok) {
|
|
549
|
-
|
|
550
|
-
throw new LiveblocksError(res.status, text);
|
|
586
|
+
throw await LiveblocksError.from(res);
|
|
551
587
|
}
|
|
552
588
|
return await res.json();
|
|
553
589
|
}
|
|
554
590
|
/**
|
|
555
591
|
* Deletes all of the room’s Storage data and disconnect all users from the room if there are any. Note that this does not delete the Yjs document in the room if one exists.
|
|
556
592
|
* @param roomId The id of the room to delete the storage from.
|
|
593
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
557
594
|
*/
|
|
558
|
-
async deleteStorageDocument(roomId) {
|
|
559
|
-
const res = await this.#delete(url2`/v2/rooms/${roomId}/storage
|
|
595
|
+
async deleteStorageDocument(roomId, options) {
|
|
596
|
+
const res = await this.#delete(url2`/v2/rooms/${roomId}/storage`, options);
|
|
560
597
|
if (!res.ok) {
|
|
561
|
-
|
|
562
|
-
throw new LiveblocksError(res.status, text);
|
|
598
|
+
throw await LiveblocksError.from(res);
|
|
563
599
|
}
|
|
564
600
|
}
|
|
565
601
|
/* -------------------------------------------------------------------------------------------------
|
|
@@ -571,19 +607,19 @@ var Liveblocks = class {
|
|
|
571
607
|
* @param params.format (optional) If true, YText will return formatting.
|
|
572
608
|
* @param params.key (optional) If provided, returns only a single key’s value, e.g. doc.get(key).toJSON().
|
|
573
609
|
* @param params.type (optional) Used with key to override the inferred type, i.e. "ymap" will return doc.get(key, Y.Map).
|
|
610
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
574
611
|
* @returns A JSON representation of the room’s Yjs document.
|
|
575
612
|
*/
|
|
576
|
-
async getYjsDocument(roomId, params = {}) {
|
|
613
|
+
async getYjsDocument(roomId, params = {}, options) {
|
|
577
614
|
const { format, key, type } = params;
|
|
578
615
|
const path = url2`v2/rooms/${roomId}/ydoc`;
|
|
579
|
-
const res = await this.#get(
|
|
580
|
-
|
|
581
|
-
key,
|
|
582
|
-
|
|
583
|
-
|
|
616
|
+
const res = await this.#get(
|
|
617
|
+
path,
|
|
618
|
+
{ formatting: format ? "true" : void 0, key, type },
|
|
619
|
+
options
|
|
620
|
+
);
|
|
584
621
|
if (!res.ok) {
|
|
585
|
-
|
|
586
|
-
throw new LiveblocksError(res.status, text);
|
|
622
|
+
throw await LiveblocksError.from(res);
|
|
587
623
|
}
|
|
588
624
|
return await res.json();
|
|
589
625
|
}
|
|
@@ -592,14 +628,17 @@ var Liveblocks = class {
|
|
|
592
628
|
* @param roomId The id of the room to send the Yjs binary update to.
|
|
593
629
|
* @param update The Yjs update to send. Typically the result of calling `Yjs.encodeStateAsUpdate(doc)`. Read the [Yjs documentation](https://docs.yjs.dev/api/document-updates) to learn how to create a binary update.
|
|
594
630
|
* @param params.guid (optional) If provided, the binary update will be applied to the Yjs subdocument with the given guid. If not provided, the binary update will be applied to the root Yjs document.
|
|
631
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
595
632
|
*/
|
|
596
|
-
async sendYjsBinaryUpdate(roomId, update, params = {}) {
|
|
597
|
-
const res = await this.#putBinary(
|
|
598
|
-
|
|
599
|
-
|
|
633
|
+
async sendYjsBinaryUpdate(roomId, update, params = {}, options) {
|
|
634
|
+
const res = await this.#putBinary(
|
|
635
|
+
url2`/v2/rooms/${roomId}/ydoc`,
|
|
636
|
+
update,
|
|
637
|
+
{ guid: params.guid },
|
|
638
|
+
options
|
|
639
|
+
);
|
|
600
640
|
if (!res.ok) {
|
|
601
|
-
|
|
602
|
-
throw new LiveblocksError(res.status, text);
|
|
641
|
+
throw await LiveblocksError.from(res);
|
|
603
642
|
}
|
|
604
643
|
}
|
|
605
644
|
/**
|
|
@@ -607,15 +646,17 @@ var Liveblocks = class {
|
|
|
607
646
|
* See [Yjs documentation](https://docs.yjs.dev/api/document-updates) for more information on working with updates.
|
|
608
647
|
* @param roomId The id of the room to get the Yjs document from.
|
|
609
648
|
* @param params.guid (optional) If provided, returns the binary update of the Yjs subdocument with the given guid. If not provided, returns the binary update of the root Yjs document.
|
|
649
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
610
650
|
* @returns The room’s Yjs document encoded as a single binary update.
|
|
611
651
|
*/
|
|
612
|
-
async getYjsDocumentAsBinaryUpdate(roomId, params = {}) {
|
|
613
|
-
const res = await this.#get(
|
|
614
|
-
|
|
615
|
-
|
|
652
|
+
async getYjsDocumentAsBinaryUpdate(roomId, params = {}, options) {
|
|
653
|
+
const res = await this.#get(
|
|
654
|
+
url2`/v2/rooms/${roomId}/ydoc-binary`,
|
|
655
|
+
{ guid: params.guid },
|
|
656
|
+
options
|
|
657
|
+
);
|
|
616
658
|
if (!res.ok) {
|
|
617
|
-
|
|
618
|
-
throw new LiveblocksError(res.status, text);
|
|
659
|
+
throw await LiveblocksError.from(res);
|
|
619
660
|
}
|
|
620
661
|
return res.arrayBuffer();
|
|
621
662
|
}
|
|
@@ -626,16 +667,13 @@ var Liveblocks = class {
|
|
|
626
667
|
* Creates a new schema which can be referenced later to enforce a room’s Storage data structure.
|
|
627
668
|
* @param name The name used to reference the schema. Must be a non-empty string with less than 65 characters and only contain lowercase letters, numbers and dashes
|
|
628
669
|
* @param body The exact allowed shape of data in the room. It is a multi-line string written in the [Liveblocks schema syntax](https://liveblocks.io/docs/platform/schema-validation/syntax).
|
|
670
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
629
671
|
* @returns The created schema.
|
|
630
672
|
*/
|
|
631
|
-
async createSchema(name, body) {
|
|
632
|
-
const res = await this.#post(url2`/v2/schemas`, {
|
|
633
|
-
name,
|
|
634
|
-
body
|
|
635
|
-
});
|
|
673
|
+
async createSchema(name, body, options) {
|
|
674
|
+
const res = await this.#post(url2`/v2/schemas`, { name, body }, options);
|
|
636
675
|
if (!res.ok) {
|
|
637
|
-
|
|
638
|
-
throw new LiveblocksError(res.status, text);
|
|
676
|
+
throw await LiveblocksError.from(res);
|
|
639
677
|
}
|
|
640
678
|
const data = await res.json();
|
|
641
679
|
const createdAt = new Date(data.createdAt);
|
|
@@ -649,13 +687,17 @@ var Liveblocks = class {
|
|
|
649
687
|
/**
|
|
650
688
|
* Returns a schema by its id.
|
|
651
689
|
* @param schemaId Id of the schema - this is the combination of the schema name and version of the schema to update. For example, `my-schema@1`.
|
|
690
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
652
691
|
* @returns The schema with the given id.
|
|
653
692
|
*/
|
|
654
|
-
async getSchema(schemaId) {
|
|
655
|
-
const res = await this.#get(
|
|
693
|
+
async getSchema(schemaId, options) {
|
|
694
|
+
const res = await this.#get(
|
|
695
|
+
url2`/v2/schemas/${schemaId}`,
|
|
696
|
+
void 0,
|
|
697
|
+
options
|
|
698
|
+
);
|
|
656
699
|
if (!res.ok) {
|
|
657
|
-
|
|
658
|
-
throw new LiveblocksError(res.status, text);
|
|
700
|
+
throw await LiveblocksError.from(res);
|
|
659
701
|
}
|
|
660
702
|
const data = await res.json();
|
|
661
703
|
const createdAt = new Date(data.createdAt);
|
|
@@ -670,15 +712,17 @@ var Liveblocks = class {
|
|
|
670
712
|
* Updates the body for the schema. A schema can only be updated if it is not used by any room.
|
|
671
713
|
* @param schemaId Id of the schema - this is the combination of the schema name and version of the schema to update. For example, `my-schema@1`.
|
|
672
714
|
* @param body The exact allowed shape of data in the room. It is a multi-line string written in the [Liveblocks schema syntax](https://liveblocks.io/docs/platform/schema-validation/syntax).
|
|
715
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
673
716
|
* @returns The updated schema. The version of the schema will be incremented.
|
|
674
717
|
*/
|
|
675
|
-
async updateSchema(schemaId, body) {
|
|
676
|
-
const res = await this.#put(
|
|
677
|
-
|
|
678
|
-
|
|
718
|
+
async updateSchema(schemaId, body, options) {
|
|
719
|
+
const res = await this.#put(
|
|
720
|
+
url2`/v2/schemas/${schemaId}`,
|
|
721
|
+
{ body },
|
|
722
|
+
options
|
|
723
|
+
);
|
|
679
724
|
if (!res.ok) {
|
|
680
|
-
|
|
681
|
-
throw new LiveblocksError(res.status, text);
|
|
725
|
+
throw await LiveblocksError.from(res);
|
|
682
726
|
}
|
|
683
727
|
const data = await res.json();
|
|
684
728
|
const createdAt = new Date(data.createdAt);
|
|
@@ -692,24 +736,28 @@ var Liveblocks = class {
|
|
|
692
736
|
/**
|
|
693
737
|
* Deletes a schema by its id. A schema can only be deleted if it is not used by any room.
|
|
694
738
|
* @param schemaId Id of the schema - this is the combination of the schema name and version of the schema to update. For example, `my-schema@1`.
|
|
739
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
695
740
|
*/
|
|
696
|
-
async deleteSchema(schemaId) {
|
|
697
|
-
const res = await this.#delete(url2`/v2/schemas/${schemaId}
|
|
741
|
+
async deleteSchema(schemaId, options) {
|
|
742
|
+
const res = await this.#delete(url2`/v2/schemas/${schemaId}`, options);
|
|
698
743
|
if (!res.ok) {
|
|
699
|
-
|
|
700
|
-
throw new LiveblocksError(res.status, text);
|
|
744
|
+
throw await LiveblocksError.from(res);
|
|
701
745
|
}
|
|
702
746
|
}
|
|
703
747
|
/**
|
|
704
748
|
* Returns the schema attached to a room.
|
|
705
749
|
* @param roomId The id of the room to get the schema from.
|
|
750
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
706
751
|
* @returns
|
|
707
752
|
*/
|
|
708
|
-
async getSchemaByRoomId(roomId) {
|
|
709
|
-
const res = await this.#get(
|
|
753
|
+
async getSchemaByRoomId(roomId, options) {
|
|
754
|
+
const res = await this.#get(
|
|
755
|
+
url2`/v2/rooms/${roomId}/schema`,
|
|
756
|
+
void 0,
|
|
757
|
+
options
|
|
758
|
+
);
|
|
710
759
|
if (!res.ok) {
|
|
711
|
-
|
|
712
|
-
throw new LiveblocksError(res.status, text);
|
|
760
|
+
throw await LiveblocksError.from(res);
|
|
713
761
|
}
|
|
714
762
|
const data = await res.json();
|
|
715
763
|
const createdAt = new Date(data.createdAt);
|
|
@@ -725,27 +773,29 @@ var Liveblocks = class {
|
|
|
725
773
|
* If the current contents of the room’s Storage do not match the schema, attaching will fail and the error message will give details on why the schema failed to attach.
|
|
726
774
|
* @param roomId The id of the room to attach the schema to.
|
|
727
775
|
* @param schemaId Id of the schema - this is the combination of the schema name and version of the schema to update. For example, `my-schema@1`.
|
|
776
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
728
777
|
* @returns The schema id as JSON.
|
|
729
778
|
*/
|
|
730
|
-
async attachSchemaToRoom(roomId, schemaId) {
|
|
731
|
-
const res = await this.#post(
|
|
732
|
-
schema
|
|
733
|
-
|
|
779
|
+
async attachSchemaToRoom(roomId, schemaId, options) {
|
|
780
|
+
const res = await this.#post(
|
|
781
|
+
url2`/v2/rooms/${roomId}/schema`,
|
|
782
|
+
{ schema: schemaId },
|
|
783
|
+
options
|
|
784
|
+
);
|
|
734
785
|
if (!res.ok) {
|
|
735
|
-
|
|
736
|
-
throw new LiveblocksError(res.status, text);
|
|
786
|
+
throw await LiveblocksError.from(res);
|
|
737
787
|
}
|
|
738
788
|
return await res.json();
|
|
739
789
|
}
|
|
740
790
|
/**
|
|
741
791
|
* Detaches a schema from a room, and disables runtime schema validation for the room.
|
|
742
792
|
* @param roomId The id of the room to detach the schema from.
|
|
793
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
743
794
|
*/
|
|
744
|
-
async detachSchemaFromRoom(roomId) {
|
|
745
|
-
const res = await this.#delete(url2`/v2/rooms/${roomId}/schema
|
|
795
|
+
async detachSchemaFromRoom(roomId, options) {
|
|
796
|
+
const res = await this.#delete(url2`/v2/rooms/${roomId}/schema`, options);
|
|
746
797
|
if (!res.ok) {
|
|
747
|
-
|
|
748
|
-
throw new LiveblocksError(res.status, text);
|
|
798
|
+
throw await LiveblocksError.from(res);
|
|
749
799
|
}
|
|
750
800
|
}
|
|
751
801
|
/* -------------------------------------------------------------------------------------------------
|
|
@@ -756,9 +806,10 @@ var Liveblocks = class {
|
|
|
756
806
|
*
|
|
757
807
|
* @param params.roomId The room ID to get the threads from.
|
|
758
808
|
* @param params.query The query to filter threads by. It is based on our query language and can filter by metadata.
|
|
809
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
759
810
|
* @returns A list of threads.
|
|
760
811
|
*/
|
|
761
|
-
async getThreads(params) {
|
|
812
|
+
async getThreads(params, options) {
|
|
762
813
|
const { roomId } = params;
|
|
763
814
|
let query;
|
|
764
815
|
if (typeof params.query === "string") {
|
|
@@ -766,12 +817,13 @@ var Liveblocks = class {
|
|
|
766
817
|
} else if (typeof params.query === "object") {
|
|
767
818
|
query = objectToQuery(params.query);
|
|
768
819
|
}
|
|
769
|
-
const res = await this.#get(
|
|
770
|
-
|
|
771
|
-
|
|
820
|
+
const res = await this.#get(
|
|
821
|
+
url2`/v2/rooms/${roomId}/threads`,
|
|
822
|
+
{ query },
|
|
823
|
+
options
|
|
824
|
+
);
|
|
772
825
|
if (!res.ok) {
|
|
773
|
-
|
|
774
|
-
throw new LiveblocksError(res.status, text);
|
|
826
|
+
throw await LiveblocksError.from(res);
|
|
775
827
|
}
|
|
776
828
|
const { data } = await res.json();
|
|
777
829
|
return {
|
|
@@ -783,14 +835,18 @@ var Liveblocks = class {
|
|
|
783
835
|
*
|
|
784
836
|
* @param params.roomId The room ID to get the thread from.
|
|
785
837
|
* @param params.threadId The thread ID.
|
|
838
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
786
839
|
* @returns A thread.
|
|
787
840
|
*/
|
|
788
|
-
async getThread(params) {
|
|
841
|
+
async getThread(params, options) {
|
|
789
842
|
const { roomId, threadId } = params;
|
|
790
|
-
const res = await this.#get(
|
|
843
|
+
const res = await this.#get(
|
|
844
|
+
url2`/v2/rooms/${roomId}/threads/${threadId}`,
|
|
845
|
+
void 0,
|
|
846
|
+
options
|
|
847
|
+
);
|
|
791
848
|
if (!res.ok) {
|
|
792
|
-
|
|
793
|
-
throw new LiveblocksError(res.status, text);
|
|
849
|
+
throw await LiveblocksError.from(res);
|
|
794
850
|
}
|
|
795
851
|
return convertToThreadData(await res.json());
|
|
796
852
|
}
|
|
@@ -802,16 +858,18 @@ var Liveblocks = class {
|
|
|
802
858
|
*
|
|
803
859
|
* @param params.roomId The room ID to get the thread participants from.
|
|
804
860
|
* @param params.threadId The thread ID to get the participants from.
|
|
861
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
805
862
|
* @returns An object containing an array of participant IDs.
|
|
806
863
|
*/
|
|
807
|
-
async getThreadParticipants(params) {
|
|
864
|
+
async getThreadParticipants(params, options) {
|
|
808
865
|
const { roomId, threadId } = params;
|
|
809
866
|
const res = await this.#get(
|
|
810
|
-
url2`/v2/rooms/${roomId}/threads/${threadId}/participants
|
|
867
|
+
url2`/v2/rooms/${roomId}/threads/${threadId}/participants`,
|
|
868
|
+
void 0,
|
|
869
|
+
options
|
|
811
870
|
);
|
|
812
871
|
if (!res.ok) {
|
|
813
|
-
|
|
814
|
-
throw new LiveblocksError(res.status, text);
|
|
872
|
+
throw await LiveblocksError.from(res);
|
|
815
873
|
}
|
|
816
874
|
return await res.json();
|
|
817
875
|
}
|
|
@@ -821,16 +879,18 @@ var Liveblocks = class {
|
|
|
821
879
|
* @param params.roomId The room ID to get the comment from.
|
|
822
880
|
* @param params.threadId The thread ID to get the comment from.
|
|
823
881
|
* @param params.commentId The comment ID.
|
|
882
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
824
883
|
* @returns A comment.
|
|
825
884
|
*/
|
|
826
|
-
async getComment(params) {
|
|
885
|
+
async getComment(params, options) {
|
|
827
886
|
const { roomId, threadId, commentId } = params;
|
|
828
887
|
const res = await this.#get(
|
|
829
|
-
url2`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}
|
|
888
|
+
url2`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}`,
|
|
889
|
+
void 0,
|
|
890
|
+
options
|
|
830
891
|
);
|
|
831
892
|
if (!res.ok) {
|
|
832
|
-
|
|
833
|
-
throw new LiveblocksError(res.status, text);
|
|
893
|
+
throw await LiveblocksError.from(res);
|
|
834
894
|
}
|
|
835
895
|
return convertToCommentData(await res.json());
|
|
836
896
|
}
|
|
@@ -842,20 +902,21 @@ var Liveblocks = class {
|
|
|
842
902
|
* @param params.data.userId The user ID of the user who is set to create the comment.
|
|
843
903
|
* @param params.data.createdAt (optional) The date the comment is set to be created.
|
|
844
904
|
* @param params.data.body The body of the comment.
|
|
905
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
845
906
|
* @returns The created comment.
|
|
846
907
|
*/
|
|
847
|
-
async createComment(params) {
|
|
908
|
+
async createComment(params, options) {
|
|
848
909
|
const { roomId, threadId, data } = params;
|
|
849
910
|
const res = await this.#post(
|
|
850
911
|
url2`/v2/rooms/${roomId}/threads/${threadId}/comments`,
|
|
851
912
|
{
|
|
852
913
|
...data,
|
|
853
914
|
createdAt: data.createdAt?.toISOString()
|
|
854
|
-
}
|
|
915
|
+
},
|
|
916
|
+
options
|
|
855
917
|
);
|
|
856
918
|
if (!res.ok) {
|
|
857
|
-
|
|
858
|
-
throw new LiveblocksError(res.status, text);
|
|
919
|
+
throw await LiveblocksError.from(res);
|
|
859
920
|
}
|
|
860
921
|
return convertToCommentData(await res.json());
|
|
861
922
|
}
|
|
@@ -866,20 +927,18 @@ var Liveblocks = class {
|
|
|
866
927
|
* @param params.commentId The comment ID to edit.
|
|
867
928
|
* @param params.data.body The body of the comment.
|
|
868
929
|
* @param params.data.editedAt (optional) The date the comment was edited.
|
|
930
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
869
931
|
* @returns The edited comment.
|
|
870
932
|
*/
|
|
871
|
-
async editComment(params) {
|
|
933
|
+
async editComment(params, options) {
|
|
872
934
|
const { roomId, threadId, commentId, data } = params;
|
|
873
935
|
const res = await this.#post(
|
|
874
936
|
url2`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}`,
|
|
875
|
-
{
|
|
876
|
-
|
|
877
|
-
editedAt: data.editedAt?.toISOString()
|
|
878
|
-
}
|
|
937
|
+
{ ...data, editedAt: data.editedAt?.toISOString() },
|
|
938
|
+
options
|
|
879
939
|
);
|
|
880
940
|
if (!res.ok) {
|
|
881
|
-
|
|
882
|
-
throw new LiveblocksError(res.status, text);
|
|
941
|
+
throw await LiveblocksError.from(res);
|
|
883
942
|
}
|
|
884
943
|
return convertToCommentData(await res.json());
|
|
885
944
|
}
|
|
@@ -888,15 +947,16 @@ var Liveblocks = class {
|
|
|
888
947
|
* @param params.roomId The room ID to delete the comment in.
|
|
889
948
|
* @param params.threadId The thread ID to delete the comment in.
|
|
890
949
|
* @param params.commentId The comment ID to delete.
|
|
950
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
891
951
|
*/
|
|
892
|
-
async deleteComment(params) {
|
|
952
|
+
async deleteComment(params, options) {
|
|
893
953
|
const { roomId, threadId, commentId } = params;
|
|
894
954
|
const res = await this.#delete(
|
|
895
|
-
url2`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}
|
|
955
|
+
url2`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}`,
|
|
956
|
+
options
|
|
896
957
|
);
|
|
897
958
|
if (!res.ok) {
|
|
898
|
-
|
|
899
|
-
throw new LiveblocksError(res.status, text);
|
|
959
|
+
throw await LiveblocksError.from(res);
|
|
900
960
|
}
|
|
901
961
|
}
|
|
902
962
|
/**
|
|
@@ -907,20 +967,24 @@ var Liveblocks = class {
|
|
|
907
967
|
* @param params.thread.comment.userId The user ID of the user who created the comment.
|
|
908
968
|
* @param params.thread.comment.createdAt (optional) The date the comment was created.
|
|
909
969
|
* @param params.thread.comment.body The body of the comment.
|
|
970
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
910
971
|
* @returns The created thread. The thread will be created with the specified comment as its first comment.
|
|
911
972
|
*/
|
|
912
|
-
async createThread(params) {
|
|
973
|
+
async createThread(params, options) {
|
|
913
974
|
const { roomId, data } = params;
|
|
914
|
-
const res = await this.#post(
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
...data
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
975
|
+
const res = await this.#post(
|
|
976
|
+
url2`/v2/rooms/${roomId}/threads`,
|
|
977
|
+
{
|
|
978
|
+
...data,
|
|
979
|
+
comment: {
|
|
980
|
+
...data.comment,
|
|
981
|
+
createdAt: data.comment.createdAt?.toISOString()
|
|
982
|
+
}
|
|
983
|
+
},
|
|
984
|
+
options
|
|
985
|
+
);
|
|
921
986
|
if (!res.ok) {
|
|
922
|
-
|
|
923
|
-
throw new LiveblocksError(res.status, text);
|
|
987
|
+
throw await LiveblocksError.from(res);
|
|
924
988
|
}
|
|
925
989
|
return convertToThreadData(await res.json());
|
|
926
990
|
}
|
|
@@ -928,15 +992,16 @@ var Liveblocks = class {
|
|
|
928
992
|
* Deletes a thread and all of its comments.
|
|
929
993
|
* @param params.roomId The room ID to delete the thread in.
|
|
930
994
|
* @param params.threadId The thread ID to delete.
|
|
995
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
931
996
|
*/
|
|
932
|
-
async deleteThread(params) {
|
|
997
|
+
async deleteThread(params, options) {
|
|
933
998
|
const { roomId, threadId } = params;
|
|
934
999
|
const res = await this.#delete(
|
|
935
|
-
url2`/v2/rooms/${roomId}/threads/${threadId}
|
|
1000
|
+
url2`/v2/rooms/${roomId}/threads/${threadId}`,
|
|
1001
|
+
options
|
|
936
1002
|
);
|
|
937
1003
|
if (!res.ok) {
|
|
938
|
-
|
|
939
|
-
throw new LiveblocksError(res.status, text);
|
|
1004
|
+
throw await LiveblocksError.from(res);
|
|
940
1005
|
}
|
|
941
1006
|
}
|
|
942
1007
|
/**
|
|
@@ -944,17 +1009,18 @@ var Liveblocks = class {
|
|
|
944
1009
|
* @param params.roomId The room ID of the thread.
|
|
945
1010
|
* @param params.threadId The thread ID to mark as resolved.
|
|
946
1011
|
* @param params.data.userId The user ID of the user who marked the thread as resolved.
|
|
1012
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
947
1013
|
* @returns The thread marked as resolved.
|
|
948
1014
|
*/
|
|
949
|
-
async markThreadAsResolved(params) {
|
|
1015
|
+
async markThreadAsResolved(params, options) {
|
|
950
1016
|
const { roomId, threadId } = params;
|
|
951
1017
|
const res = await this.#post(
|
|
952
1018
|
url2`/v2/rooms/${roomId}/threads/${threadId}/mark-as-resolved`,
|
|
953
|
-
{}
|
|
1019
|
+
{},
|
|
1020
|
+
options
|
|
954
1021
|
);
|
|
955
1022
|
if (!res.ok) {
|
|
956
|
-
|
|
957
|
-
throw new LiveblocksError(res.status, text);
|
|
1023
|
+
throw await LiveblocksError.from(res);
|
|
958
1024
|
}
|
|
959
1025
|
return convertToThreadData(await res.json());
|
|
960
1026
|
}
|
|
@@ -963,17 +1029,18 @@ var Liveblocks = class {
|
|
|
963
1029
|
* @param params.roomId The room ID of the thread.
|
|
964
1030
|
* @param params.threadId The thread ID to mark as unresolved.
|
|
965
1031
|
* @param params.data.userId The user ID of the user who marked the thread as unresolved.
|
|
1032
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
966
1033
|
* @returns The thread marked as unresolved.
|
|
967
1034
|
*/
|
|
968
|
-
async markThreadAsUnresolved(params) {
|
|
1035
|
+
async markThreadAsUnresolved(params, options) {
|
|
969
1036
|
const { roomId, threadId } = params;
|
|
970
1037
|
const res = await this.#post(
|
|
971
1038
|
url2`/v2/rooms/${roomId}/threads/${threadId}/mark-as-unresolved`,
|
|
972
|
-
{}
|
|
1039
|
+
{},
|
|
1040
|
+
options
|
|
973
1041
|
);
|
|
974
1042
|
if (!res.ok) {
|
|
975
|
-
|
|
976
|
-
throw new LiveblocksError(res.status, text);
|
|
1043
|
+
throw await LiveblocksError.from(res);
|
|
977
1044
|
}
|
|
978
1045
|
return convertToThreadData(await res.json());
|
|
979
1046
|
}
|
|
@@ -984,20 +1051,21 @@ var Liveblocks = class {
|
|
|
984
1051
|
* @param params.data.metadata The metadata for the thread. Value must be a string, boolean or number
|
|
985
1052
|
* @param params.data.userId The user ID of the user who updated the thread.
|
|
986
1053
|
* @param params.data.updatedAt (optional) The date the thread is set to be updated.
|
|
1054
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
987
1055
|
* @returns The updated thread metadata.
|
|
988
1056
|
*/
|
|
989
|
-
async editThreadMetadata(params) {
|
|
1057
|
+
async editThreadMetadata(params, options) {
|
|
990
1058
|
const { roomId, threadId, data } = params;
|
|
991
1059
|
const res = await this.#post(
|
|
992
1060
|
url2`/v2/rooms/${roomId}/threads/${threadId}/metadata`,
|
|
993
1061
|
{
|
|
994
1062
|
...data,
|
|
995
1063
|
updatedAt: data.updatedAt?.toISOString()
|
|
996
|
-
}
|
|
1064
|
+
},
|
|
1065
|
+
options
|
|
997
1066
|
);
|
|
998
1067
|
if (!res.ok) {
|
|
999
|
-
|
|
1000
|
-
throw new LiveblocksError(res.status, text);
|
|
1068
|
+
throw await LiveblocksError.from(res);
|
|
1001
1069
|
}
|
|
1002
1070
|
return await res.json();
|
|
1003
1071
|
}
|
|
@@ -1009,20 +1077,21 @@ var Liveblocks = class {
|
|
|
1009
1077
|
* @param params.data.emoji The (emoji) reaction to add.
|
|
1010
1078
|
* @param params.data.userId The user ID of the user associated with the reaction.
|
|
1011
1079
|
* @param params.data.createdAt (optional) The date the reaction is set to be created.
|
|
1080
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1012
1081
|
* @returns The created comment reaction.
|
|
1013
1082
|
*/
|
|
1014
|
-
async addCommentReaction(params) {
|
|
1083
|
+
async addCommentReaction(params, options) {
|
|
1015
1084
|
const { roomId, threadId, commentId, data } = params;
|
|
1016
1085
|
const res = await this.#post(
|
|
1017
1086
|
url2`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}/add-reaction`,
|
|
1018
1087
|
{
|
|
1019
1088
|
...data,
|
|
1020
1089
|
createdAt: data.createdAt?.toISOString()
|
|
1021
|
-
}
|
|
1090
|
+
},
|
|
1091
|
+
options
|
|
1022
1092
|
);
|
|
1023
1093
|
if (!res.ok) {
|
|
1024
|
-
|
|
1025
|
-
throw new LiveblocksError(res.status, text);
|
|
1094
|
+
throw await LiveblocksError.from(res);
|
|
1026
1095
|
}
|
|
1027
1096
|
const reaction = await res.json();
|
|
1028
1097
|
return convertToCommentUserReaction(reaction);
|
|
@@ -1035,34 +1104,37 @@ var Liveblocks = class {
|
|
|
1035
1104
|
* @param params.data.emoji The (emoji) reaction to remove.
|
|
1036
1105
|
* @param params.data.userId The user ID of the user associated with the reaction.
|
|
1037
1106
|
* @param params.data.removedAt (optional) The date the reaction is set to be removed.
|
|
1107
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1038
1108
|
*/
|
|
1039
|
-
async removeCommentReaction(params) {
|
|
1109
|
+
async removeCommentReaction(params, options) {
|
|
1040
1110
|
const { roomId, threadId, data } = params;
|
|
1041
1111
|
const res = await this.#post(
|
|
1042
1112
|
url2`/v2/rooms/${roomId}/threads/${threadId}/comments/${params.commentId}/remove-reaction`,
|
|
1043
1113
|
{
|
|
1044
1114
|
...data,
|
|
1045
1115
|
removedAt: data.removedAt?.toISOString()
|
|
1046
|
-
}
|
|
1116
|
+
},
|
|
1117
|
+
options
|
|
1047
1118
|
);
|
|
1048
1119
|
if (!res.ok) {
|
|
1049
|
-
|
|
1050
|
-
throw new LiveblocksError(res.status, text);
|
|
1120
|
+
throw await LiveblocksError.from(res);
|
|
1051
1121
|
}
|
|
1052
1122
|
}
|
|
1053
1123
|
/**
|
|
1054
1124
|
* Returns the inbox notifications for a user.
|
|
1055
1125
|
* @param params.userId The user ID to get the inbox notifications from.
|
|
1056
1126
|
* @param params.inboxNotificationId The ID of the inbox notification to get.
|
|
1127
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1057
1128
|
*/
|
|
1058
|
-
async getInboxNotification(params) {
|
|
1129
|
+
async getInboxNotification(params, options) {
|
|
1059
1130
|
const { userId, inboxNotificationId } = params;
|
|
1060
1131
|
const res = await this.#get(
|
|
1061
|
-
url2`/v2/users/${userId}/inbox-notifications/${inboxNotificationId}
|
|
1132
|
+
url2`/v2/users/${userId}/inbox-notifications/${inboxNotificationId}`,
|
|
1133
|
+
void 0,
|
|
1134
|
+
options
|
|
1062
1135
|
);
|
|
1063
1136
|
if (!res.ok) {
|
|
1064
|
-
|
|
1065
|
-
throw new LiveblocksError(res.status, text);
|
|
1137
|
+
throw await LiveblocksError.from(res);
|
|
1066
1138
|
}
|
|
1067
1139
|
return convertToInboxNotificationData(
|
|
1068
1140
|
await res.json()
|
|
@@ -1072,8 +1144,9 @@ var Liveblocks = class {
|
|
|
1072
1144
|
* Returns the inbox notifications for a user.
|
|
1073
1145
|
* @param params.userId The user ID to get the inbox notifications from.
|
|
1074
1146
|
* @param params.query The query to filter inbox notifications by. It is based on our query language and can filter by unread.
|
|
1147
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1075
1148
|
*/
|
|
1076
|
-
async getInboxNotifications(params) {
|
|
1149
|
+
async getInboxNotifications(params, options) {
|
|
1077
1150
|
const { userId } = params;
|
|
1078
1151
|
let query;
|
|
1079
1152
|
if (typeof params.query === "string") {
|
|
@@ -1081,12 +1154,13 @@ var Liveblocks = class {
|
|
|
1081
1154
|
} else if (typeof params.query === "object") {
|
|
1082
1155
|
query = objectToQuery(params.query);
|
|
1083
1156
|
}
|
|
1084
|
-
const res = await this.#get(
|
|
1085
|
-
|
|
1086
|
-
|
|
1157
|
+
const res = await this.#get(
|
|
1158
|
+
url2`/v2/users/${userId}/inbox-notifications`,
|
|
1159
|
+
{ query },
|
|
1160
|
+
options
|
|
1161
|
+
);
|
|
1087
1162
|
if (!res.ok) {
|
|
1088
|
-
|
|
1089
|
-
throw new LiveblocksError(res.status, text);
|
|
1163
|
+
throw await LiveblocksError.from(res);
|
|
1090
1164
|
}
|
|
1091
1165
|
const { data } = await res.json();
|
|
1092
1166
|
return {
|
|
@@ -1097,15 +1171,17 @@ var Liveblocks = class {
|
|
|
1097
1171
|
* Gets the user's room notification settings.
|
|
1098
1172
|
* @param params.userId The user ID to get the room notifications from.
|
|
1099
1173
|
* @param params.roomId The room ID to get the room notification settings from.
|
|
1174
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1100
1175
|
*/
|
|
1101
|
-
async getRoomNotificationSettings(params) {
|
|
1176
|
+
async getRoomNotificationSettings(params, options) {
|
|
1102
1177
|
const { userId, roomId } = params;
|
|
1103
1178
|
const res = await this.#get(
|
|
1104
|
-
url2`/v2/rooms/${roomId}/users/${userId}/notification-settings
|
|
1179
|
+
url2`/v2/rooms/${roomId}/users/${userId}/notification-settings`,
|
|
1180
|
+
void 0,
|
|
1181
|
+
options
|
|
1105
1182
|
);
|
|
1106
1183
|
if (!res.ok) {
|
|
1107
|
-
|
|
1108
|
-
throw new LiveblocksError(res.status, text);
|
|
1184
|
+
throw await LiveblocksError.from(res);
|
|
1109
1185
|
}
|
|
1110
1186
|
return await res.json();
|
|
1111
1187
|
}
|
|
@@ -1114,16 +1190,17 @@ var Liveblocks = class {
|
|
|
1114
1190
|
* @param params.userId The user ID to update the room notification settings for.
|
|
1115
1191
|
* @param params.roomId The room ID to update the room notification settings for.
|
|
1116
1192
|
* @param params.data The new room notification settings for the user.
|
|
1193
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1117
1194
|
*/
|
|
1118
|
-
async updateRoomNotificationSettings(params) {
|
|
1195
|
+
async updateRoomNotificationSettings(params, options) {
|
|
1119
1196
|
const { userId, roomId, data } = params;
|
|
1120
1197
|
const res = await this.#post(
|
|
1121
1198
|
url2`/v2/rooms/${roomId}/users/${userId}/notification-settings`,
|
|
1122
|
-
data
|
|
1199
|
+
data,
|
|
1200
|
+
options
|
|
1123
1201
|
);
|
|
1124
1202
|
if (!res.ok) {
|
|
1125
|
-
|
|
1126
|
-
throw new LiveblocksError(res.status, text);
|
|
1203
|
+
throw await LiveblocksError.from(res);
|
|
1127
1204
|
}
|
|
1128
1205
|
return await res.json();
|
|
1129
1206
|
}
|
|
@@ -1131,33 +1208,33 @@ var Liveblocks = class {
|
|
|
1131
1208
|
* Delete the user's room notification settings.
|
|
1132
1209
|
* @param params.userId The user ID to delete the room notification settings from.
|
|
1133
1210
|
* @param params.roomId The room ID to delete the room notification settings from.
|
|
1211
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1134
1212
|
*/
|
|
1135
|
-
async deleteRoomNotificationSettings(params) {
|
|
1213
|
+
async deleteRoomNotificationSettings(params, options) {
|
|
1136
1214
|
const { userId, roomId } = params;
|
|
1137
1215
|
const res = await this.#delete(
|
|
1138
|
-
url2`/v2/rooms/${roomId}/users/${userId}/notification-settings
|
|
1216
|
+
url2`/v2/rooms/${roomId}/users/${userId}/notification-settings`,
|
|
1217
|
+
options
|
|
1139
1218
|
);
|
|
1140
1219
|
if (!res.ok) {
|
|
1141
|
-
|
|
1142
|
-
throw new LiveblocksError(res.status, text);
|
|
1220
|
+
throw await LiveblocksError.from(res);
|
|
1143
1221
|
}
|
|
1144
1222
|
}
|
|
1145
1223
|
/**
|
|
1146
1224
|
* Update a room ID.
|
|
1147
1225
|
* @param params.roomId The current ID of the room.
|
|
1148
1226
|
* @param params.newRoomId The new room ID.
|
|
1227
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1149
1228
|
*/
|
|
1150
|
-
async updateRoomId(params) {
|
|
1229
|
+
async updateRoomId(params, options) {
|
|
1151
1230
|
const { currentRoomId, newRoomId } = params;
|
|
1152
1231
|
const res = await this.#post(
|
|
1153
1232
|
url2`/v2/rooms/${currentRoomId}/update-room-id`,
|
|
1154
|
-
{
|
|
1155
|
-
|
|
1156
|
-
}
|
|
1233
|
+
{ newRoomId },
|
|
1234
|
+
options
|
|
1157
1235
|
);
|
|
1158
1236
|
if (!res.ok) {
|
|
1159
|
-
|
|
1160
|
-
throw new LiveblocksError(res.status, text);
|
|
1237
|
+
throw await LiveblocksError.from(res);
|
|
1161
1238
|
}
|
|
1162
1239
|
const data = await res.json();
|
|
1163
1240
|
return {
|
|
@@ -1166,52 +1243,61 @@ var Liveblocks = class {
|
|
|
1166
1243
|
lastConnectionAt: data.lastConnectionAt ? new Date(data.lastConnectionAt) : void 0
|
|
1167
1244
|
};
|
|
1168
1245
|
}
|
|
1169
|
-
async triggerInboxNotification(params) {
|
|
1170
|
-
const res = await this.#post(
|
|
1246
|
+
async triggerInboxNotification(params, options) {
|
|
1247
|
+
const res = await this.#post(
|
|
1248
|
+
url2`/v2/inbox-notifications/trigger`,
|
|
1249
|
+
params,
|
|
1250
|
+
options
|
|
1251
|
+
);
|
|
1171
1252
|
if (!res.ok) {
|
|
1172
|
-
|
|
1173
|
-
throw new LiveblocksError(res.status, text);
|
|
1253
|
+
throw await LiveblocksError.from(res);
|
|
1174
1254
|
}
|
|
1175
1255
|
}
|
|
1176
1256
|
/**
|
|
1177
1257
|
* Deletes an inbox notification for a user.
|
|
1178
1258
|
* @param params.userId The user ID for which to delete the inbox notification.
|
|
1179
1259
|
* @param params.inboxNotificationId The ID of the inbox notification to delete.
|
|
1260
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1180
1261
|
*/
|
|
1181
|
-
async deleteInboxNotification(params) {
|
|
1262
|
+
async deleteInboxNotification(params, options) {
|
|
1182
1263
|
const { userId, inboxNotificationId } = params;
|
|
1183
1264
|
const res = await this.#delete(
|
|
1184
|
-
url2`/v2/users/${userId}/inbox-notifications/${inboxNotificationId}
|
|
1265
|
+
url2`/v2/users/${userId}/inbox-notifications/${inboxNotificationId}`,
|
|
1266
|
+
options
|
|
1185
1267
|
);
|
|
1186
1268
|
if (!res.ok) {
|
|
1187
|
-
|
|
1188
|
-
throw new LiveblocksError(res.status, text);
|
|
1269
|
+
throw await LiveblocksError.from(res);
|
|
1189
1270
|
}
|
|
1190
1271
|
}
|
|
1191
1272
|
/**
|
|
1192
1273
|
* Deletes all inbox notifications for a user.
|
|
1193
1274
|
* @param params.userId The user ID for which to delete all the inbox notifications.
|
|
1275
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1194
1276
|
*/
|
|
1195
|
-
async deleteAllInboxNotifications(params) {
|
|
1277
|
+
async deleteAllInboxNotifications(params, options) {
|
|
1196
1278
|
const { userId } = params;
|
|
1197
1279
|
const res = await this.#delete(
|
|
1198
|
-
url2`/v2/users/${userId}/inbox-notifications
|
|
1280
|
+
url2`/v2/users/${userId}/inbox-notifications`,
|
|
1281
|
+
options
|
|
1199
1282
|
);
|
|
1200
1283
|
if (!res.ok) {
|
|
1201
|
-
|
|
1202
|
-
throw new LiveblocksError(res.status, text);
|
|
1284
|
+
throw await LiveblocksError.from(res);
|
|
1203
1285
|
}
|
|
1204
1286
|
}
|
|
1205
1287
|
/**
|
|
1206
1288
|
* Get notification settings for a user for a project.
|
|
1207
1289
|
* @param params.userId The user ID to get the notifications settings for.
|
|
1290
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1208
1291
|
*/
|
|
1209
|
-
async getNotificationSettings(params) {
|
|
1292
|
+
async getNotificationSettings(params, options) {
|
|
1210
1293
|
const { userId } = params;
|
|
1211
|
-
const res = await this.#get(
|
|
1294
|
+
const res = await this.#get(
|
|
1295
|
+
url2`/v2/users/${userId}/notification-settings`,
|
|
1296
|
+
void 0,
|
|
1297
|
+
options
|
|
1298
|
+
);
|
|
1212
1299
|
if (!res.ok) {
|
|
1213
|
-
|
|
1214
|
-
throw new LiveblocksError(res.status, text);
|
|
1300
|
+
throw await LiveblocksError.from(res);
|
|
1215
1301
|
}
|
|
1216
1302
|
const plainSettings = await res.json();
|
|
1217
1303
|
const settings = createUserNotificationSettings(plainSettings);
|
|
@@ -1221,16 +1307,17 @@ var Liveblocks = class {
|
|
|
1221
1307
|
* Update the user's notification settings.
|
|
1222
1308
|
* @param params.userId The user ID to update the notification settings for.
|
|
1223
1309
|
* @param params.data The new notification settings for the user.
|
|
1310
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1224
1311
|
*/
|
|
1225
|
-
async updateNotificationSettings(params) {
|
|
1312
|
+
async updateNotificationSettings(params, options) {
|
|
1226
1313
|
const { userId, data } = params;
|
|
1227
1314
|
const res = await this.#post(
|
|
1228
1315
|
url2`/v2/users/${userId}/notification-settings`,
|
|
1229
|
-
data
|
|
1316
|
+
data,
|
|
1317
|
+
options
|
|
1230
1318
|
);
|
|
1231
1319
|
if (!res.ok) {
|
|
1232
|
-
|
|
1233
|
-
throw new LiveblocksError(res.status, text);
|
|
1320
|
+
throw await LiveblocksError.from(res);
|
|
1234
1321
|
}
|
|
1235
1322
|
const plainSettings = await res.json();
|
|
1236
1323
|
const settings = createUserNotificationSettings(plainSettings);
|
|
@@ -1239,24 +1326,51 @@ var Liveblocks = class {
|
|
|
1239
1326
|
/**
|
|
1240
1327
|
* Delete the user's notification settings
|
|
1241
1328
|
* @param params.userId The user ID to update the notification settings for.
|
|
1329
|
+
* @param options.signal (optional) An abort signal to cancel the request.
|
|
1242
1330
|
*/
|
|
1243
|
-
async deleteNotificationSettings(params) {
|
|
1331
|
+
async deleteNotificationSettings(params, options) {
|
|
1244
1332
|
const { userId } = params;
|
|
1245
1333
|
const res = await this.#delete(
|
|
1246
|
-
url2`/v2/users/${userId}/notification-settings
|
|
1334
|
+
url2`/v2/users/${userId}/notification-settings`,
|
|
1335
|
+
options
|
|
1247
1336
|
);
|
|
1248
1337
|
if (!res.ok) {
|
|
1249
|
-
|
|
1250
|
-
throw new LiveblocksError(res.status, text);
|
|
1338
|
+
throw await LiveblocksError.from(res);
|
|
1251
1339
|
}
|
|
1252
1340
|
}
|
|
1253
1341
|
};
|
|
1254
|
-
var LiveblocksError = class extends Error {
|
|
1342
|
+
var LiveblocksError = class _LiveblocksError extends Error {
|
|
1255
1343
|
status;
|
|
1256
|
-
|
|
1344
|
+
details;
|
|
1345
|
+
constructor(message, status, details) {
|
|
1257
1346
|
super(message);
|
|
1258
1347
|
this.name = "LiveblocksError";
|
|
1259
1348
|
this.status = status;
|
|
1349
|
+
this.details = details;
|
|
1350
|
+
}
|
|
1351
|
+
toString() {
|
|
1352
|
+
let msg = `${this.name}: ${this.message} (status ${this.status})`;
|
|
1353
|
+
if (this.details) {
|
|
1354
|
+
msg += `
|
|
1355
|
+
${this.details}`;
|
|
1356
|
+
}
|
|
1357
|
+
return msg;
|
|
1358
|
+
}
|
|
1359
|
+
static async from(res) {
|
|
1360
|
+
const FALLBACK = "An error happened without an error message";
|
|
1361
|
+
let text;
|
|
1362
|
+
try {
|
|
1363
|
+
text = await res.text();
|
|
1364
|
+
} catch {
|
|
1365
|
+
text = FALLBACK;
|
|
1366
|
+
}
|
|
1367
|
+
const obj = tryParseJson(text) ?? { message: text };
|
|
1368
|
+
const message = obj.message || FALLBACK;
|
|
1369
|
+
const details = [
|
|
1370
|
+
obj.suggestion ? `Suggestion: ${String(obj.suggestion)}` : void 0,
|
|
1371
|
+
obj.docs ? `See also: ${String(obj.docs)}` : void 0
|
|
1372
|
+
].filter(Boolean).join("\n") || void 0;
|
|
1373
|
+
return new _LiveblocksError(message, res.status, details);
|
|
1260
1374
|
}
|
|
1261
1375
|
};
|
|
1262
1376
|
|