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