@liveblocks/node 2.17.0 → 2.18.0-yjsfactory

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.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { BaseUserMeta, DU, OptionalTupleUnless, PlainLsonObject, JsonObject, QueryMetadata, ThreadData, CommentData, CommentBody, Patchable, CommentUserReaction, InboxNotificationData, RoomNotificationSettings, KDAD, DAD, LsonObject, ToImmutable, PartialUnless, BaseMetadata, DE, DM, DS } from '@liveblocks/core';
2
- export { CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyLinkElementArgs, CommentBodyMention, CommentBodyMentionElementArgs, CommentBodyParagraph, CommentBodyParagraphElementArgs, CommentBodyText, CommentBodyTextElementArgs, CommentData, CommentUserReaction, IUserInfo, Json, JsonArray, JsonObject, JsonScalar, Lson, LsonObject, PlainLsonObject, ResolveUsersArgs, StringifyCommentBodyElements, StringifyCommentBodyOptions, ThreadData, User, getMentionedIdsFromCommentBody, stringifyCommentBody } from '@liveblocks/core';
1
+ import { BaseUserMeta, DU, OptionalTupleUnless, PlainLsonObject, JsonObject, QueryMetadata, ThreadData, CommentData, CommentBody, Patchable, CommentUserReaction, InboxNotificationData, RoomNotificationSettings, KDAD, DAD, UserNotificationSettings, PartialUserNotificationSettings, LsonObject, ToImmutable, PartialUnless, BaseMetadata, DE, DM, DS, NotificationChannel } from '@liveblocks/core';
2
+ export { CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyLinkElementArgs, CommentBodyMention, CommentBodyMentionElementArgs, CommentBodyParagraph, CommentBodyParagraphElementArgs, CommentBodyText, CommentBodyTextElementArgs, CommentData, CommentUserReaction, IUserInfo, Json, JsonArray, JsonObject, JsonScalar, Lson, LsonObject, PlainLsonObject, ResolveUsersArgs, StringifyCommentBodyElements, StringifyCommentBodyOptions, ThreadData, User, getMentionedIdsFromCommentBody, isNotificationChannelEnabled, stringifyCommentBody } from '@liveblocks/core';
3
3
  import { IncomingHttpHeaders } from 'http';
4
4
 
5
5
  declare const ALL_PERMISSIONS: readonly ["room:write", "room:read", "room:presence:write", "comments:write", "comments:read"];
@@ -755,6 +755,29 @@ declare class Liveblocks {
755
755
  deleteAllInboxNotifications(params: {
756
756
  userId: string;
757
757
  }): Promise<void>;
758
+ /**
759
+ * Get notification settings for a user for a project.
760
+ * @param params.userId The user ID to get the notifications settings for.
761
+ */
762
+ getNotificationSettings(params: {
763
+ userId: string;
764
+ }): Promise<UserNotificationSettings>;
765
+ /**
766
+ * Update the user's notification settings.
767
+ * @param params.userId The user ID to update the notification settings for.
768
+ * @param params.data The new notification settings for the user.
769
+ */
770
+ updateNotificationSettings(params: {
771
+ userId: string;
772
+ data: PartialUserNotificationSettings;
773
+ }): Promise<UserNotificationSettings>;
774
+ /**
775
+ * Delete the user's notification settings
776
+ * @param params.userId The user ID to update the notification settings for.
777
+ */
778
+ deleteNotificationSettings(params: {
779
+ userId: string;
780
+ }): Promise<void>;
758
781
  }
