@liveblocks/node 3.20.0-rc1 → 3.20.1

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
@@ -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 = "3.20.0-rc1";
6
+ var PKG_VERSION = "3.20.1";
7
7
  var PKG_FORMAT = "cjs";
8
8
 
9
9
  // src/client.ts
@@ -24,6 +24,9 @@ var PKG_FORMAT = "cjs";
24
24
 
25
25
 
26
26
 
27
+
28
+
29
+
27
30
 
28
31
 
29
32
 
@@ -160,29 +163,18 @@ function normalizeStatusCode(statusCode) {
160
163
  }
161
164
 
162
165
  // src/Session.ts
163
- var ALL_PERMISSIONS = Object.freeze([
164
- "room:write",
165
- "room:read",
166
- "room:presence:write",
167
- "comments:write",
168
- "comments:read",
169
- "feeds:write"
170
- ]);
171
- function isPermission(value) {
172
- return ALL_PERMISSIONS.includes(value);
173
- }
174
166
  var MAX_PERMS_PER_SET = 10;
175
- var READ_ACCESS = Object.freeze([
176
- "room:read",
177
- "room:presence:write",
178
- // TODO: Remove once backend no longer requires this
179
- "comments:read"
180
- // TODO: Remove — implied by room:read
181
- ]);
182
- var FULL_ACCESS = Object.freeze(["room:write"]);
167
+ var READ_ACCESS = Object.freeze([_core.Permission.Read]);
168
+ var FULL_ACCESS = Object.freeze([_core.Permission.Write]);
183
169
  var roomPatternRegex = /^([*]|[^*]{1,128}[*]?)$/;
184
170
  var Session = (_class = class {
171
+ /**
172
+ * @deprecated Use `["*:write"]` instead.
173
+ */
185
174
  __init() {this.FULL_ACCESS = FULL_ACCESS}
175
+ /**
176
+ * @deprecated Use `["*:read"]` instead.
177
+ */
186
178
  __init2() {this.READ_ACCESS = READ_ACCESS}
187
179
  #postFn;
188
180
  #userId;
@@ -229,11 +221,9 @@ var Session = (_class = class {
229
221
  if (newPerms.length === 0) {
230
222
  throw new Error("Permission list cannot be empty");
231
223
  }
224
+ const permissions = _core.normalizeRoomPermissions.call(void 0, newPerms);
232
225
  const existingPerms = this.#getOrCreate(roomIdOrPattern);
233
- for (const perm of newPerms) {
234
- if (!isPermission(perm)) {
235
- throw new Error(`Not a valid permission: ${perm}`);
236
- }
226
+ for (const perm of permissions) {
237
227
  existingPerms.add(perm);
238
228
  }
239
229
  return this;
@@ -308,6 +298,22 @@ function inflateRoomData(room) {
308
298
  lastConnectionAt
309
299
  };
310
300
  }
301
+ function normalizeCreateRoomOptions(options) {
302
+ return {
303
+ ...options,
304
+ defaultAccesses: _core.normalizeRoomPermissions.call(void 0, options.defaultAccesses),
305
+ groupsAccesses: _core.normalizeRoomAccesses.call(void 0, options.groupsAccesses),
306
+ usersAccesses: _core.normalizeRoomAccesses.call(void 0, options.usersAccesses)
307
+ };
308
+ }
309
+ function normalizeUpdateRoomOptions(options) {
310
+ return {
311
+ ...options,
312
+ defaultAccesses: options.defaultAccesses === void 0 || options.defaultAccesses === null ? options.defaultAccesses : _core.normalizeRoomPermissions.call(void 0, options.defaultAccesses),
313
+ groupsAccesses: _core.normalizeUpdateRoomAccesses.call(void 0, options.groupsAccesses),
314
+ usersAccesses: _core.normalizeUpdateRoomAccesses.call(void 0, options.usersAccesses)
315
+ };
316
+ }
311
317
  function inflateAiCopilot(copilot) {
312
318
  return {
313
319
  ...copilot,
@@ -614,6 +620,7 @@ var Liveblocks = class {
614
620
  * @returns The created room.
615
621
  */
616
622
  async createRoom(roomId, params, options) {
623
+ const normalizedParams = normalizeCreateRoomOptions(params);
617
624
  const {
618
625
  defaultAccesses,
619
626
  groupsAccesses,
@@ -621,7 +628,7 @@ var Liveblocks = class {
621
628
  metadata,
622
629
  tenantId,
623
630
  organizationId
624
- } = params;
631
+ } = normalizedParams;
625
632
  const body = {
626
633
  id: roomId,
627
634
  defaultAccesses,
@@ -674,9 +681,13 @@ var Liveblocks = class {
674
681
  * @returns The room.
675
682
  */
676
683
  async upsertRoom(roomId, params, options) {
684
+ const body = {
685
+ update: normalizeUpdateRoomOptions(params.update),
686
+ create: params.create === void 0 ? void 0 : normalizeCreateRoomOptions(params.create)
687
+ };
677
688
  const res = await this.#post(
678
689
  _core.url`/v2/rooms/${roomId}/upsert`,
679
- params,
690
+ body,
680
691
  options
681
692
  );
682
693
  if (!res.ok) {
@@ -711,7 +722,7 @@ var Liveblocks = class {
711
722
  * @returns The updated room.
712
723
  */
713
724
  async updateRoom(roomId, params, options) {
714
- const { defaultAccesses, groupsAccesses, usersAccesses, metadata } = params;
725
+ const { defaultAccesses, groupsAccesses, usersAccesses, metadata } = normalizeUpdateRoomOptions(params);
715
726
  const res = await this.#post(
716
727
  _core.url`/v2/rooms/${roomId}`,
717
728
  {