@liveblocks/client 0.16.15 → 0.16.16
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/internal.d.ts +29 -1
- package/internal.js +39 -2
- package/internal.mjs +43 -3
- package/package.json +1 -1
- package/shared.js +6 -9
- package/shared.mjs +6 -9
package/internal.d.ts
CHANGED
|
@@ -317,6 +317,34 @@ declare function throwUsageError(message: string): void;
|
|
|
317
317
|
*/
|
|
318
318
|
declare function errorIf(condition: unknown, message: string): void;
|
|
319
319
|
|
|
320
|
+
declare const SCOPES: readonly ["websocket:presence", "websocket:storage", "room:read", "room:write", "rooms:read", "rooms:write"];
|
|
321
|
+
declare type Scope = typeof SCOPES[number];
|
|
322
|
+
declare type AppOnlyAuthToken = {
|
|
323
|
+
appId: string;
|
|
324
|
+
roomId?: never;
|
|
325
|
+
scopes: string[];
|
|
326
|
+
};
|
|
327
|
+
declare type RoomAuthToken = {
|
|
328
|
+
appId: string;
|
|
329
|
+
roomId: string;
|
|
330
|
+
scopes: string[];
|
|
331
|
+
actor: number;
|
|
332
|
+
maxConnections: number;
|
|
333
|
+
maxConnectionsPerRoom?: number;
|
|
334
|
+
id?: string;
|
|
335
|
+
info?: Json;
|
|
336
|
+
};
|
|
337
|
+
declare type AuthToken = AppOnlyAuthToken | RoomAuthToken;
|
|
338
|
+
interface JwtMetadata extends JsonObject {
|
|
339
|
+
iat: number;
|
|
340
|
+
exp: number;
|
|
341
|
+
}
|
|
342
|
+
declare function isScope(value: unknown): value is Scope;
|
|
343
|
+
declare function isAppOnlyAuthToken(data: JsonObject): data is AppOnlyAuthToken;
|
|
344
|
+
declare function isRoomAuthToken(data: JsonObject): data is RoomAuthToken;
|
|
345
|
+
declare function isAuthToken(data: JsonObject): data is AuthToken;
|
|
346
|
+
declare function parseAuthToken(token: string): AuthToken & JwtMetadata;
|
|
347
|
+
|
|
320
348
|
declare function lsonToJson(value: Lson | AbstractCrdt): Json;
|
|
321
349
|
declare function patchLiveObjectKey<O extends LsonObject>(liveObject: LiveObject<O>, key: keyof O, prev: unknown, next: unknown): void;
|
|
322
350
|
declare function patchImmutableObject<T>(state: T, updates: StorageUpdate[]): T;
|
|
@@ -354,4 +382,4 @@ declare function tryParseJson(rawMessage: string): Json | undefined;
|
|
|
354
382
|
*/
|
|
355
383
|
declare function b64decode(b64value: string): string;
|
|
356
384
|
|
|
357
|
-
export { BroadcastEventClientMsg, ClientMsg, ClientMsgCode, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateRegisterOp, CreateRootObjectOp, DeleteCrdtOp, DeleteObjectKeyOp, FetchStorageClientMsg, IdTuple, InitialDocumentStateServerMsg, NodeMap, Op, OpCode, ParentToChildNodeMap, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, UpdateObjectOp, UpdatePresenceClientMsg, UpdateStorageClientMsg, UserJoinServerMsg, WebsocketCloseCodes, assertNever, b64decode, comparePosition, deprecate, deprecateIf, errorIf, isChildCrdt, isRootCrdt, lsonToJson, makePosition, patchImmutableObject, patchLiveObjectKey, throwUsageError, tryParseJson };
|
|
385
|
+
export { AppOnlyAuthToken, AuthToken, BroadcastEventClientMsg, ClientMsg, ClientMsgCode, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateRegisterOp, CreateRootObjectOp, DeleteCrdtOp, DeleteObjectKeyOp, FetchStorageClientMsg, IdTuple, InitialDocumentStateServerMsg, NodeMap, Op, OpCode, ParentToChildNodeMap, RoomAuthToken, RoomStateServerMsg, Scope, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, UpdateObjectOp, UpdatePresenceClientMsg, UpdateStorageClientMsg, UserJoinServerMsg, WebsocketCloseCodes, assertNever, b64decode, comparePosition, deprecate, deprecateIf, errorIf, isAppOnlyAuthToken, isAuthToken, isChildCrdt, isRoomAuthToken, isRootCrdt, isScope, lsonToJson, makePosition, parseAuthToken, patchImmutableObject, patchLiveObjectKey, throwUsageError, tryParseJson };
|
package/internal.js
CHANGED
|
@@ -4,7 +4,37 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: !0
|
|
5
5
|
});
|
|
6
6
|
|
|
7
|
-
var LiveObject = require("./shared.js");
|
|
7
|
+
var LiveObject = require("./shared.js"), SCOPES = [ "websocket:presence", "websocket:storage", "room:read", "room:write", "rooms:read", "rooms:write" ];
|
|
8
|
+
|
|
9
|
+
function isStringList(value) {
|
|
10
|
+
return Array.isArray(value) && value.every((function(i) {
|
|
11
|
+
return "string" == typeof i;
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function isAppOnlyAuthToken(data) {
|
|
16
|
+
return "string" == typeof data.appId && void 0 === data.roomId && isStringList(data.scopes);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function isRoomAuthToken(data) {
|
|
20
|
+
return "string" == typeof data.appId && "string" == typeof data.roomId && "number" == typeof data.actor && (void 0 === data.id || "string" == typeof data.id) && isStringList(data.scopes) && "number" == typeof data.maxConnections && (void 0 === data.maxConnectionsPerRoom || "number" == typeof data.maxConnectionsPerRoom);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isAuthToken(data) {
|
|
24
|
+
return isAppOnlyAuthToken(data) || isRoomAuthToken(data);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function parseJwtToken(token) {
|
|
28
|
+
var tokenParts = token.split(".");
|
|
29
|
+
if (3 !== tokenParts.length) throw new Error("Authentication error: invalid JWT token");
|
|
30
|
+
var data = LiveObject.tryParseJson(LiveObject.b64decode(tokenParts[1]));
|
|
31
|
+
if (data && function(data) {
|
|
32
|
+
if (!LiveObject.isPlainObject(data)) return !1;
|
|
33
|
+
var iat = data.iat, exp = data.exp;
|
|
34
|
+
return "number" == typeof iat && "number" == typeof exp;
|
|
35
|
+
}(data)) return data;
|
|
36
|
+
throw new Error("Authentication error: missing JWT metadata");
|
|
37
|
+
}
|
|
8
38
|
|
|
9
39
|
function lsonObjectToJson(obj) {
|
|
10
40
|
var result = {};
|
|
@@ -172,7 +202,14 @@ exports.isChildCrdt = LiveObject.isChildCrdt, exports.isJsonArray = LiveObject.i
|
|
|
172
202
|
exports.isJsonObject = LiveObject.isJsonObject, exports.isJsonScalar = LiveObject.isJsonScalar,
|
|
173
203
|
exports.isRootCrdt = LiveObject.isRootCrdt, exports.makePosition = LiveObject.makePosition,
|
|
174
204
|
exports.throwUsageError = LiveObject.throwUsageError, exports.tryParseJson = LiveObject.tryParseJson,
|
|
175
|
-
exports.
|
|
205
|
+
exports.isAppOnlyAuthToken = isAppOnlyAuthToken, exports.isAuthToken = isAuthToken,
|
|
206
|
+
exports.isRoomAuthToken = isRoomAuthToken, exports.isScope = function(value) {
|
|
207
|
+
return SCOPES.includes(value);
|
|
208
|
+
}, exports.lsonToJson = lsonToJson, exports.parseAuthToken = function(token) {
|
|
209
|
+
var data = parseJwtToken(token);
|
|
210
|
+
if (data && isAuthToken(data)) return data;
|
|
211
|
+
throw new Error("Authentication error. Liveblocks could not parse the response of your authentication endpoint");
|
|
212
|
+
}, exports.patchImmutableObject = function(state, updates) {
|
|
176
213
|
return updates.reduce((function(state, update) {
|
|
177
214
|
return function(state, update) {
|
|
178
215
|
var path = function(node) {
|
package/internal.mjs
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
|
-
import { L as LiveObject, b as LiveList, k as LiveMap,
|
|
1
|
+
import { t as tryParseJson, e as b64decode, l as isPlainObject$1, L as LiveObject, b as LiveList, k as LiveMap, n as LiveRegister, A as AbstractCrdt, o as findNonSerializableValue } from "./shared.mjs";
|
|
2
2
|
|
|
3
|
-
export { C as ClientMsgCode,
|
|
3
|
+
export { C as ClientMsgCode, u as CrdtType, O as OpCode, S as ServerMsgCode, W as WebsocketCloseCodes, y as assertNever, e as b64decode, v as comparePosition, p as deprecate, j as deprecateIf, q as errorIf, x as isChildCrdt, c as isJsonArray, f as isJsonObject, z as isJsonScalar, h as isRootCrdt, w as makePosition, s as throwUsageError, t as tryParseJson } from "./shared.mjs";
|
|
4
|
+
|
|
5
|
+
const SCOPES = [ "websocket:presence", "websocket:storage", "room:read", "room:write", "rooms:read", "rooms:write" ];
|
|
6
|
+
|
|
7
|
+
function isScope(value) {
|
|
8
|
+
return SCOPES.includes(value);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function isStringList(value) {
|
|
12
|
+
return Array.isArray(value) && value.every((i => "string" == typeof i));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function isAppOnlyAuthToken(data) {
|
|
16
|
+
return "string" == typeof data.appId && void 0 === data.roomId && isStringList(data.scopes);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function isRoomAuthToken(data) {
|
|
20
|
+
return "string" == typeof data.appId && "string" == typeof data.roomId && "number" == typeof data.actor && (void 0 === data.id || "string" == typeof data.id) && isStringList(data.scopes) && "number" == typeof data.maxConnections && (void 0 === data.maxConnectionsPerRoom || "number" == typeof data.maxConnectionsPerRoom);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isAuthToken(data) {
|
|
24
|
+
return isAppOnlyAuthToken(data) || isRoomAuthToken(data);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function parseJwtToken(token) {
|
|
28
|
+
const tokenParts = token.split(".");
|
|
29
|
+
if (3 !== tokenParts.length) throw new Error("Authentication error: invalid JWT token");
|
|
30
|
+
const data = tryParseJson(b64decode(tokenParts[1]));
|
|
31
|
+
if (data && function(data) {
|
|
32
|
+
if (!isPlainObject$1(data)) return !1;
|
|
33
|
+
const {iat: iat, exp: exp} = data;
|
|
34
|
+
return "number" == typeof iat && "number" == typeof exp;
|
|
35
|
+
}(data)) return data;
|
|
36
|
+
throw new Error("Authentication error: missing JWT metadata");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function parseAuthToken(token) {
|
|
40
|
+
const data = parseJwtToken(token);
|
|
41
|
+
if (data && isAuthToken(data)) return data;
|
|
42
|
+
throw new Error("Authentication error. Liveblocks could not parse the response of your authentication endpoint");
|
|
43
|
+
}
|
|
4
44
|
|
|
5
45
|
function lsonObjectToJson(obj) {
|
|
6
46
|
const result = {};
|
|
@@ -145,4 +185,4 @@ function patchImmutableNode(state, path, update) {
|
|
|
145
185
|
});
|
|
146
186
|
}
|
|
147
187
|
|
|
148
|
-
export { lsonToJson, patchImmutableObject, patchLiveObjectKey };
|
|
188
|
+
export { isAppOnlyAuthToken, isAuthToken, isRoomAuthToken, isScope, lsonToJson, parseAuthToken, patchImmutableObject, patchLiveObjectKey };
|
package/package.json
CHANGED
package/shared.js
CHANGED
|
@@ -944,14 +944,11 @@ function selfOrRegister(obj) {
|
|
|
944
944
|
|
|
945
945
|
function isPlain(value) {
|
|
946
946
|
var type = typeof value;
|
|
947
|
-
return "undefined" === type || null === value || "string" === type || "boolean" === type || "number" === type || Array.isArray(value) ||
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
for (;null !== Object.getPrototypeOf(baseProto); ) baseProto = Object.getPrototypeOf(baseProto);
|
|
953
|
-
return proto === baseProto;
|
|
954
|
-
}(value);
|
|
947
|
+
return "undefined" === type || null === value || "string" === type || "boolean" === type || "number" === type || Array.isArray(value) || isPlainObject(value);
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
function isPlainObject(blob) {
|
|
951
|
+
return null !== blob && "object" == typeof blob && "[object Object]" === Object.prototype.toString.call(blob);
|
|
955
952
|
}
|
|
956
953
|
|
|
957
954
|
function entries(obj) {
|
|
@@ -1370,7 +1367,7 @@ exports.errorIf = function(condition, message) {
|
|
|
1370
1367
|
}
|
|
1371
1368
|
})), ops;
|
|
1372
1369
|
}, exports.isChildCrdt = isChildCrdt, exports.isJsonArray = isJsonArray, exports.isJsonObject = isJsonObject,
|
|
1373
|
-
exports.isJsonScalar = isJsonScalar, exports.isRootCrdt = function(crdt) {
|
|
1370
|
+
exports.isJsonScalar = isJsonScalar, exports.isPlainObject = isPlainObject, exports.isRootCrdt = function(crdt) {
|
|
1374
1371
|
return crdt.type === exports.CrdtType.OBJECT && !isChildCrdt(crdt);
|
|
1375
1372
|
}, exports.isSameNodeOrChildOf = function isSameNodeOrChildOf(node, parent) {
|
|
1376
1373
|
return node === parent || !!node._parent && isSameNodeOrChildOf(node._parent, parent);
|
package/shared.mjs
CHANGED
|
@@ -913,14 +913,11 @@ function mergeStorageUpdates(first, second) {
|
|
|
913
913
|
|
|
914
914
|
function isPlain(value) {
|
|
915
915
|
const type = typeof value;
|
|
916
|
-
return "undefined" === type || null === value || "string" === type || "boolean" === type || "number" === type || Array.isArray(value) ||
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
for (;null !== Object.getPrototypeOf(baseProto); ) baseProto = Object.getPrototypeOf(baseProto);
|
|
922
|
-
return proto === baseProto;
|
|
923
|
-
}(value);
|
|
916
|
+
return "undefined" === type || null === value || "string" === type || "boolean" === type || "number" === type || Array.isArray(value) || isPlainObject(value);
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
function isPlainObject(blob) {
|
|
920
|
+
return null !== blob && "object" == typeof blob && "[object Object]" === Object.prototype.toString.call(blob);
|
|
924
921
|
}
|
|
925
922
|
|
|
926
923
|
function findNonSerializableValue(value, path = "") {
|
|
@@ -1277,4 +1274,4 @@ class LiveObject extends AbstractCrdt {
|
|
|
1277
1274
|
}
|
|
1278
1275
|
}
|
|
1279
1276
|
|
|
1280
|
-
export { AbstractCrdt as A, ClientMsgCode as C, LiveObject as L, OpCode as O, ServerMsgCode as S, WebsocketCloseCodes as W, isSameNodeOrChildOf as a, LiveList as b, isJsonArray as c, compact as d, b64decode as e, isJsonObject as f, getTreesDiffOperations as g, isRootCrdt as h, isTokenValid as i, deprecateIf as j, LiveMap as k,
|
|
1277
|
+
export { AbstractCrdt as A, ClientMsgCode as C, LiveObject as L, OpCode as O, ServerMsgCode as S, WebsocketCloseCodes as W, isSameNodeOrChildOf as a, LiveList as b, isJsonArray as c, compact as d, b64decode as e, isJsonObject as f, getTreesDiffOperations as g, isRootCrdt as h, isTokenValid as i, deprecateIf as j, LiveMap as k, isPlainObject as l, mergeStorageUpdates as m, LiveRegister as n, findNonSerializableValue as o, deprecate as p, errorIf as q, remove as r, throwUsageError as s, tryParseJson as t, CrdtType as u, comparePosition as v, makePosition as w, isChildCrdt as x, assertNever as y, isJsonScalar as z };
|