@liveblocks/node 1.11.3 → 1.12.0-lexical3

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 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 = "1.11.3";
6
+ var PKG_VERSION = "1.12.0-lexical3";
7
7
  var PKG_FORMAT = "esm";
8
8
 
9
9
  // src/utils.ts
@@ -112,7 +112,9 @@ function buildLiveblocksAuthorizeEndpoint(options, roomId) {
112
112
  import {
113
113
  convertToCommentData,
114
114
  convertToCommentUserReaction,
115
- convertToThreadData
115
+ convertToInboxNotificationData,
116
+ convertToThreadData,
117
+ objectToQuery
116
118
  } from "@liveblocks/core";
117
119
 
118
120
  // src/Session.ts
@@ -405,10 +407,17 @@ var Liveblocks = class {
405
407
  * @param params.userId (optional) A filter on users accesses.
406
408
  * @param params.metadata (optional) A filter on metadata. Multiple metadata keys can be used to filter rooms.
407
409
  * @param params.groupIds (optional) A filter on groups accesses. Multiple groups can be used.
410
+ * @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.
408
411
  * @returns A list of rooms.
409
412
  */
410
413
  async getRooms(params = {}) {
411
414
  const path = url`/v2/rooms`;
415
+ let query;
416
+ if (typeof params.query === "string") {
417
+ query = params.query;
418
+ } else if (typeof params.query === "object") {
419
+ query = objectToQuery(params.query);
420
+ }
412
421
  const queryParams = {
413
422
  limit: params.limit,
414
423
  startingAfter: params.startingAfter,
@@ -416,11 +425,12 @@ var Liveblocks = class {
416
425
  groupIds: params.groupIds ? params.groupIds.join(",") : void 0,
417
426
  // "Flatten" {metadata: {foo: "bar"}} to {"metadata.foo": "bar"}
418
427
  ...Object.fromEntries(
419
- Object.entries(params.metadata ?? {}).map(([key, val]) => {
420
- const value = Array.isArray(val) ? val.join(",") : val;
421
- return [`metadata.${key}`, value];
422
- })
423
- )
428
+ Object.entries(params.metadata ?? {}).map(([key, val]) => [
429
+ `metadata.${key}`,
430
+ val
431
+ ])
432
+ ),
433
+ query
424
434
  };
425
435
  const res = await this.get(path, queryParams);
426
436
  if (!res.ok) {
@@ -791,11 +801,20 @@ var Liveblocks = class {
791
801
  * Gets all the threads in a room.
792
802
  *
793
803
  * @param params.roomId The room ID to get the threads from.
804
+ * @param params.query The query to filter threads by. It is based on our query language and can filter by metadata.
794
805
  * @returns A list of threads.
795
806
  */
796
807
  async getThreads(params) {
797
808
  const { roomId } = params;
798
- const res = await this.get(url`/v2/rooms/${roomId}/threads`);
809
+ let query;
810
+ if (typeof params.query === "string") {
811
+ query = params.query;
812
+ } else if (typeof params.query === "object") {
813
+ query = objectToQuery(params.query);
814
+ }
815
+ const res = await this.get(url`/v2/rooms/${roomId}/threads`, {
816
+ query
817
+ });
799
818
  if (!res.ok) {
800
819
  const text = await res.text();
801
820
  throw new LiveblocksError(res.status, text);
@@ -819,9 +838,7 @@ var Liveblocks = class {
819
838
  const text = await res.text();
820
839
  throw new LiveblocksError(res.status, text);
821
840
  }
822
- return convertToThreadData(
823
- await res.json()
824
- );
841
+ return convertToThreadData(await res.json());
825
842
  }
826
843
  /**
827
844
  * Gets a thread's participants.
@@ -951,9 +968,7 @@ var Liveblocks = class {
951
968
  const text = await res.text();
952
969
  throw new LiveblocksError(res.status, text);
953
970
  }
954
- return convertToThreadData(
955
- await res.json()
956
- );
971
+ return convertToThreadData(await res.json());
957
972
  }
958
973
  /**
959
974
  * Updates the metadata of the specified thread in a room.
@@ -1042,12 +1057,9 @@ var Liveblocks = class {
1042
1057
  const text = await res.text();
1043
1058
  throw new LiveblocksError(res.status, text);
1044
1059
  }
1045
- const data = await res.json();
1046
- return {
1047
- ...data,
1048
- notifiedAt: new Date(data.notifiedAt),
1049
- readAt: data.readAt ? new Date(data.readAt) : null
1050
- };
1060
+ return convertToInboxNotificationData(
1061
+ await res.json()
1062
+ );
1051
1063
  }
1052
1064
  /**
1053
1065
  * Gets the user's room notification settings.
@@ -1122,6 +1134,13 @@ var Liveblocks = class {
1122
1134
  lastConnectionAt: data.lastConnectionAt ? new Date(data.lastConnectionAt) : void 0
1123
1135
  };
1124
1136
  }
1137
+ async triggerInboxNotification(params) {
1138
+ const res = await this.post(url`/v2/inbox-notifications/trigger`, params);
1139
+ if (!res.ok) {
1140
+ const text = await res.text();
1141
+ throw new LiveblocksError(res.status, text);
1142
+ }
1143
+ }
1125
1144
  };
1126
1145
  var LiveblocksError = class extends Error {
1127
1146
  constructor(status, message = "") {
@@ -1239,8 +1258,19 @@ var _WebhookHandler = class _WebhookHandler {
1239
1258
  "threadCreated",
1240
1259
  "ydocUpdated",
1241
1260
  "notification"
1242
- ].includes(event.type))
1261
+ ].includes(event.type)) {
1262
+ if (event.type === "notification") {
1263
+ const notification = event;
1264
+ if (notification.data.kind === "thread" || notification.data.kind === "textMention" || notification.data.kind.startsWith("$")) {
1265
+ return;
1266
+ } else {
1267
+ throw new Error(
1268
+ `Unknown notification kind: ${notification.data.kind}`
1269
+ );
1270
+ }
1271
+ }
1243
1272
  return;
1273
+ }
1244
1274
  throw new Error(
1245
1275
  "Unknown event type, please upgrade to a higher version of @liveblocks/node"
1246
1276
  );