@liveblocks/node 3.20.0-exp6 → 3.20.0-perm1
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 +40 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -28
- package/dist/index.d.ts +14 -28
- package/dist/index.js +41 -28
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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-
|
|
6
|
+
var PKG_VERSION = "3.20.0-perm1";
|
|
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
|
|
|
@@ -108,6 +111,11 @@ function xwarn(resp, method, path) {
|
|
|
108
111
|
// src/Session.ts
|
|
109
112
|
|
|
110
113
|
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
111
119
|
// src/utils.ts
|
|
112
120
|
var DEFAULT_BASE_URL = "https://api.liveblocks.io";
|
|
113
121
|
var VALID_KEY_CHARS_REGEX = /^[\w-]+$/;
|
|
@@ -160,26 +168,9 @@ function normalizeStatusCode(statusCode) {
|
|
|
160
168
|
}
|
|
161
169
|
|
|
162
170
|
// 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
171
|
var MAX_PERMS_PER_SET = 10;
|
|
175
|
-
var READ_ACCESS = Object.freeze([
|
|
176
|
-
|
|
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"]);
|
|
172
|
+
var READ_ACCESS = Object.freeze([_core.Permission.RoomRead]);
|
|
173
|
+
var FULL_ACCESS = Object.freeze([_core.Permission.RoomWrite]);
|
|
183
174
|
var roomPatternRegex = /^([*]|[^*]{1,128}[*]?)$/;
|
|
184
175
|
var Session = (_class = class {
|
|
185
176
|
__init() {this.FULL_ACCESS = FULL_ACCESS}
|
|
@@ -226,13 +217,14 @@ var Session = (_class = class {
|
|
|
226
217
|
if (!roomPatternRegex.test(roomIdOrPattern)) {
|
|
227
218
|
throw new Error("Invalid room name or pattern");
|
|
228
219
|
}
|
|
229
|
-
|
|
220
|
+
const normalizedPermissions = _core.normalizeRoomPermissionInput.call(void 0, newPerms);
|
|
221
|
+
if (normalizedPermissions.length === 0) {
|
|
230
222
|
throw new Error("Permission list cannot be empty");
|
|
231
223
|
}
|
|
232
224
|
const existingPerms = this.#getOrCreate(roomIdOrPattern);
|
|
233
|
-
for (const perm of
|
|
234
|
-
|
|
235
|
-
|
|
225
|
+
for (const perm of normalizedPermissions) {
|
|
226
|
+
for (const conflictingPerm of _core.getRoomPermissionConflicts.call(void 0, perm)) {
|
|
227
|
+
existingPerms.delete(conflictingPerm);
|
|
236
228
|
}
|
|
237
229
|
existingPerms.add(perm);
|
|
238
230
|
}
|
|
@@ -308,6 +300,22 @@ function inflateRoomData(room) {
|
|
|
308
300
|
lastConnectionAt
|
|
309
301
|
};
|
|
310
302
|
}
|
|
303
|
+
function normalizeCreateRoomOptions(options) {
|
|
304
|
+
return {
|
|
305
|
+
...options,
|
|
306
|
+
defaultAccesses: _core.normalizeRoomPermissionInput.call(void 0, options.defaultAccesses),
|
|
307
|
+
groupsAccesses: _core.normalizeRoomAccessesInput.call(void 0, options.groupsAccesses),
|
|
308
|
+
usersAccesses: _core.normalizeRoomAccessesInput.call(void 0, options.usersAccesses)
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
function normalizeUpdateRoomOptions(options) {
|
|
312
|
+
return {
|
|
313
|
+
...options,
|
|
314
|
+
defaultAccesses: options.defaultAccesses === void 0 || options.defaultAccesses === null ? options.defaultAccesses : _core.normalizeRoomPermissionInput.call(void 0, options.defaultAccesses),
|
|
315
|
+
groupsAccesses: _core.normalizeRoomAccessesUpdateInput.call(void 0, options.groupsAccesses),
|
|
316
|
+
usersAccesses: _core.normalizeRoomAccessesUpdateInput.call(void 0, options.usersAccesses)
|
|
317
|
+
};
|
|
318
|
+
}
|
|
311
319
|
function inflateAiCopilot(copilot) {
|
|
312
320
|
return {
|
|
313
321
|
...copilot,
|
|
@@ -614,6 +622,7 @@ var Liveblocks = class {
|
|
|
614
622
|
* @returns The created room.
|
|
615
623
|
*/
|
|
616
624
|
async createRoom(roomId, params, options) {
|
|
625
|
+
const normalizedParams = normalizeCreateRoomOptions(params);
|
|
617
626
|
const {
|
|
618
627
|
defaultAccesses,
|
|
619
628
|
groupsAccesses,
|
|
@@ -621,7 +630,7 @@ var Liveblocks = class {
|
|
|
621
630
|
metadata,
|
|
622
631
|
tenantId,
|
|
623
632
|
organizationId
|
|
624
|
-
} =
|
|
633
|
+
} = normalizedParams;
|
|
625
634
|
const body = {
|
|
626
635
|
id: roomId,
|
|
627
636
|
defaultAccesses,
|
|
@@ -674,9 +683,13 @@ var Liveblocks = class {
|
|
|
674
683
|
* @returns The room.
|
|
675
684
|
*/
|
|
676
685
|
async upsertRoom(roomId, params, options) {
|
|
686
|
+
const body = {
|
|
687
|
+
update: normalizeUpdateRoomOptions(params.update),
|
|
688
|
+
create: params.create === void 0 ? void 0 : normalizeCreateRoomOptions(params.create)
|
|
689
|
+
};
|
|
677
690
|
const res = await this.#post(
|
|
678
691
|
_core.url`/v2/rooms/${roomId}/upsert`,
|
|
679
|
-
|
|
692
|
+
body,
|
|
680
693
|
options
|
|
681
694
|
);
|
|
682
695
|
if (!res.ok) {
|
|
@@ -711,7 +724,7 @@ var Liveblocks = class {
|
|
|
711
724
|
* @returns The updated room.
|
|
712
725
|
*/
|
|
713
726
|
async updateRoom(roomId, params, options) {
|
|
714
|
-
const { defaultAccesses, groupsAccesses, usersAccesses, metadata } = params;
|
|
727
|
+
const { defaultAccesses, groupsAccesses, usersAccesses, metadata } = normalizeUpdateRoomOptions(params);
|
|
715
728
|
const res = await this.#post(
|
|
716
729
|
_core.url`/v2/rooms/${roomId}`,
|
|
717
730
|
{
|