759
782
  declare class LiveblocksError extends Error {
760
783
  status: number;
@@ -1027,7 +1050,7 @@ type ThreadMarkedAsUnresolvedEvent = {
1027
1050
  type ThreadNotificationEvent = {
1028
1051
  type: "notification";
1029
1052
  data: {
1030
- channel: "email";
1053
+ channel: NotificationChannel;
1031
1054
  kind: "thread";
1032
1055
  projectId: string;
1033
1056
  roomId: string;
@@ -1044,7 +1067,7 @@ type ThreadNotificationEvent = {
1044
1067
  type TextMentionNotificationEvent = {
1045
1068
  type: "notification";
1046
1069
  data: {
1047
- channel: "email";
1070
+ channel: NotificationChannel;
1048
1071
  kind: "textMention";
1049
1072
  projectId: string;
1050
1073
  roomId: string;
@@ -1058,11 +1081,10 @@ type TextMentionNotificationEvent = {
1058
1081
  createdAt: string;
1059
1082
  };
1060
1083
  };
1061
- type CustomKind = `$${string}`;
1062
1084
  type CustomNotificationEvent = {
1063
1085
  type: "notification";
1064
1086
  data: {
1065
- channel: "email";
1087
+ channel: NotificationChannel;
1066
1088
  kind: CustomKind;
1067
1089
  projectId: string;
1068
1090
  roomId: string | null;
@@ -1100,6 +1122,17 @@ declare function isThreadNotificationEvent(event: WebhookEvent): event is Thread
1100
1122
  * @returns A boolean type predicate.
1101
1123
  */
1102
1124
  declare function isTextMentionNotificationEvent(event: WebhookEvent): event is TextMentionNotificationEvent;
1125
+ /**
1126
+ * Type guard to check if a webhook event is a `CustomNotificationEvent`
1127
+ *
1128
+ * The check is made against the event type and event data kind.
1129
+ * You should use this guard to safely check the webhook event you received
1130
+ * when you're expecting a `CustomNotificationEvent`.
1131
+ *
1132
+ * @param event The webhook event received after calling `webhookHandler.verifyRequest()`.
1133
+ * @returns A boolean type predicate.
1134
+ */
1135
+ declare function isCustomNotificationEvent(event: WebhookEvent): event is CustomNotificationEvent;
1103
1136
 
1104
1137
  /**
1105
1138
  * @deprecated RoomInfo was renamed to RoomData, to avoid
@@ -1108,4 +1141,4 @@ declare function isTextMentionNotificationEvent(event: WebhookEvent): event is T
1108
1141
  */
1109
1142
  type RoomInfo = RoomData;
1110
1143
 
1111
- export { type CommentCreatedEvent, type CommentDeletedEvent, type CommentEditedEvent, type CommentReactionAdded, type CommentReactionRemoved, type CustomNotificationEvent, Liveblocks, LiveblocksError, type LiveblocksOptions, type NotificationEvent, type RoomAccesses, type RoomCreatedEvent, type RoomData, type RoomDeletedEvent, type RoomInfo, type RoomPermission, type RoomUser, type Schema, type StorageUpdatedEvent, type TextMentionNotificationEvent, type ThreadCreatedEvent, type ThreadDeletedEvent, type ThreadMarkedAsResolvedEvent, type ThreadMarkedAsUnresolvedEvent, type ThreadMetadataUpdatedEvent, type ThreadNotificationEvent, type ThreadParticipants, type UserEnteredEvent, type UserLeftEvent, type WebhookEvent, WebhookHandler, type WebhookRequest, type YDocUpdatedEvent, isTextMentionNotificationEvent, isThreadNotificationEvent };
1144
+ export { type CommentCreatedEvent, type CommentDeletedEvent, type CommentEditedEvent, type CommentReactionAdded, type CommentReactionRemoved, type CustomNotificationEvent, Liveblocks, LiveblocksError, type LiveblocksOptions, type NotificationEvent, type RoomAccesses, type RoomCreatedEvent, type RoomData, type RoomDeletedEvent, type RoomInfo, type RoomPermission, type RoomUser, type Schema, type StorageUpdatedEvent, type TextMentionNotificationEvent, type ThreadCreatedEvent, type ThreadDeletedEvent, type ThreadMarkedAsResolvedEvent, type ThreadMarkedAsUnresolvedEvent, type ThreadMetadataUpdatedEvent, type ThreadNotificationEvent, type ThreadParticipants, type UserEnteredEvent, type UserLeftEvent, type WebhookEvent, WebhookHandler, type WebhookRequest, type YDocUpdatedEvent, isCustomNotificationEvent, isTextMentionNotificationEvent, isThreadNotificationEvent };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { BaseUserMeta, DU, OptionalTupleUnless, PlainLsonObject, JsonObject, QueryMetadata, ThreadData, CommentData, CommentBody, Patchable, CommentUserReaction, InboxNotificationData, RoomNotificationSettings, KDAD, DAD, LsonObject, ToImmutable, PartialUnless, BaseMetadata, DE, DM, DS } from '@liveblocks/core';
2
- export { CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyLinkElementArgs, CommentBodyMention, CommentBodyMentionElementArgs, CommentBodyParagraph, CommentBodyParagraphElementArgs, CommentBodyText, CommentBodyTextElementArgs, CommentData, CommentUserReaction, IUserInfo, Json, JsonArray, JsonObject, JsonScalar, Lson, LsonObject, PlainLsonObject, ResolveUsersArgs, StringifyCommentBodyElements, StringifyCommentBodyOptions, ThreadData, User, getMentionedIdsFromCommentBody, stringifyCommentBody } from '@liveblocks/core';
1
+ import { BaseUserMeta, DU, OptionalTupleUnless, PlainLsonObject, JsonObject, QueryMetadata, ThreadData, CommentData, CommentBody, Patchable, CommentUserReaction, InboxNotificationData, RoomNotificationSettings, KDAD, DAD, UserNotificationSettings, PartialUserNotificationSettings, LsonObject, ToImmutable, PartialUnless, BaseMetadata, DE, DM, DS, NotificationChannel } from '@liveblocks/core';
2
+ export { CommentBody, CommentBodyBlockElement, CommentBodyElement, CommentBodyInlineElement, CommentBodyLink, CommentBodyLinkElementArgs, CommentBodyMention, CommentBodyMentionElementArgs, CommentBodyParagraph, CommentBodyParagraphElementArgs, CommentBodyText, CommentBodyTextElementArgs, CommentData, CommentUserReaction, IUserInfo, Json, JsonArray, JsonObject, JsonScalar, Lson, LsonObject, PlainLsonObject, ResolveUsersArgs, StringifyCommentBodyElements, StringifyCommentBodyOptions, ThreadData, User, getMentionedIdsFromCommentBody, isNotificationChannelEnabled, stringifyCommentBody } from '@liveblocks/core';
3
3
  import { IncomingHttpHeaders } from 'http';
4
4
 
5
5
  declare const ALL_PERMISSIONS: readonly ["room:write", "room:read", "room:presence:write", "comments:write", "comments:read"];
@@ -755,6 +755,29 @@ declare class Liveblocks {
755
755
  deleteAllInboxNotifications(params: {
756
756
  userId: string;
757
757
  }): Promise<void>;
758
+ /**
759
+ * Get notification settings for a user for a project.
760
+ * @param params.userId The user ID to get the notifications settings for.
761
+ */
762
+ getNotificationSettings(params: {
763
+ userId: string;
764
+ }): Promise<UserNotificationSettings>;
765
+ /**
766
+ * Update the user's notification settings.
767
+ * @param params.userId The user ID to update the notification settings for.
768
+ * @param params.data The new notification settings for the user.
769
+ */
770
+ updateNotificationSettings(params: {
771
+ userId: string;
772
+ data: PartialUserNotificationSettings;
773
+ }): Promise<UserNotificationSettings>;
774
+ /**
775
+ * Delete the user's notification settings
776
+ * @param params.userId The user ID to update the notification settings for.
777
+ */
778
+ deleteNotificationSettings(params: {
779
+ userId: string;
780
+ }): Promise<void>;
758
781
  }
759
782
  declare class LiveblocksError extends Error {
760
783
  status: number;
@@ -1027,7 +1050,7 @@ type ThreadMarkedAsUnresolvedEvent = {
1027
1050
  type ThreadNotificationEvent = {
1028
1051
  type: "notification";
1029
1052
  data: {
1030
- channel: "email";
1053
+ channel: NotificationChannel;
1031
1054
  kind: "thread";
1032
1055
  projectId: string;
1033
1056
  roomId: string;
@@ -1044,7 +1067,7 @@ type ThreadNotificationEvent = {
1044
1067
  type TextMentionNotificationEvent = {
1045
1068
  type: "notification";
1046
1069
  data: {
1047
- channel: "email";
1070
+ channel: NotificationChannel;
1048
1071
  kind: "textMention";
1049
1072
  projectId: string;
1050
1073
  roomId: string;
@@ -1058,11 +1081,10 @@ type TextMentionNotificationEvent = {
1058
1081
  createdAt: string;
1059
1082
  };
1060
1083
  };
1061
- type CustomKind = `$${string}`;
1062
1084
  type CustomNotificationEvent = {
1063
1085
  type: "notification";
1064
1086
  data: {
1065
- channel: "email";
1087
+ channel: NotificationChannel;
1066
1088
  kind: CustomKind;
1067
1089
  projectId: string;
1068
1090
  roomId: string | null;
@@ -1100,6 +1122,17 @@ declare function isThreadNotificationEvent(event: WebhookEvent): event is Thread
1100
1122
  * @returns A boolean type predicate.
1101
1123
  */
1102
1124
  declare function isTextMentionNotificationEvent(event: WebhookEvent): event is TextMentionNotificationEvent;
1125
+ /**
1126
+ * Type guard to check if a webhook event is a `CustomNotificationEvent`
1127
+ *
1128
+ * The check is made against the event type and event data kind.
1129
+ * You should use this guard to safely check the webhook event you received
1130
+ * when you're expecting a `CustomNotificationEvent`.
1131
+ *
1132
+ * @param event The webhook event received after calling `webhookHandler.verifyRequest()`.
1133
+ * @returns A boolean type predicate.
1134
+ */
1135
+ declare function isCustomNotificationEvent(event: WebhookEvent): event is CustomNotificationEvent;
1103
1136
 
1104
1137
  /**
1105
1138
  * @deprecated RoomInfo was renamed to RoomData, to avoid
@@ -1108,4 +1141,4 @@ declare function isTextMentionNotificationEvent(event: WebhookEvent): event is T
1108
1141
  */
1109
1142
  type RoomInfo = RoomData;
1110
1143
 
1111
- export { type CommentCreatedEvent, type CommentDeletedEvent, type CommentEditedEvent, type CommentReactionAdded, type CommentReactionRemoved, type CustomNotificationEvent, Liveblocks, LiveblocksError, type LiveblocksOptions, type NotificationEvent, type RoomAccesses, type RoomCreatedEvent, type RoomData, type RoomDeletedEvent, type RoomInfo, type RoomPermission, type RoomUser, type Schema, type StorageUpdatedEvent, type TextMentionNotificationEvent, type ThreadCreatedEvent, type ThreadDeletedEvent, type ThreadMarkedAsResolvedEvent, type ThreadMarkedAsUnresolvedEvent, type ThreadMetadataUpdatedEvent, type ThreadNotificationEvent, type ThreadParticipants, type UserEnteredEvent, type UserLeftEvent, type WebhookEvent, WebhookHandler, type WebhookRequest, type YDocUpdatedEvent, isTextMentionNotificationEvent, isThreadNotificationEvent };
1144
+ export { type CommentCreatedEvent, type CommentDeletedEvent, type CommentEditedEvent, type CommentReactionAdded, type CommentReactionRemoved, type CustomNotificationEvent, Liveblocks, LiveblocksError, type LiveblocksOptions, type NotificationEvent, type RoomAccesses, type RoomCreatedEvent, type RoomData, type RoomDeletedEvent, type RoomInfo, type RoomPermission, type RoomUser, type Schema, type StorageUpdatedEvent, type TextMentionNotificationEvent, type ThreadCreatedEvent, type ThreadDeletedEvent, type ThreadMarkedAsResolvedEvent, type ThreadMarkedAsUnresolvedEvent, type ThreadMetadataUpdatedEvent, type ThreadNotificationEvent, type ThreadParticipants, type UserEnteredEvent, type UserLeftEvent, type WebhookEvent, WebhookHandler, type WebhookRequest, type YDocUpdatedEvent, isCustomNotificationEvent, isTextMentionNotificationEvent, isThreadNotificationEvent };
package/dist/index.js 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.17.0";
6
+ var PKG_VERSION = "2.18.0-yjsfactory";
7
7
  var PKG_FORMAT = "cjs";
8
8
 
9
9
  // src/client.ts
@@ -1201,6 +1201,50 @@ var Liveblocks = class {
1201
1201
  throw new LiveblocksError(res.status, text);
1202
1202
  }
1203
1203
  }
1204
+ /**
1205
+ * Get notification settings for a user for a project.
1206
+ * @param params.userId The user ID to get the notifications settings for.
1207
+ */
1208
+ async getNotificationSettings(params) {
1209
+ const { userId } = params;
1210
+ const res = await this.#get(_core.url`/v2/users/${userId}/notification-settings`);
1211
+ if (!res.ok) {
1212
+ const text = await res.text();
1213
+ throw new LiveblocksError(res.status, text);
1214
+ }
1215
+ return await res.json();
1216
+ }
1217
+ /**
1218
+ * Update the user's notification settings.
1219
+ * @param params.userId The user ID to update the notification settings for.
1220
+ * @param params.data The new notification settings for the user.
1221
+ */
1222
+ async updateNotificationSettings(params) {
1223
+ const { userId, data } = params;
1224
+ const res = await this.#post(
1225
+ _core.url`/v2/users/${userId}/notification-settings`,
1226
+ data
1227
+ );
1228
+ if (!res.ok) {
1229
+ const text = await res.text();
1230
+ throw new LiveblocksError(res.status, text);
1231
+ }
1232
+ return await res.json();
1233
+ }
1234
+ /**
1235
+ * Delete the user's notification settings
1236
+ * @param params.userId The user ID to update the notification settings for.
1237
+ */
1238
+ async deleteNotificationSettings(params) {
1239
+ const { userId } = params;
1240
+ const res = await this.#delete(
1241
+ _core.url`/v2/users/${userId}/notification-settings`
1242
+ );
1243
+ if (!res.ok) {
1244
+ const text = await res.text();
1245
+ throw new LiveblocksError(res.status, text);
1246
+ }
1247
+ }
1204
1248
  };
1205
1249
  var LiveblocksError = class extends Error {
1206
1250
 
@@ -1325,11 +1369,11 @@ var WebhookHandler = class _WebhookHandler {
1325
1369
  ].includes(event.type)) {
1326
1370
  if (event.type === "notification") {
1327
1371
  const notification = event;
1328
- if (notification.data.kind === "thread" || notification.data.kind === "textMention" || notification.data.kind.startsWith("$")) {
1372
+ if (notification.data.kind === "thread" || notification.data.kind === "textMention" || isCustomKind(notification.data.kind)) {
1329
1373
  return;
1330
1374
  } else {
1331
1375
  throw new Error(
1332
- `Unknown notification kind: ${notification.data.kind}`
1376
+ `Unknown notification kind: ${JSON.stringify(notification.data.kind)}`
1333
1377
  );
1334
1378
  }
1335
1379
  }
@@ -1342,18 +1386,25 @@ var WebhookHandler = class _WebhookHandler {
1342
1386
  };
1343
1387
  var WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60;
1344
1388
  var isNotUndefined = (value) => value !== void 0;
1389
+ var isCustomKind = (value) => {
1390
+ return isString(value) && value.startsWith("$");
1391
+ };
1345
1392
  function isThreadNotificationEvent(event) {
1346
1393
  return event.type === "notification" && event.data.kind === "thread";
1347
1394
  }
1348
1395
  function isTextMentionNotificationEvent(event) {
1349
1396
  return event.type === "notification" && event.data.kind === "textMention";
1350
1397
  }
1398
+ function isCustomNotificationEvent(event) {
1399
+ return event.type === "notification" && isCustomKind(event.data.kind);
1400
+ }
1351
1401
 
1352
1402
  // src/index.ts
1353
1403
 
1354
1404
 
1355
1405
 
1356
1406
 
1407
+
1357
1408
  _core.detectDupes.call(void 0, PKG_NAME, PKG_VERSION, PKG_FORMAT);
1358
1409
 
1359
1410
 
@@ -1363,5 +1414,7 @@ _core.detectDupes.call(void 0, PKG_NAME, PKG_VERSION, PKG_FORMAT);
1363
1414
 
1364
1415
 
1365
1416
 
1366
- exports.Liveblocks = Liveblocks; exports.LiveblocksError = LiveblocksError; exports.WebhookHandler = WebhookHandler; exports.getMentionedIdsFromCommentBody = _core.getMentionedIdsFromCommentBody; exports.isTextMentionNotificationEvent = isTextMentionNotificationEvent; exports.isThreadNotificationEvent = isThreadNotificationEvent; exports.stringifyCommentBody = _core.stringifyCommentBody;
1417
+
1418
+
1419
+ exports.Liveblocks = Liveblocks; exports.LiveblocksError = LiveblocksError; exports.WebhookHandler = WebhookHandler; exports.getMentionedIdsFromCommentBody = _core.getMentionedIdsFromCommentBody; exports.isCustomNotificationEvent = isCustomNotificationEvent; exports.isNotificationChannelEnabled = _core.isNotificationChannelEnabled; exports.isTextMentionNotificationEvent = isTextMentionNotificationEvent; exports.isThreadNotificationEvent = isThreadNotificationEvent; exports.stringifyCommentBody = _core.stringifyCommentBody;
1367
1420
  //# sourceMappingURL=index.js.map