@liveblocks/client 0.16.14 → 0.16.17
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 +32 -2
- package/internal.js +42 -4
- package/internal.mjs +43 -3
- package/package.json +1 -1
- package/shared.d.ts +4 -1
- package/shared.js +11 -10
- package/shared.mjs +11 -10
package/internal.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { d as JsonObject, J as Json, g as Resolve, e as Lson, A as AbstractCrdt, f as LsonObject, L as LiveObject, S as StorageUpdate } from './shared';
|
|
2
|
-
export { g as Resolve, h as RoomInitializers } from './shared';
|
|
2
|
+
export { g as Resolve, h as RoomInitializers, i as isJsonArray, j as isJsonObject, k as isJsonScalar } from './shared';
|
|
3
3
|
|
|
4
4
|
declare type IdTuple<T> = [id: string, value: T];
|
|
5
5
|
/**
|
|
@@ -317,6 +317,33 @@ 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
|
+
maxConnectionsPerRoom?: number;
|
|
333
|
+
id?: string;
|
|
334
|
+
info?: Json;
|
|
335
|
+
};
|
|
336
|
+
declare type AuthToken = AppOnlyAuthToken | RoomAuthToken;
|
|
337
|
+
interface JwtMetadata extends JsonObject {
|
|
338
|
+
iat: number;
|
|
339
|
+
exp: number;
|
|
340
|
+
}
|
|
341
|
+
declare function isScope(value: unknown): value is Scope;
|
|
342
|
+
declare function isAppOnlyAuthToken(data: JsonObject): data is AppOnlyAuthToken;
|
|
343
|
+
declare function isRoomAuthToken(data: JsonObject): data is RoomAuthToken;
|
|
344
|
+
declare function isAuthToken(data: JsonObject): data is AuthToken;
|
|
345
|
+
declare function parseAuthToken(token: string): AuthToken & JwtMetadata;
|
|
346
|
+
|
|
320
347
|
declare function lsonToJson(value: Lson | AbstractCrdt): Json;
|
|
321
348
|
declare function patchLiveObjectKey<O extends LsonObject>(liveObject: LiveObject<O>, key: keyof O, prev: unknown, next: unknown): void;
|
|
322
349
|
declare function patchImmutableObject<T>(state: T, updates: StorageUpdate[]): T;
|
|
@@ -344,6 +371,9 @@ declare function comparePosition(posA: string, posB: string): number;
|
|
|
344
371
|
* 🍒 case.
|
|
345
372
|
*/
|
|
346
373
|
declare function assertNever(_value: never, errmsg: string): never;
|
|
374
|
+
declare function isPlainObject(blob: unknown): blob is {
|
|
375
|
+
[key: string]: unknown;
|
|
376
|
+
};
|
|
347
377
|
/**
|
|
348
378
|
* Alternative to JSON.parse() that will not throw in production. If the passed
|
|
349
379
|
* string cannot be parsed, this will return `undefined`.
|
|
@@ -354,4 +384,4 @@ declare function tryParseJson(rawMessage: string): Json | undefined;
|
|
|
354
384
|
*/
|
|
355
385
|
declare function b64decode(b64value: string): string;
|
|
356
386
|
|
|
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 };
|
|
387
|
+
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, isPlainObject, 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) && (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 = {};
|
|
@@ -168,10 +198,18 @@ Object.defineProperty(exports, "ClientMsgCode", {
|
|
|
168
198
|
}), exports.assertNever = LiveObject.assertNever, exports.b64decode = LiveObject.b64decode,
|
|
169
199
|
exports.comparePosition = LiveObject.comparePosition, exports.deprecate = LiveObject.deprecate,
|
|
170
200
|
exports.deprecateIf = LiveObject.deprecateIf, exports.errorIf = LiveObject.errorIf,
|
|
171
|
-
exports.isChildCrdt = LiveObject.isChildCrdt, exports.
|
|
201
|
+
exports.isChildCrdt = LiveObject.isChildCrdt, exports.isJsonArray = LiveObject.isJsonArray,
|
|
202
|
+
exports.isJsonObject = LiveObject.isJsonObject, exports.isJsonScalar = LiveObject.isJsonScalar,
|
|
203
|
+
exports.isPlainObject = LiveObject.isPlainObject, exports.isRootCrdt = LiveObject.isRootCrdt,
|
|
172
204
|
exports.makePosition = LiveObject.makePosition, exports.throwUsageError = LiveObject.throwUsageError,
|
|
173
|
-
exports.tryParseJson = LiveObject.tryParseJson, exports.
|
|
174
|
-
exports.
|
|
205
|
+
exports.tryParseJson = LiveObject.tryParseJson, exports.isAppOnlyAuthToken = isAppOnlyAuthToken,
|
|
206
|
+
exports.isAuthToken = isAuthToken, 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) {
|
|
175
213
|
return updates.reduce((function(state, update) {
|
|
176
214
|
return function(state, update) {
|
|
177
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, l as isPlainObject, 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) && (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.d.ts
CHANGED
|
@@ -14,6 +14,9 @@ declare type JsonArray = Json[];
|
|
|
14
14
|
declare type JsonObject = {
|
|
15
15
|
[key: string]: Json | undefined;
|
|
16
16
|
};
|
|
17
|
+
declare function isJsonScalar(data: Json): data is JsonScalar;
|
|
18
|
+
declare function isJsonArray(data: Json): data is JsonArray;
|
|
19
|
+
declare function isJsonObject(data: Json): data is JsonObject;
|
|
17
20
|
|
|
18
21
|
/**
|
|
19
22
|
* The LiveMap class is similar to a JavaScript Map that is synchronized on all clients.
|
|
@@ -780,4 +783,4 @@ declare class LiveObject<O extends LsonObject = LsonObject> extends AbstractCrdt
|
|
|
780
783
|
update(overrides: Partial<O>): void;
|
|
781
784
|
}
|
|
782
785
|
|
|
783
|
-
export { AbstractCrdt as A, BroadcastOptions as B, ClientOptions as C, History as H, Json as J, LiveObject as L, Others as O, Presence as P, Room as R, StorageUpdate as S, User as U, Client as a, LiveMap as b, LiveList as c, JsonObject as d, Lson as e, LsonObject as f, Resolve as g, RoomInitializers as h };
|
|
786
|
+
export { AbstractCrdt as A, BroadcastOptions as B, ClientOptions as C, History as H, Json as J, LiveObject as L, Others as O, Presence as P, Room as R, StorageUpdate as S, User as U, Client as a, LiveMap as b, LiveList as c, JsonObject as d, Lson as e, LsonObject as f, Resolve as g, RoomInitializers as h, isJsonArray as i, isJsonObject as j, isJsonScalar as k };
|
package/shared.js
CHANGED
|
@@ -197,12 +197,16 @@ var AbstractCrdt = function() {
|
|
|
197
197
|
} ]), AbstractCrdt;
|
|
198
198
|
}();
|
|
199
199
|
|
|
200
|
+
function isJsonScalar(data) {
|
|
201
|
+
return null === data || "string" == typeof data || "number" == typeof data || "boolean" == typeof data;
|
|
202
|
+
}
|
|
203
|
+
|
|
200
204
|
function isJsonArray(data) {
|
|
201
205
|
return Array.isArray(data);
|
|
202
206
|
}
|
|
203
207
|
|
|
204
208
|
function isJsonObject(data) {
|
|
205
|
-
return
|
|
209
|
+
return !isJsonScalar(data) && !isJsonArray(data);
|
|
206
210
|
}
|
|
207
211
|
|
|
208
212
|
var _Symbol$iterator$1, _Symbol$iterator2, LiveRegister = function(_AbstractCrdt) {
|
|
@@ -940,14 +944,11 @@ function selfOrRegister(obj) {
|
|
|
940
944
|
|
|
941
945
|
function isPlain(value) {
|
|
942
946
|
var type = typeof value;
|
|
943
|
-
return "undefined" === type || null === value || "string" === type || "boolean" === type || "number" === type || Array.isArray(value) ||
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
for (;null !== Object.getPrototypeOf(baseProto); ) baseProto = Object.getPrototypeOf(baseProto);
|
|
949
|
-
return proto === baseProto;
|
|
950
|
-
}(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);
|
|
951
952
|
}
|
|
952
953
|
|
|
953
954
|
function entries(obj) {
|
|
@@ -1366,7 +1367,7 @@ exports.errorIf = function(condition, message) {
|
|
|
1366
1367
|
}
|
|
1367
1368
|
})), ops;
|
|
1368
1369
|
}, exports.isChildCrdt = isChildCrdt, exports.isJsonArray = isJsonArray, exports.isJsonObject = isJsonObject,
|
|
1369
|
-
exports.isRootCrdt = function(crdt) {
|
|
1370
|
+
exports.isJsonScalar = isJsonScalar, exports.isPlainObject = isPlainObject, exports.isRootCrdt = function(crdt) {
|
|
1370
1371
|
return crdt.type === exports.CrdtType.OBJECT && !isChildCrdt(crdt);
|
|
1371
1372
|
}, exports.isSameNodeOrChildOf = function isSameNodeOrChildOf(node, parent) {
|
|
1372
1373
|
return node === parent || !!node._parent && isSameNodeOrChildOf(node._parent, parent);
|
package/shared.mjs
CHANGED
|
@@ -70,12 +70,16 @@ class AbstractCrdt {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
function isJsonScalar(data) {
|
|
74
|
+
return null === data || "string" == typeof data || "number" == typeof data || "boolean" == typeof data;
|
|
75
|
+
}
|
|
76
|
+
|
|
73
77
|
function isJsonArray(data) {
|
|
74
78
|
return Array.isArray(data);
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
function isJsonObject(data) {
|
|
78
|
-
return
|
|
82
|
+
return !isJsonScalar(data) && !isJsonArray(data);
|
|
79
83
|
}
|
|
80
84
|
|
|
81
85
|
class LiveRegister extends AbstractCrdt {
|
|
@@ -909,14 +913,11 @@ function mergeStorageUpdates(first, second) {
|
|
|
909
913
|
|
|
910
914
|
function isPlain(value) {
|
|
911
915
|
const type = typeof value;
|
|
912
|
-
return "undefined" === type || null === value || "string" === type || "boolean" === type || "number" === type || Array.isArray(value) ||
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
for (;null !== Object.getPrototypeOf(baseProto); ) baseProto = Object.getPrototypeOf(baseProto);
|
|
918
|
-
return proto === baseProto;
|
|
919
|
-
}(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);
|
|
920
921
|
}
|
|
921
922
|
|
|
922
923
|
function findNonSerializableValue(value, path = "") {
|
|
@@ -1273,4 +1274,4 @@ class LiveObject extends AbstractCrdt {
|
|
|
1273
1274
|
}
|
|
1274
1275
|
}
|
|
1275
1276
|
|
|
1276
|
-
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 };
|