@liveblocks/node 2.18.3 → 2.18.4-uns2
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.mjs → index.cjs} +125 -120
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.mts → index.d.cts} +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +124 -119
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { detectDupes } from "@liveblocks/core";
|
|
3
3
|
|
|
4
4
|
// src/version.ts
|
|
5
5
|
var PKG_NAME = "@liveblocks/node";
|
|
6
|
-
var PKG_VERSION = "2.18.
|
|
7
|
-
var PKG_FORMAT = "
|
|
6
|
+
var PKG_VERSION = "2.18.4-uns2";
|
|
7
|
+
var PKG_FORMAT = "esm";
|
|
8
8
|
|
|
9
9
|
// src/client.ts
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
import {
|
|
11
|
+
convertToCommentData,
|
|
12
|
+
convertToCommentUserReaction,
|
|
13
|
+
convertToInboxNotificationData,
|
|
14
|
+
convertToThreadData,
|
|
15
|
+
createUserNotificationSettings,
|
|
16
|
+
objectToQuery,
|
|
17
|
+
url as url2,
|
|
18
|
+
urljoin
|
|
19
|
+
} from "@liveblocks/core";
|
|
19
20
|
|
|
20
21
|
// src/Session.ts
|
|
21
|
-
|
|
22
|
+
import { url } from "@liveblocks/core";
|
|
22
23
|
|
|
23
24
|
// src/utils.ts
|
|
24
25
|
var DEFAULT_BASE_URL = "https://api.liveblocks.io";
|
|
@@ -31,7 +32,7 @@ function getBaseUrl(baseUrl) {
|
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
async function fetchPolyfill() {
|
|
34
|
-
return typeof globalThis.fetch !== "undefined" ? globalThis.fetch : (await
|
|
35
|
+
return typeof globalThis.fetch !== "undefined" ? globalThis.fetch : (await import("node-fetch")).default;
|
|
35
36
|
}
|
|
36
37
|
function isString(value) {
|
|
37
38
|
return typeof value === "string";
|
|
@@ -90,16 +91,16 @@ var READ_ACCESS = Object.freeze([
|
|
|
90
91
|
]);
|
|
91
92
|
var FULL_ACCESS = Object.freeze(["room:write", "comments:write"]);
|
|
92
93
|
var roomPatternRegex = /^([*]|[^*]{1,128}[*]?)$/;
|
|
93
|
-
var Session =
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
var Session = class {
|
|
95
|
+
FULL_ACCESS = FULL_ACCESS;
|
|
96
|
+
READ_ACCESS = READ_ACCESS;
|
|
96
97
|
#postFn;
|
|
97
98
|
#userId;
|
|
98
99
|
#userInfo;
|
|
99
100
|
#sealed = false;
|
|
100
101
|
#permissions = /* @__PURE__ */ new Map();
|
|
101
102
|
/** @internal */
|
|
102
|
-
constructor(postFn, userId, userInfo) {
|
|
103
|
+
constructor(postFn, userId, userInfo) {
|
|
103
104
|
assertNonEmpty(userId, "userId");
|
|
104
105
|
this.#postFn = postFn;
|
|
105
106
|
this.#userId = userId;
|
|
@@ -177,7 +178,7 @@ var Session = (_class = class {
|
|
|
177
178
|
);
|
|
178
179
|
}
|
|
179
180
|
try {
|
|
180
|
-
const resp = await this.#postFn(
|
|
181
|
+
const resp = await this.#postFn(url`/v2/authorize-user`, {
|
|
181
182
|
// Required
|
|
182
183
|
userId: this.#userId,
|
|
183
184
|
permissions: this.serializePermissions(),
|
|
@@ -196,7 +197,7 @@ var Session = (_class = class {
|
|
|
196
197
|
};
|
|
197
198
|
}
|
|
198
199
|
}
|
|
199
|
-
}
|
|
200
|
+
};
|
|
200
201
|
|
|
201
202
|
// src/client.ts
|
|
202
203
|
var Liveblocks = class {
|
|
@@ -213,7 +214,7 @@ var Liveblocks = class {
|
|
|
213
214
|
this.#baseUrl = new URL(getBaseUrl(options.baseUrl));
|
|
214
215
|
}
|
|
215
216
|
async #post(path, json) {
|
|
216
|
-
const url3 =
|
|
217
|
+
const url3 = urljoin(this.#baseUrl, path);
|
|
217
218
|
const headers = {
|
|
218
219
|
Authorization: `Bearer ${this.#secret}`,
|
|
219
220
|
"Content-Type": "application/json"
|
|
@@ -227,7 +228,7 @@ var Liveblocks = class {
|
|
|
227
228
|
return res;
|
|
228
229
|
}
|
|
229
230
|
async #put(path, json) {
|
|
230
|
-
const url3 =
|
|
231
|
+
const url3 = urljoin(this.#baseUrl, path);
|
|
231
232
|
const headers = {
|
|
232
233
|
Authorization: `Bearer ${this.#secret}`,
|
|
233
234
|
"Content-Type": "application/json"
|
|
@@ -240,7 +241,7 @@ var Liveblocks = class {
|
|
|
240
241
|
});
|
|
241
242
|
}
|
|
242
243
|
async #putBinary(path, body, params) {
|
|
243
|
-
const url3 =
|
|
244
|
+
const url3 = urljoin(this.#baseUrl, path, params);
|
|
244
245
|
const headers = {
|
|
245
246
|
Authorization: `Bearer ${this.#secret}`,
|
|
246
247
|
"Content-Type": "application/octet-stream"
|
|
@@ -249,7 +250,7 @@ var Liveblocks = class {
|
|
|
249
250
|
return await fetch(url3, { method: "PUT", headers, body });
|
|
250
251
|
}
|
|
251
252
|
async #delete(path) {
|
|
252
|
-
const url3 =
|
|
253
|
+
const url3 = urljoin(this.#baseUrl, path);
|
|
253
254
|
const headers = {
|
|
254
255
|
Authorization: `Bearer ${this.#secret}`
|
|
255
256
|
};
|
|
@@ -258,7 +259,7 @@ var Liveblocks = class {
|
|
|
258
259
|
return res;
|
|
259
260
|
}
|
|
260
261
|
async #get(path, params) {
|
|
261
|
-
const url3 =
|
|
262
|
+
const url3 = urljoin(this.#baseUrl, path, params);
|
|
262
263
|
const headers = {
|
|
263
264
|
Authorization: `Bearer ${this.#secret}`
|
|
264
265
|
};
|
|
@@ -287,7 +288,7 @@ var Liveblocks = class {
|
|
|
287
288
|
*/
|
|
288
289
|
prepareSession(userId, ...rest) {
|
|
289
290
|
const options = rest[0];
|
|
290
|
-
return new Session(this.#post.bind(this), userId,
|
|
291
|
+
return new Session(this.#post.bind(this), userId, options?.userInfo);
|
|
291
292
|
}
|
|
292
293
|
/**
|
|
293
294
|
* Call this to authenticate the user as an actor you want to allow to use
|
|
@@ -324,7 +325,7 @@ var Liveblocks = class {
|
|
|
324
325
|
// These fields define the security identity of the user. Whatever you pass in here will define which
|
|
325
326
|
async identifyUser(identity, ...rest) {
|
|
326
327
|
const options = rest[0];
|
|
327
|
-
const path =
|
|
328
|
+
const path = url2`/v2/identify-user`;
|
|
328
329
|
const userId = typeof identity === "string" ? identity : identity.userId;
|
|
329
330
|
const groupIds = typeof identity === "string" ? void 0 : identity.groupIds;
|
|
330
331
|
assertNonEmpty(userId, "userId");
|
|
@@ -333,7 +334,7 @@ var Liveblocks = class {
|
|
|
333
334
|
userId,
|
|
334
335
|
groupIds,
|
|
335
336
|
// Optional metadata
|
|
336
|
-
userInfo:
|
|
337
|
+
userInfo: options?.userInfo
|
|
337
338
|
});
|
|
338
339
|
return {
|
|
339
340
|
status: normalizeStatusCode(resp.status),
|
|
@@ -342,7 +343,7 @@ var Liveblocks = class {
|
|
|
342
343
|
} catch (er) {
|
|
343
344
|
return {
|
|
344
345
|
status: 503,
|
|
345
|
-
body: `Call to ${
|
|
346
|
+
body: `Call to ${urljoin(
|
|
346
347
|
this.#baseUrl,
|
|
347
348
|
path
|
|
348
349
|
)} failed. See "error" for more information.`,
|
|
@@ -364,12 +365,12 @@ var Liveblocks = class {
|
|
|
364
365
|
* @returns A list of rooms.
|
|
365
366
|
*/
|
|
366
367
|
async getRooms(params = {}) {
|
|
367
|
-
const path =
|
|
368
|
+
const path = url2`/v2/rooms`;
|
|
368
369
|
let query;
|
|
369
370
|
if (typeof params.query === "string") {
|
|
370
371
|
query = params.query;
|
|
371
372
|
} else if (typeof params.query === "object") {
|
|
372
|
-
query =
|
|
373
|
+
query = objectToQuery(params.query);
|
|
373
374
|
}
|
|
374
375
|
const queryParams = {
|
|
375
376
|
limit: params.limit,
|
|
@@ -378,7 +379,7 @@ var Liveblocks = class {
|
|
|
378
379
|
groupIds: params.groupIds ? params.groupIds.join(",") : void 0,
|
|
379
380
|
// "Flatten" {metadata: {foo: "bar"}} to {"metadata.foo": "bar"}
|
|
380
381
|
...Object.fromEntries(
|
|
381
|
-
Object.entries(
|
|
382
|
+
Object.entries(params.metadata ?? {}).map(([key, val]) => [
|
|
382
383
|
`metadata.${key}`,
|
|
383
384
|
val
|
|
384
385
|
])
|
|
@@ -416,7 +417,7 @@ var Liveblocks = class {
|
|
|
416
417
|
*/
|
|
417
418
|
async createRoom(roomId, params) {
|
|
418
419
|
const { defaultAccesses, groupsAccesses, usersAccesses, metadata } = params;
|
|
419
|
-
const res = await this.#post(
|
|
420
|
+
const res = await this.#post(url2`/v2/rooms`, {
|
|
420
421
|
id: roomId,
|
|
421
422
|
defaultAccesses,
|
|
422
423
|
groupsAccesses,
|
|
@@ -442,7 +443,7 @@ var Liveblocks = class {
|
|
|
442
443
|
* @returns The room with the given id.
|
|
443
444
|
*/
|
|
444
445
|
async getRoom(roomId) {
|
|
445
|
-
const res = await this.#get(
|
|
446
|
+
const res = await this.#get(url2`/v2/rooms/${roomId}`);
|
|
446
447
|
if (!res.ok) {
|
|
447
448
|
const text = await res.text();
|
|
448
449
|
throw new LiveblocksError(res.status, text);
|
|
@@ -468,7 +469,7 @@ var Liveblocks = class {
|
|
|
468
469
|
*/
|
|
469
470
|
async updateRoom(roomId, params) {
|
|
470
471
|
const { defaultAccesses, groupsAccesses, usersAccesses, metadata } = params;
|
|
471
|
-
const res = await this.#post(
|
|
472
|
+
const res = await this.#post(url2`/v2/rooms/${roomId}`, {
|
|
472
473
|
defaultAccesses,
|
|
473
474
|
groupsAccesses,
|
|
474
475
|
usersAccesses,
|
|
@@ -492,7 +493,7 @@ var Liveblocks = class {
|
|
|
492
493
|
* @param roomId The id of the room to delete.
|
|
493
494
|
*/
|
|
494
495
|
async deleteRoom(roomId) {
|
|
495
|
-
const res = await this.#delete(
|
|
496
|
+
const res = await this.#delete(url2`/v2/rooms/${roomId}`);
|
|
496
497
|
if (!res.ok) {
|
|
497
498
|
const text = await res.text();
|
|
498
499
|
throw new LiveblocksError(res.status, text);
|
|
@@ -504,7 +505,7 @@ var Liveblocks = class {
|
|
|
504
505
|
* @returns A list of users currently present in the requested room.
|
|
505
506
|
*/
|
|
506
507
|
async getActiveUsers(roomId) {
|
|
507
|
-
const res = await this.#get(
|
|
508
|
+
const res = await this.#get(url2`/v2/rooms/${roomId}/active_users`);
|
|
508
509
|
if (!res.ok) {
|
|
509
510
|
const text = await res.text();
|
|
510
511
|
throw new LiveblocksError(res.status, text);
|
|
@@ -518,7 +519,7 @@ var Liveblocks = class {
|
|
|
518
519
|
*/
|
|
519
520
|
async broadcastEvent(roomId, message) {
|
|
520
521
|
const res = await this.#post(
|
|
521
|
-
|
|
522
|
+
url2`/v2/rooms/${roomId}/broadcast_event`,
|
|
522
523
|
message
|
|
523
524
|
);
|
|
524
525
|
if (!res.ok) {
|
|
@@ -527,7 +528,7 @@ var Liveblocks = class {
|
|
|
527
528
|
}
|
|
528
529
|
}
|
|
529
530
|
async getStorageDocument(roomId, format = "plain-lson") {
|
|
530
|
-
const res = await this.#get(
|
|
531
|
+
const res = await this.#get(url2`/v2/rooms/${roomId}/storage`, { format });
|
|
531
532
|
if (!res.ok) {
|
|
532
533
|
const text = await res.text();
|
|
533
534
|
throw new LiveblocksError(res.status, text);
|
|
@@ -543,7 +544,7 @@ var Liveblocks = class {
|
|
|
543
544
|
* @returns The initialized storage document. It is of the same format as the one passed in.
|
|
544
545
|
*/
|
|
545
546
|
async initializeStorageDocument(roomId, document) {
|
|
546
|
-
const res = await this.#post(
|
|
547
|
+
const res = await this.#post(url2`/v2/rooms/${roomId}/storage`, document);
|
|
547
548
|
if (!res.ok) {
|
|
548
549
|
const text = await res.text();
|
|
549
550
|
throw new LiveblocksError(res.status, text);
|
|
@@ -555,7 +556,7 @@ var Liveblocks = class {
|
|
|
555
556
|
* @param roomId The id of the room to delete the storage from.
|
|
556
557
|
*/
|
|
557
558
|
async deleteStorageDocument(roomId) {
|
|
558
|
-
const res = await this.#delete(
|
|
559
|
+
const res = await this.#delete(url2`/v2/rooms/${roomId}/storage`);
|
|
559
560
|
if (!res.ok) {
|
|
560
561
|
const text = await res.text();
|
|
561
562
|
throw new LiveblocksError(res.status, text);
|
|
@@ -574,7 +575,7 @@ var Liveblocks = class {
|
|
|
574
575
|
*/
|
|
575
576
|
async getYjsDocument(roomId, params = {}) {
|
|
576
577
|
const { format, key, type } = params;
|
|
577
|
-
const path =
|
|
578
|
+
const path = url2`v2/rooms/${roomId}/ydoc`;
|
|
578
579
|
const res = await this.#get(path, {
|
|
579
580
|
formatting: format ? "true" : void 0,
|
|
580
581
|
key,
|
|
@@ -593,7 +594,7 @@ var Liveblocks = class {
|
|
|
593
594
|
* @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.
|
|
594
595
|
*/
|
|
595
596
|
async sendYjsBinaryUpdate(roomId, update, params = {}) {
|
|
596
|
-
const res = await this.#putBinary(
|
|
597
|
+
const res = await this.#putBinary(url2`/v2/rooms/${roomId}/ydoc`, update, {
|
|
597
598
|
guid: params.guid
|
|
598
599
|
});
|
|
599
600
|
if (!res.ok) {
|
|
@@ -609,7 +610,7 @@ var Liveblocks = class {
|
|
|
609
610
|
* @returns The room’s Yjs document encoded as a single binary update.
|
|
610
611
|
*/
|
|
611
612
|
async getYjsDocumentAsBinaryUpdate(roomId, params = {}) {
|
|
612
|
-
const res = await this.#get(
|
|
613
|
+
const res = await this.#get(url2`/v2/rooms/${roomId}/ydoc-binary`, {
|
|
613
614
|
guid: params.guid
|
|
614
615
|
});
|
|
615
616
|
if (!res.ok) {
|
|
@@ -628,7 +629,7 @@ var Liveblocks = class {
|
|
|
628
629
|
* @returns The created schema.
|
|
629
630
|
*/
|
|
630
631
|
async createSchema(name, body) {
|
|
631
|
-
const res = await this.#post(
|
|
632
|
+
const res = await this.#post(url2`/v2/schemas`, {
|
|
632
633
|
name,
|
|
633
634
|
body
|
|
634
635
|
});
|
|
@@ -651,7 +652,7 @@ var Liveblocks = class {
|
|
|
651
652
|
* @returns The schema with the given id.
|
|
652
653
|
*/
|
|
653
654
|
async getSchema(schemaId) {
|
|
654
|
-
const res = await this.#get(
|
|
655
|
+
const res = await this.#get(url2`/v2/schemas/${schemaId}`);
|
|
655
656
|
if (!res.ok) {
|
|
656
657
|
const text = await res.text();
|
|
657
658
|
throw new LiveblocksError(res.status, text);
|
|
@@ -672,7 +673,7 @@ var Liveblocks = class {
|
|
|
672
673
|
* @returns The updated schema. The version of the schema will be incremented.
|
|
673
674
|
*/
|
|
674
675
|
async updateSchema(schemaId, body) {
|
|
675
|
-
const res = await this.#put(
|
|
676
|
+
const res = await this.#put(url2`/v2/schemas/${schemaId}`, {
|
|
676
677
|
body
|
|
677
678
|
});
|
|
678
679
|
if (!res.ok) {
|
|
@@ -693,7 +694,7 @@ var Liveblocks = class {
|
|
|
693
694
|
* @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`.
|
|
694
695
|
*/
|
|
695
696
|
async deleteSchema(schemaId) {
|
|
696
|
-
const res = await this.#delete(
|
|
697
|
+
const res = await this.#delete(url2`/v2/schemas/${schemaId}`);
|
|
697
698
|
if (!res.ok) {
|
|
698
699
|
const text = await res.text();
|
|
699
700
|
throw new LiveblocksError(res.status, text);
|
|
@@ -705,7 +706,7 @@ var Liveblocks = class {
|
|
|
705
706
|
* @returns
|
|
706
707
|
*/
|
|
707
708
|
async getSchemaByRoomId(roomId) {
|
|
708
|
-
const res = await this.#get(
|
|
709
|
+
const res = await this.#get(url2`/v2/rooms/${roomId}/schema`);
|
|
709
710
|
if (!res.ok) {
|
|
710
711
|
const text = await res.text();
|
|
711
712
|
throw new LiveblocksError(res.status, text);
|
|
@@ -727,7 +728,7 @@ var Liveblocks = class {
|
|
|
727
728
|
* @returns The schema id as JSON.
|
|
728
729
|
*/
|
|
729
730
|
async attachSchemaToRoom(roomId, schemaId) {
|
|
730
|
-
const res = await this.#post(
|
|
731
|
+
const res = await this.#post(url2`/v2/rooms/${roomId}/schema`, {
|
|
731
732
|
schema: schemaId
|
|
732
733
|
});
|
|
733
734
|
if (!res.ok) {
|
|
@@ -741,7 +742,7 @@ var Liveblocks = class {
|
|
|
741
742
|
* @param roomId The id of the room to detach the schema from.
|
|
742
743
|
*/
|
|
743
744
|
async detachSchemaFromRoom(roomId) {
|
|
744
|
-
const res = await this.#delete(
|
|
745
|
+
const res = await this.#delete(url2`/v2/rooms/${roomId}/schema`);
|
|
745
746
|
if (!res.ok) {
|
|
746
747
|
const text = await res.text();
|
|
747
748
|
throw new LiveblocksError(res.status, text);
|
|
@@ -763,9 +764,9 @@ var Liveblocks = class {
|
|
|
763
764
|
if (typeof params.query === "string") {
|
|
764
765
|
query = params.query;
|
|
765
766
|
} else if (typeof params.query === "object") {
|
|
766
|
-
query =
|
|
767
|
+
query = objectToQuery(params.query);
|
|
767
768
|
}
|
|
768
|
-
const res = await this.#get(
|
|
769
|
+
const res = await this.#get(url2`/v2/rooms/${roomId}/threads`, {
|
|
769
770
|
query
|
|
770
771
|
});
|
|
771
772
|
if (!res.ok) {
|
|
@@ -774,7 +775,7 @@ var Liveblocks = class {
|
|
|
774
775
|
}
|
|
775
776
|
const { data } = await res.json();
|
|
776
777
|
return {
|
|
777
|
-
data: data.map((thread) =>
|
|
778
|
+
data: data.map((thread) => convertToThreadData(thread))
|
|
778
779
|
};
|
|
779
780
|
}
|
|
780
781
|
/**
|
|
@@ -786,12 +787,12 @@ var Liveblocks = class {
|
|
|
786
787
|
*/
|
|
787
788
|
async getThread(params) {
|
|
788
789
|
const { roomId, threadId } = params;
|
|
789
|
-
const res = await this.#get(
|
|
790
|
+
const res = await this.#get(url2`/v2/rooms/${roomId}/threads/${threadId}`);
|
|
790
791
|
if (!res.ok) {
|
|
791
792
|
const text = await res.text();
|
|
792
793
|
throw new LiveblocksError(res.status, text);
|
|
793
794
|
}
|
|
794
|
-
return
|
|
795
|
+
return convertToThreadData(await res.json());
|
|
795
796
|
}
|
|
796
797
|
/**
|
|
797
798
|
* Gets a thread's participants.
|
|
@@ -806,7 +807,7 @@ var Liveblocks = class {
|
|
|
806
807
|
async getThreadParticipants(params) {
|
|
807
808
|
const { roomId, threadId } = params;
|
|
808
809
|
const res = await this.#get(
|
|
809
|
-
|
|
810
|
+
url2`/v2/rooms/${roomId}/threads/${threadId}/participants`
|
|
810
811
|
);
|
|
811
812
|
if (!res.ok) {
|
|
812
813
|
const text = await res.text();
|
|
@@ -825,13 +826,13 @@ var Liveblocks = class {
|
|
|
825
826
|
async getComment(params) {
|
|
826
827
|
const { roomId, threadId, commentId } = params;
|
|
827
828
|
const res = await this.#get(
|
|
828
|
-
|
|
829
|
+
url2`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}`
|
|
829
830
|
);
|
|
830
831
|
if (!res.ok) {
|
|
831
832
|
const text = await res.text();
|
|
832
833
|
throw new LiveblocksError(res.status, text);
|
|
833
834
|
}
|
|
834
|
-
return
|
|
835
|
+
return convertToCommentData(await res.json());
|
|
835
836
|
}
|
|
836
837
|
/**
|
|
837
838
|
* Creates a comment.
|
|
@@ -846,17 +847,17 @@ var Liveblocks = class {
|
|
|
846
847
|
async createComment(params) {
|
|
847
848
|
const { roomId, threadId, data } = params;
|
|
848
849
|
const res = await this.#post(
|
|
849
|
-
|
|
850
|
+
url2`/v2/rooms/${roomId}/threads/${threadId}/comments`,
|
|
850
851
|
{
|
|
851
852
|
...data,
|
|
852
|
-
createdAt:
|
|
853
|
+
createdAt: data.createdAt?.toISOString()
|
|
853
854
|
}
|
|
854
855
|
);
|
|
855
856
|
if (!res.ok) {
|
|
856
857
|
const text = await res.text();
|
|
857
858
|
throw new LiveblocksError(res.status, text);
|
|
858
859
|
}
|
|
859
|
-
return
|
|
860
|
+
return convertToCommentData(await res.json());
|
|
860
861
|
}
|
|
861
862
|
/**
|
|
862
863
|
* Edits a comment.
|
|
@@ -870,17 +871,17 @@ var Liveblocks = class {
|
|
|
870
871
|
async editComment(params) {
|
|
871
872
|
const { roomId, threadId, commentId, data } = params;
|
|
872
873
|
const res = await this.#post(
|
|
873
|
-
|
|
874
|
+
url2`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}`,
|
|
874
875
|
{
|
|
875
876
|
...data,
|
|
876
|
-
editedAt:
|
|
877
|
+
editedAt: data.editedAt?.toISOString()
|
|
877
878
|
}
|
|
878
879
|
);
|
|
879
880
|
if (!res.ok) {
|
|
880
881
|
const text = await res.text();
|
|
881
882
|
throw new LiveblocksError(res.status, text);
|
|
882
883
|
}
|
|
883
|
-
return
|
|
884
|
+
return convertToCommentData(await res.json());
|
|
884
885
|
}
|
|
885
886
|
/**
|
|
886
887
|
* Deletes a comment. Deletes a comment. If there are no remaining comments in the thread, the thread is also deleted.
|
|
@@ -891,7 +892,7 @@ var Liveblocks = class {
|
|
|
891
892
|
async deleteComment(params) {
|
|
892
893
|
const { roomId, threadId, commentId } = params;
|
|
893
894
|
const res = await this.#delete(
|
|
894
|
-
|
|
895
|
+
url2`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}`
|
|
895
896
|
);
|
|
896
897
|
if (!res.ok) {
|
|
897
898
|
const text = await res.text();
|
|
@@ -910,18 +911,18 @@ var Liveblocks = class {
|
|
|
910
911
|
*/
|
|
911
912
|
async createThread(params) {
|
|
912
913
|
const { roomId, data } = params;
|
|
913
|
-
const res = await this.#post(
|
|
914
|
+
const res = await this.#post(url2`/v2/rooms/${roomId}/threads`, {
|
|
914
915
|
...data,
|
|
915
916
|
comment: {
|
|
916
917
|
...data.comment,
|
|
917
|
-
createdAt:
|
|
918
|
+
createdAt: data.comment.createdAt?.toISOString()
|
|
918
919
|
}
|
|
919
920
|
});
|
|
920
921
|
if (!res.ok) {
|
|
921
922
|
const text = await res.text();
|
|
922
923
|
throw new LiveblocksError(res.status, text);
|
|
923
924
|
}
|
|
924
|
-
return
|
|
925
|
+
return convertToThreadData(await res.json());
|
|
925
926
|
}
|
|
926
927
|
/**
|
|
927
928
|
* Deletes a thread and all of its comments.
|
|
@@ -931,7 +932,7 @@ var Liveblocks = class {
|
|
|
931
932
|
async deleteThread(params) {
|
|
932
933
|
const { roomId, threadId } = params;
|
|
933
934
|
const res = await this.#delete(
|
|
934
|
-
|
|
935
|
+
url2`/v2/rooms/${roomId}/threads/${threadId}`
|
|
935
936
|
);
|
|
936
937
|
if (!res.ok) {
|
|
937
938
|
const text = await res.text();
|
|
@@ -948,14 +949,14 @@ var Liveblocks = class {
|
|
|
948
949
|
async markThreadAsResolved(params) {
|
|
949
950
|
const { roomId, threadId } = params;
|
|
950
951
|
const res = await this.#post(
|
|
951
|
-
|
|
952
|
+
url2`/v2/rooms/${roomId}/threads/${threadId}/mark-as-resolved`,
|
|
952
953
|
{}
|
|
953
954
|
);
|
|
954
955
|
if (!res.ok) {
|
|
955
956
|
const text = await res.text();
|
|
956
957
|
throw new LiveblocksError(res.status, text);
|
|
957
958
|
}
|
|
958
|
-
return
|
|
959
|
+
return convertToThreadData(await res.json());
|
|
959
960
|
}
|
|
960
961
|
/**
|
|
961
962
|
* Mark a thread as unresolved.
|
|
@@ -967,14 +968,14 @@ var Liveblocks = class {
|
|
|
967
968
|
async markThreadAsUnresolved(params) {
|
|
968
969
|
const { roomId, threadId } = params;
|
|
969
970
|
const res = await this.#post(
|
|
970
|
-
|
|
971
|
+
url2`/v2/rooms/${roomId}/threads/${threadId}/mark-as-unresolved`,
|
|
971
972
|
{}
|
|
972
973
|
);
|
|
973
974
|
if (!res.ok) {
|
|
974
975
|
const text = await res.text();
|
|
975
976
|
throw new LiveblocksError(res.status, text);
|
|
976
977
|
}
|
|
977
|
-
return
|
|
978
|
+
return convertToThreadData(await res.json());
|
|
978
979
|
}
|
|
979
980
|
/**
|
|
980
981
|
* Updates the metadata of the specified thread in a room.
|
|
@@ -988,10 +989,10 @@ var Liveblocks = class {
|
|
|
988
989
|
async editThreadMetadata(params) {
|
|
989
990
|
const { roomId, threadId, data } = params;
|
|
990
991
|
const res = await this.#post(
|
|
991
|
-
|
|
992
|
+
url2`/v2/rooms/${roomId}/threads/${threadId}/metadata`,
|
|
992
993
|
{
|
|
993
994
|
...data,
|
|
994
|
-
updatedAt:
|
|
995
|
+
updatedAt: data.updatedAt?.toISOString()
|
|
995
996
|
}
|
|
996
997
|
);
|
|
997
998
|
if (!res.ok) {
|
|
@@ -1013,10 +1014,10 @@ var Liveblocks = class {
|
|
|
1013
1014
|
async addCommentReaction(params) {
|
|
1014
1015
|
const { roomId, threadId, commentId, data } = params;
|
|
1015
1016
|
const res = await this.#post(
|
|
1016
|
-
|
|
1017
|
+
url2`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}/add-reaction`,
|
|
1017
1018
|
{
|
|
1018
1019
|
...data,
|
|
1019
|
-
createdAt:
|
|
1020
|
+
createdAt: data.createdAt?.toISOString()
|
|
1020
1021
|
}
|
|
1021
1022
|
);
|
|
1022
1023
|
if (!res.ok) {
|
|
@@ -1024,7 +1025,7 @@ var Liveblocks = class {
|
|
|
1024
1025
|
throw new LiveblocksError(res.status, text);
|
|
1025
1026
|
}
|
|
1026
1027
|
const reaction = await res.json();
|
|
1027
|
-
return
|
|
1028
|
+
return convertToCommentUserReaction(reaction);
|
|
1028
1029
|
}
|
|
1029
1030
|
/**
|
|
1030
1031
|
* Removes a reaction from a comment.
|
|
@@ -1038,10 +1039,10 @@ var Liveblocks = class {
|
|
|
1038
1039
|
async removeCommentReaction(params) {
|
|
1039
1040
|
const { roomId, threadId, data } = params;
|
|
1040
1041
|
const res = await this.#post(
|
|
1041
|
-
|
|
1042
|
+
url2`/v2/rooms/${roomId}/threads/${threadId}/comments/${params.commentId}/remove-reaction`,
|
|
1042
1043
|
{
|
|
1043
1044
|
...data,
|
|
1044
|
-
removedAt:
|
|
1045
|
+
removedAt: data.removedAt?.toISOString()
|
|
1045
1046
|
}
|
|
1046
1047
|
);
|
|
1047
1048
|
if (!res.ok) {
|
|
@@ -1057,13 +1058,13 @@ var Liveblocks = class {
|
|
|
1057
1058
|
async getInboxNotification(params) {
|
|
1058
1059
|
const { userId, inboxNotificationId } = params;
|
|
1059
1060
|
const res = await this.#get(
|
|
1060
|
-
|
|
1061
|
+
url2`/v2/users/${userId}/inbox-notifications/${inboxNotificationId}`
|
|
1061
1062
|
);
|
|
1062
1063
|
if (!res.ok) {
|
|
1063
1064
|
const text = await res.text();
|
|
1064
1065
|
throw new LiveblocksError(res.status, text);
|
|
1065
1066
|
}
|
|
1066
|
-
return
|
|
1067
|
+
return convertToInboxNotificationData(
|
|
1067
1068
|
await res.json()
|
|
1068
1069
|
);
|
|
1069
1070
|
}
|
|
@@ -1078,9 +1079,9 @@ var Liveblocks = class {
|
|
|
1078
1079
|
if (typeof params.query === "string") {
|
|
1079
1080
|
query = params.query;
|
|
1080
1081
|
} else if (typeof params.query === "object") {
|
|
1081
|
-
query =
|
|
1082
|
+
query = objectToQuery(params.query);
|
|
1082
1083
|
}
|
|
1083
|
-
const res = await this.#get(
|
|
1084
|
+
const res = await this.#get(url2`/v2/users/${userId}/inbox-notifications`, {
|
|
1084
1085
|
query
|
|
1085
1086
|
});
|
|
1086
1087
|
if (!res.ok) {
|
|
@@ -1089,7 +1090,7 @@ var Liveblocks = class {
|
|
|
1089
1090
|
}
|
|
1090
1091
|
const { data } = await res.json();
|
|
1091
1092
|
return {
|
|
1092
|
-
data: data.map(
|
|
1093
|
+
data: data.map(convertToInboxNotificationData)
|
|
1093
1094
|
};
|
|
1094
1095
|
}
|
|
1095
1096
|
/**
|
|
@@ -1100,7 +1101,7 @@ var Liveblocks = class {
|
|
|
1100
1101
|
async getRoomNotificationSettings(params) {
|
|
1101
1102
|
const { userId, roomId } = params;
|
|
1102
1103
|
const res = await this.#get(
|
|
1103
|
-
|
|
1104
|
+
url2`/v2/rooms/${roomId}/users/${userId}/notification-settings`
|
|
1104
1105
|
);
|
|
1105
1106
|
if (!res.ok) {
|
|
1106
1107
|
const text = await res.text();
|
|
@@ -1117,7 +1118,7 @@ var Liveblocks = class {
|
|
|
1117
1118
|
async updateRoomNotificationSettings(params) {
|
|
1118
1119
|
const { userId, roomId, data } = params;
|
|
1119
1120
|
const res = await this.#post(
|
|
1120
|
-
|
|
1121
|
+
url2`/v2/rooms/${roomId}/users/${userId}/notification-settings`,
|
|
1121
1122
|
data
|
|
1122
1123
|
);
|
|
1123
1124
|
if (!res.ok) {
|
|
@@ -1134,7 +1135,7 @@ var Liveblocks = class {
|
|
|
1134
1135
|
async deleteRoomNotificationSettings(params) {
|
|
1135
1136
|
const { userId, roomId } = params;
|
|
1136
1137
|
const res = await this.#delete(
|
|
1137
|
-
|
|
1138
|
+
url2`/v2/rooms/${roomId}/users/${userId}/notification-settings`
|
|
1138
1139
|
);
|
|
1139
1140
|
if (!res.ok) {
|
|
1140
1141
|
const text = await res.text();
|
|
@@ -1149,7 +1150,7 @@ var Liveblocks = class {
|
|
|
1149
1150
|
async updateRoomId(params) {
|
|
1150
1151
|
const { currentRoomId, newRoomId } = params;
|
|
1151
1152
|
const res = await this.#post(
|
|
1152
|
-
|
|
1153
|
+
url2`/v2/rooms/${currentRoomId}/update-room-id`,
|
|
1153
1154
|
{
|
|
1154
1155
|
newRoomId
|
|
1155
1156
|
}
|
|
@@ -1166,7 +1167,7 @@ var Liveblocks = class {
|
|
|
1166
1167
|
};
|
|
1167
1168
|
}
|
|
1168
1169
|
async triggerInboxNotification(params) {
|
|
1169
|
-
const res = await this.#post(
|
|
1170
|
+
const res = await this.#post(url2`/v2/inbox-notifications/trigger`, params);
|
|
1170
1171
|
if (!res.ok) {
|
|
1171
1172
|
const text = await res.text();
|
|
1172
1173
|
throw new LiveblocksError(res.status, text);
|
|
@@ -1180,7 +1181,7 @@ var Liveblocks = class {
|
|
|
1180
1181
|
async deleteInboxNotification(params) {
|
|
1181
1182
|
const { userId, inboxNotificationId } = params;
|
|
1182
1183
|
const res = await this.#delete(
|
|
1183
|
-
|
|
1184
|
+
url2`/v2/users/${userId}/inbox-notifications/${inboxNotificationId}`
|
|
1184
1185
|
);
|
|
1185
1186
|
if (!res.ok) {
|
|
1186
1187
|
const text = await res.text();
|
|
@@ -1194,7 +1195,7 @@ var Liveblocks = class {
|
|
|
1194
1195
|
async deleteAllInboxNotifications(params) {
|
|
1195
1196
|
const { userId } = params;
|
|
1196
1197
|
const res = await this.#delete(
|
|
1197
|
-
|
|
1198
|
+
url2`/v2/users/${userId}/inbox-notifications`
|
|
1198
1199
|
);
|
|
1199
1200
|
if (!res.ok) {
|
|
1200
1201
|
const text = await res.text();
|
|
@@ -1207,12 +1208,14 @@ var Liveblocks = class {
|
|
|
1207
1208
|
*/
|
|
1208
1209
|
async getNotificationSettings(params) {
|
|
1209
1210
|
const { userId } = params;
|
|
1210
|
-
const res = await this.#get(
|
|
1211
|
+
const res = await this.#get(url2`/v2/users/${userId}/notification-settings`);
|
|
1211
1212
|
if (!res.ok) {
|
|
1212
1213
|
const text = await res.text();
|
|
1213
1214
|
throw new LiveblocksError(res.status, text);
|
|
1214
1215
|
}
|
|
1215
|
-
|
|
1216
|
+
const plainSettings = await res.json();
|
|
1217
|
+
const settings = createUserNotificationSettings(plainSettings);
|
|
1218
|
+
return settings;
|
|
1216
1219
|
}
|
|
1217
1220
|
/**
|
|
1218
1221
|
* Update the user's notification settings.
|
|
@@ -1222,14 +1225,16 @@ var Liveblocks = class {
|
|
|
1222
1225
|
async updateNotificationSettings(params) {
|
|
1223
1226
|
const { userId, data } = params;
|
|
1224
1227
|
const res = await this.#post(
|
|
1225
|
-
|
|
1228
|
+
url2`/v2/users/${userId}/notification-settings`,
|
|
1226
1229
|
data
|
|
1227
1230
|
);
|
|
1228
1231
|
if (!res.ok) {
|
|
1229
1232
|
const text = await res.text();
|
|
1230
1233
|
throw new LiveblocksError(res.status, text);
|
|
1231
1234
|
}
|
|
1232
|
-
|
|
1235
|
+
const plainSettings = await res.json();
|
|
1236
|
+
const settings = createUserNotificationSettings(plainSettings);
|
|
1237
|
+
return settings;
|
|
1233
1238
|
}
|
|
1234
1239
|
/**
|
|
1235
1240
|
* Delete the user's notification settings
|
|
@@ -1238,7 +1243,7 @@ var Liveblocks = class {
|
|
|
1238
1243
|
async deleteNotificationSettings(params) {
|
|
1239
1244
|
const { userId } = params;
|
|
1240
1245
|
const res = await this.#delete(
|
|
1241
|
-
|
|
1246
|
+
url2`/v2/users/${userId}/notification-settings`
|
|
1242
1247
|
);
|
|
1243
1248
|
if (!res.ok) {
|
|
1244
1249
|
const text = await res.text();
|
|
@@ -1247,7 +1252,7 @@ var Liveblocks = class {
|
|
|
1247
1252
|
}
|
|
1248
1253
|
};
|
|
1249
1254
|
var LiveblocksError = class extends Error {
|
|
1250
|
-
|
|
1255
|
+
status;
|
|
1251
1256
|
constructor(status, message = "") {
|
|
1252
1257
|
super(message);
|
|
1253
1258
|
this.name = "LiveblocksError";
|
|
@@ -1256,8 +1261,8 @@ var LiveblocksError = class extends Error {
|
|
|
1256
1261
|
};
|
|
1257
1262
|
|
|
1258
1263
|
// src/webhooks.ts
|
|
1259
|
-
|
|
1260
|
-
|
|
1264
|
+
import * as base64 from "@stablelib/base64";
|
|
1265
|
+
import * as sha256 from "fast-sha256";
|
|
1261
1266
|
var WebhookHandler = class _WebhookHandler {
|
|
1262
1267
|
#secretBuffer;
|
|
1263
1268
|
static #secretPrefix = "whsec_";
|
|
@@ -1400,21 +1405,21 @@ function isCustomNotificationEvent(event) {
|
|
|
1400
1405
|
}
|
|
1401
1406
|
|
|
1402
1407
|
// src/index.ts
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1408
|
+
import {
|
|
1409
|
+
getMentionedIdsFromCommentBody,
|
|
1410
|
+
isNotificationChannelEnabled,
|
|
1411
|
+
stringifyCommentBody
|
|
1412
|
+
} from "@liveblocks/core";
|
|
1413
|
+
detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
1414
|
+
export {
|
|
1415
|
+
Liveblocks,
|
|
1416
|
+
LiveblocksError,
|
|
1417
|
+
WebhookHandler,
|
|
1418
|
+
getMentionedIdsFromCommentBody,
|
|
1419
|
+
isCustomNotificationEvent,
|
|
1420
|
+
isNotificationChannelEnabled,
|
|
1421
|
+
isTextMentionNotificationEvent,
|
|
1422
|
+
isThreadNotificationEvent,
|
|
1423
|
+
stringifyCommentBody
|
|
1424
|
+
};
|
|
1420
1425
|
//# sourceMappingURL=index.js.map
|