@liveblocks/core 2.19.0 → 2.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -6,7 +6,7 @@ var __export = (target, all) => {
6
6
 
7
7
  // src/version.ts
8
8
  var PKG_NAME = "@liveblocks/core";
9
- var PKG_VERSION = "2.19.0";
9
+ var PKG_VERSION = "2.20.0";
10
10
  var PKG_FORMAT = "cjs";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -187,6 +187,12 @@ function keys(obj) {
187
187
  function values(obj) {
188
188
  return Object.values(obj);
189
189
  }
190
+ function create(obj, descriptors) {
191
+ if (typeof descriptors !== "undefined") {
192
+ return Object.create(obj, descriptors);
193
+ }
194
+ return Object.create(obj);
195
+ }
190
196
  function mapValues(obj, mapFn) {
191
197
  const result = {};
192
198
  for (const pair of Object.entries(obj)) {
@@ -3597,6 +3603,71 @@ function unlinkDevTools(roomId) {
3597
3603
  });
3598
3604
  }
3599
3605
 
3606
+ // src/protocol/UserNotificationSettings.ts
3607
+ var kPlain = Symbol("user-notification-settings-plain");
3608
+ function createUserNotificationSettings(plain) {
3609
+ const channels = [
3610
+ "email",
3611
+ "slack",
3612
+ "teams",
3613
+ "webPush"
3614
+ ];
3615
+ const descriptors = {
3616
+ [kPlain]: {
3617
+ value: plain,
3618
+ enumerable: false
3619
+ }
3620
+ };
3621
+ for (const channel of channels) {
3622
+ descriptors[channel] = {
3623
+ enumerable: true,
3624
+ /**
3625
+ * In the TypeScript standard library definitions, the built-in interface for a property descriptor
3626
+ * does not include a specialized type for the “this” context in the getter or setter functions.
3627
+ * As a result, both the ⁠get and ⁠set methods implicitly have ⁠this: any.
3628
+ * The reason is that property descriptors in JavaScript are used across various objects with
3629
+ * no enforced shape for ⁠this. And so the standard library definitions have to remain as broad as possible
3630
+ * to support any valid JavaScript usage (e.g `Object.defineProperty`).
3631
+ *
3632
+ * So we can safely tells that this getter is typed as `this: UserNotificationSettings` because we're
3633
+ * creating a well known shaped object → `UserNotificationSettings`.
3634
+ */
3635
+ get() {
3636
+ const value = this[kPlain][channel];
3637
+ if (typeof value === "undefined") {
3638
+ error2(
3639
+ `In order to use the '${channel}' channel, please set up your project first. For more information: https://liveblocks.io/docs/errors/enable-a-notification-channel`
3640
+ );
3641
+ return null;
3642
+ }
3643
+ return value;
3644
+ }
3645
+ };
3646
+ }
3647
+ return create(null, descriptors);
3648
+ }
3649
+ function patchUserNotificationSettings(existing, patch) {
3650
+ const outcoming = createUserNotificationSettings({
3651
+ ...existing[kPlain]
3652
+ });
3653
+ for (const channel of keys(patch)) {
3654
+ const updates = patch[channel];
3655
+ if (updates !== void 0) {
3656
+ const kindUpdates = Object.fromEntries(
3657
+ entries(updates).filter(([, value]) => value !== void 0)
3658
+ );
3659
+ outcoming[kPlain][channel] = {
3660
+ ...outcoming[kPlain][channel],
3661
+ ...kindUpdates
3662
+ };
3663
+ }
3664
+ }
3665
+ return outcoming;
3666
+ }
3667
+ function isNotificationChannelEnabled(settings) {
3668
+ return settings !== null ? values(settings).every((enabled) => enabled === true) : false;
3669
+ }
3670
+
3600
3671
  // src/lib/position.ts
3601
3672
  var MIN_CODE = 32;
3602
3673
  var MAX_CODE = 126;
@@ -8189,6 +8260,16 @@ function createClient(options) {
8189
8260
  const win = typeof window !== "undefined" ? window : void 0;
8190
8261
  _optionalChain([win, 'optionalAccess', _184 => _184.addEventListener, 'call', _185 => _185("beforeunload", maybePreventClose)]);
8191
8262
  }
8263
+ async function getNotificationSettings(options2) {
8264
+ const plainSettings = await httpClient.getUserNotificationSettings(options2);
8265
+ const settings = createUserNotificationSettings(plainSettings);
8266
+ return settings;
8267
+ }
8268
+ async function updateNotificationSettings(settings) {
8269
+ const plainSettings = await httpClient.updateUserNotificationSettings(settings);
8270
+ const settingsObject = createUserNotificationSettings(plainSettings);
8271
+ return settingsObject;
8272
+ }
8192
8273
  const client = Object.defineProperty(
8193
8274
  {
8194
8275
  enterRoom,
@@ -8202,9 +8283,9 @@ function createClient(options) {
8202
8283
  markInboxNotificationAsRead: httpClient.markInboxNotificationAsRead,
8203
8284
  deleteAllInboxNotifications: httpClient.deleteAllInboxNotifications,
8204
8285
  deleteInboxNotification: httpClient.deleteInboxNotification,
8205
- // Public channel notification settings API
8206
- getNotificationSettings: httpClient.getUserNotificationSettings,
8207
- updateNotificationSettings: httpClient.updateUserNotificationSettings,
8286
+ // Public user notification settings API
8287
+ getNotificationSettings,
8288
+ updateNotificationSettings,
8208
8289
  // Advanced resolvers APIs
8209
8290
  resolvers: {
8210
8291
  invalidateUsers: invalidateResolvedUsers,
@@ -9194,11 +9275,6 @@ var SortedList = class _SortedList {
9194
9275
  }
9195
9276
  };
9196
9277
 
9197
- // src/protocol/UserNotificationSettings.ts
9198
- function isNotificationChannelEnabled(settings) {
9199
- return values(settings).every((enabled) => enabled === true);
9200
- }
9201
-
9202
9278
  // src/types/Others.ts
9203
9279
  var TextEditorType = /* @__PURE__ */ ((TextEditorType2) => {
9204
9280
  TextEditorType2["Lexical"] = "lexical";
@@ -9299,5 +9375,7 @@ var NotificationsApiError = HttpError;
9299
9375
 
9300
9376
 
9301
9377
 
9302
- exports.ClientMsgCode = ClientMsgCode; exports.CommentsApiError = CommentsApiError; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.DerivedSignal = DerivedSignal; exports.HttpError = HttpError; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.LiveblocksError = LiveblocksError; exports.MutableSignal = MutableSignal; exports.NotificationsApiError = NotificationsApiError; exports.OpCode = OpCode; exports.Permission = Permission; exports.Promise_withResolvers = Promise_withResolvers; exports.ServerMsgCode = ServerMsgCode; exports.Signal = Signal; exports.SortedList = SortedList; exports.TextEditorType = TextEditorType; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.ackOp = ackOp; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.autoRetry = autoRetry; exports.b64decode = b64decode; exports.batch = batch; exports.chunk = chunk; exports.cloneLson = cloneLson; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToThreadData = convertToThreadData; exports.createClient = createClient; exports.createCommentAttachmentId = createCommentAttachmentId; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createThreadId = createThreadId; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.entries = entries; exports.errorIf = errorIf; exports.freeze = freeze; exports.generateCommentUrl = generateCommentUrl; exports.getMentionedIdsFromCommentBody = getMentionedIdsFromCommentBody; exports.html = html; exports.htmlSafe = htmlSafe; exports.isChildCrdt = isChildCrdt; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isNotificationChannelEnabled = isNotificationChannelEnabled; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.isStartsWithOperator = isStartsWithOperator; exports.kInternal = kInternal; exports.keys = keys; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.raise = raise; exports.resolveUsersInCommentBody = resolveUsersInCommentBody; exports.shallow = shallow; exports.stableStringify = stableStringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toAbsoluteUrl = toAbsoluteUrl; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.url = url; exports.urljoin = urljoin; exports.wait = wait; exports.withTimeout = withTimeout;
9378
+
9379
+
9380
+ exports.ClientMsgCode = ClientMsgCode; exports.CommentsApiError = CommentsApiError; exports.CrdtType = CrdtType; exports.DefaultMap = DefaultMap; exports.DerivedSignal = DerivedSignal; exports.HttpError = HttpError; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.LiveblocksError = LiveblocksError; exports.MutableSignal = MutableSignal; exports.NotificationsApiError = NotificationsApiError; exports.OpCode = OpCode; exports.Permission = Permission; exports.Promise_withResolvers = Promise_withResolvers; exports.ServerMsgCode = ServerMsgCode; exports.Signal = Signal; exports.SortedList = SortedList; exports.TextEditorType = TextEditorType; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.ackOp = ackOp; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.autoRetry = autoRetry; exports.b64decode = b64decode; exports.batch = batch; exports.chunk = chunk; exports.cloneLson = cloneLson; exports.compactObject = compactObject; exports.console = fancy_console_exports; exports.convertToCommentData = convertToCommentData; exports.convertToCommentUserReaction = convertToCommentUserReaction; exports.convertToInboxNotificationData = convertToInboxNotificationData; exports.convertToThreadData = convertToThreadData; exports.createClient = createClient; exports.createCommentAttachmentId = createCommentAttachmentId; exports.createCommentId = createCommentId; exports.createInboxNotificationId = createInboxNotificationId; exports.createThreadId = createThreadId; exports.createUserNotificationSettings = createUserNotificationSettings; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.entries = entries; exports.errorIf = errorIf; exports.freeze = freeze; exports.generateCommentUrl = generateCommentUrl; exports.getMentionedIdsFromCommentBody = getMentionedIdsFromCommentBody; exports.html = html; exports.htmlSafe = htmlSafe; exports.isChildCrdt = isChildCrdt; exports.isCommentBodyLink = isCommentBodyLink; exports.isCommentBodyMention = isCommentBodyMention; exports.isCommentBodyText = isCommentBodyText; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isNotificationChannelEnabled = isNotificationChannelEnabled; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.isStartsWithOperator = isStartsWithOperator; exports.kInternal = kInternal; exports.keys = keys; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.mapValues = mapValues; exports.memoizeOnSuccess = memoizeOnSuccess; exports.nanoid = nanoid; exports.nn = nn; exports.objectToQuery = objectToQuery; exports.patchLiveObjectKey = patchLiveObjectKey; exports.patchUserNotificationSettings = patchUserNotificationSettings; exports.raise = raise; exports.resolveUsersInCommentBody = resolveUsersInCommentBody; exports.shallow = shallow; exports.stableStringify = stableStringify; exports.stringifyCommentBody = stringifyCommentBody; exports.throwUsageError = throwUsageError; exports.toAbsoluteUrl = toAbsoluteUrl; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.url = url; exports.urljoin = urljoin; exports.wait = wait; exports.withTimeout = withTimeout;
9303
9381
  //# sourceMappingURL=index.cjs.map