@liveblocks/core 1.1.0 → 1.1.1-internal1
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.d.ts +24 -30
- package/dist/index.js +17 -57
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -669,31 +669,6 @@ declare type Delegates<T extends BaseAuthResult> = {
|
|
|
669
669
|
createSocket: (token: T) => IWebSocketInstance;
|
|
670
670
|
};
|
|
671
671
|
|
|
672
|
-
declare type AppOnlyAuthToken = {
|
|
673
|
-
appId: string;
|
|
674
|
-
roomId?: never;
|
|
675
|
-
scopes: string[];
|
|
676
|
-
};
|
|
677
|
-
declare type RoomAuthToken = {
|
|
678
|
-
appId: string;
|
|
679
|
-
roomId: string;
|
|
680
|
-
scopes: string[];
|
|
681
|
-
actor: number;
|
|
682
|
-
maxConnectionsPerRoom?: number;
|
|
683
|
-
info?: Json;
|
|
684
|
-
groupIds?: string[];
|
|
685
|
-
} & ({
|
|
686
|
-
id: string;
|
|
687
|
-
anonymousId?: never;
|
|
688
|
-
} | {
|
|
689
|
-
id?: never;
|
|
690
|
-
anonymousId: string;
|
|
691
|
-
});
|
|
692
|
-
declare type AuthToken = AppOnlyAuthToken | RoomAuthToken;
|
|
693
|
-
declare function isAppOnlyAuthToken(data: JsonObject): data is AppOnlyAuthToken;
|
|
694
|
-
declare function isRoomAuthToken(data: JsonObject): data is RoomAuthToken;
|
|
695
|
-
declare function isAuthToken(data: JsonObject): data is AuthToken;
|
|
696
|
-
|
|
697
672
|
declare type ReadonlyArrayWithLegacyMethods<T> = readonly T[] & {
|
|
698
673
|
/**
|
|
699
674
|
* @deprecated Prefer the normal .length property on arrays.
|
|
@@ -1456,12 +1431,14 @@ declare enum ClientMsgCode {
|
|
|
1456
1431
|
UPDATE_PRESENCE = 100,
|
|
1457
1432
|
BROADCAST_EVENT = 103,
|
|
1458
1433
|
FETCH_STORAGE = 200,
|
|
1459
|
-
UPDATE_STORAGE = 201
|
|
1434
|
+
UPDATE_STORAGE = 201,
|
|
1435
|
+
FETCH_YDOC = 300,
|
|
1436
|
+
UPDATE_YDOC = 301
|
|
1460
1437
|
}
|
|
1461
1438
|
/**
|
|
1462
1439
|
* Messages that can be sent from the client to the server.
|
|
1463
1440
|
*/
|
|
1464
|
-
declare type ClientMsg<TPresence extends JsonObject, TRoomEvent extends Json> = BroadcastEventClientMsg<TRoomEvent> | UpdatePresenceClientMsg<TPresence> | UpdateStorageClientMsg | FetchStorageClientMsg;
|
|
1441
|
+
declare type ClientMsg<TPresence extends JsonObject, TRoomEvent extends Json> = BroadcastEventClientMsg<TRoomEvent> | UpdatePresenceClientMsg<TPresence> | UpdateStorageClientMsg | FetchStorageClientMsg | FetchYDocClientMsg | UpdateYDocClientMsg;
|
|
1465
1442
|
declare type BroadcastEventClientMsg<TRoomEvent extends Json> = {
|
|
1466
1443
|
type: ClientMsgCode.BROADCAST_EVENT;
|
|
1467
1444
|
event: TRoomEvent;
|
|
@@ -1499,6 +1476,14 @@ declare type UpdateStorageClientMsg = {
|
|
|
1499
1476
|
declare type FetchStorageClientMsg = {
|
|
1500
1477
|
readonly type: ClientMsgCode.FETCH_STORAGE;
|
|
1501
1478
|
};
|
|
1479
|
+
declare type FetchYDocClientMsg = {
|
|
1480
|
+
readonly type: ClientMsgCode.FETCH_YDOC;
|
|
1481
|
+
readonly vector: string;
|
|
1482
|
+
};
|
|
1483
|
+
declare type UpdateYDocClientMsg = {
|
|
1484
|
+
readonly type: ClientMsgCode.UPDATE_YDOC;
|
|
1485
|
+
readonly update: string;
|
|
1486
|
+
};
|
|
1502
1487
|
|
|
1503
1488
|
declare type IdTuple<T> = [id: string, value: T];
|
|
1504
1489
|
declare enum CrdtType {
|
|
@@ -1548,12 +1533,13 @@ declare enum ServerMsgCode {
|
|
|
1548
1533
|
ROOM_STATE = 104,
|
|
1549
1534
|
INITIAL_STORAGE_STATE = 200,
|
|
1550
1535
|
UPDATE_STORAGE = 201,
|
|
1551
|
-
REJECT_STORAGE_OP = 299
|
|
1536
|
+
REJECT_STORAGE_OP = 299,
|
|
1537
|
+
UPDATE_YDOC = 300
|
|
1552
1538
|
}
|
|
1553
1539
|
/**
|
|
1554
1540
|
* Messages that can be sent from the server to the client.
|
|
1555
1541
|
*/
|
|
1556
|
-
declare type ServerMsg<TPresence extends JsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json> = UpdatePresenceServerMsg<TPresence> | UserJoinServerMsg<TUserMeta> | UserLeftServerMsg | BroadcastedEventServerMsg<TRoomEvent> | RoomStateServerMsg<TUserMeta> | InitialDocumentStateServerMsg | UpdateStorageServerMsg | RejectedStorageOpServerMsg;
|
|
1542
|
+
declare type ServerMsg<TPresence extends JsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json> = UpdatePresenceServerMsg<TPresence> | UserJoinServerMsg<TUserMeta> | UserLeftServerMsg | BroadcastedEventServerMsg<TRoomEvent> | RoomStateServerMsg<TUserMeta> | InitialDocumentStateServerMsg | UpdateStorageServerMsg | RejectedStorageOpServerMsg | YDocUpdate;
|
|
1557
1543
|
/**
|
|
1558
1544
|
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
1559
1545
|
* a User updated their presence. For example, when a user moves their cursor.
|
|
@@ -1636,6 +1622,14 @@ declare type UserLeftServerMsg = {
|
|
|
1636
1622
|
readonly type: ServerMsgCode.USER_LEFT;
|
|
1637
1623
|
readonly actor: number;
|
|
1638
1624
|
};
|
|
1625
|
+
/**
|
|
1626
|
+
* Sent by the WebSocket server when the ydoc is updated or when requested based on stateVector passed.
|
|
1627
|
+
* Contains a base64 encoded update
|
|
1628
|
+
*/
|
|
1629
|
+
declare type YDocUpdate = {
|
|
1630
|
+
readonly type: ServerMsgCode.UPDATE_YDOC;
|
|
1631
|
+
readonly update: string;
|
|
1632
|
+
};
|
|
1639
1633
|
/**
|
|
1640
1634
|
* Sent by the WebSocket server and broadcasted to all clients to announce that
|
|
1641
1635
|
* a User broadcasted an Event to everyone in the Room.
|
|
@@ -1884,4 +1878,4 @@ declare type EnsureJson<T> = [
|
|
|
1884
1878
|
[K in keyof T]: EnsureJson<T[K]>;
|
|
1885
1879
|
};
|
|
1886
1880
|
|
|
1887
|
-
export { AckOp,
|
|
1881
|
+
export { AckOp, BaseAuthResult, BaseUserMeta, BroadcastEventClientMsg, BroadcastOptions, BroadcastedEventServerMsg, Client, ClientMsg, ClientMsgCode, CrdtType, CreateChildOp, CreateListOp, CreateMapOp, CreateObjectOp, CreateOp, CreateRegisterOp, CreateRootObjectOp, Delegates, DeleteCrdtOp, DeleteObjectKeyOp, DevToolsTreeNode as DevTools, protocol as DevToolsMsg, EnsureJson, FetchStorageClientMsg, FetchYDocClientMsg, History, IWebSocket, IWebSocketCloseEvent, IWebSocketEvent, IWebSocketInstance, IWebSocketMessageEvent, IdTuple, Immutable, InitialDocumentStateServerMsg, Json, JsonArray, JsonObject, JsonScalar, LegacyConnectionStatus, LiveList, LiveListUpdate, LiveMap, LiveMapUpdate, LiveNode, LiveObject, LiveObjectUpdate, LiveStructure, LostConnectionEvent, Lson, LsonObject, NodeMap, Op, OpCode, Others, ParentToChildNodeMap, PlainLson, PlainLsonFields, PlainLsonList, PlainLsonMap, PlainLsonObject, RejectedStorageOpServerMsg, Resolve, Room, RoomInitializers, RoomStateServerMsg, SerializedChild, SerializedCrdt, SerializedList, SerializedMap, SerializedObject, SerializedRegister, SerializedRootObject, ServerMsg, ServerMsgCode, SetParentKeyOp, Status, StorageStatus, StorageUpdate, ToImmutable, ToJson, UpdateObjectOp, UpdatePresenceClientMsg, UpdatePresenceServerMsg, UpdateStorageClientMsg, UpdateStorageServerMsg, UpdateYDocClientMsg, User, UserJoinServerMsg, UserLeftServerMsg, WebsocketCloseCodes, asArrayWithLegacyMethods, asPos, assert, assertNever, b64decode, createClient, deprecate, deprecateIf, errorIf, freeze, isChildCrdt, isJsonArray, isJsonObject, isJsonScalar, isPlainObject, isRootCrdt, legacy_patchImmutableObject, lsonToJson, makePosition, nn, patchLiveObjectKey, shallow, throwUsageError, toPlainLson, tryParseJson, withTimeout };
|
package/dist/index.js
CHANGED
|
@@ -17,18 +17,6 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
20
|
var __async = (__this, __arguments, generator) => {
|
|
33
21
|
return new Promise((resolve, reject) => {
|
|
34
22
|
var fulfilled = (value) => {
|
|
@@ -157,7 +145,7 @@ var onMessageFromPanel = eventSource.observable;
|
|
|
157
145
|
// src/devtools/index.ts
|
|
158
146
|
var VERSION = true ? (
|
|
159
147
|
/* istanbul ignore next */
|
|
160
|
-
"1.1.
|
|
148
|
+
"1.1.1-internal1"
|
|
161
149
|
) : "dev";
|
|
162
150
|
var _devtoolsSetupHasRun = false;
|
|
163
151
|
function setupDevTools(getAllRooms) {
|
|
@@ -3924,13 +3912,6 @@ function isJsonObject(data) {
|
|
|
3924
3912
|
}
|
|
3925
3913
|
|
|
3926
3914
|
// src/protocol/AuthToken.ts
|
|
3927
|
-
function hasJwtMeta(data) {
|
|
3928
|
-
if (!isPlainObject(data)) {
|
|
3929
|
-
return false;
|
|
3930
|
-
}
|
|
3931
|
-
const { iat, exp } = data;
|
|
3932
|
-
return typeof iat === "number" && typeof exp === "number";
|
|
3933
|
-
}
|
|
3934
3915
|
function isTokenExpired(token) {
|
|
3935
3916
|
const now = Date.now() / 1e3;
|
|
3936
3917
|
const valid = now <= token.exp - 300 && now >= token.iat - 300;
|
|
@@ -3939,44 +3920,23 @@ function isTokenExpired(token) {
|
|
|
3939
3920
|
function isStringList(value) {
|
|
3940
3921
|
return Array.isArray(value) && value.every((i) => typeof i === "string");
|
|
3941
3922
|
}
|
|
3942
|
-
function
|
|
3943
|
-
return typeof data.
|
|
3923
|
+
function isMinimalTokenPayload(data) {
|
|
3924
|
+
return isPlainObject(data) && typeof data.iat === "number" && typeof data.exp === "number" && typeof data.actor === "number" && (data.id === void 0 || typeof data.id === "string") && isStringList(data.scopes);
|
|
3944
3925
|
}
|
|
3945
|
-
function
|
|
3946
|
-
|
|
3947
|
-
}
|
|
3948
|
-
function isAuthToken(data) {
|
|
3949
|
-
return isAppOnlyAuthToken(data) || isRoomAuthToken(data);
|
|
3950
|
-
}
|
|
3951
|
-
function parseJwtToken(token) {
|
|
3952
|
-
const tokenParts = token.split(".");
|
|
3926
|
+
function parseAuthToken(rawTokenString) {
|
|
3927
|
+
const tokenParts = rawTokenString.split(".");
|
|
3953
3928
|
if (tokenParts.length !== 3) {
|
|
3954
3929
|
throw new Error("Authentication error: invalid JWT token");
|
|
3955
3930
|
}
|
|
3956
|
-
const
|
|
3957
|
-
if (
|
|
3958
|
-
return data;
|
|
3959
|
-
} else {
|
|
3960
|
-
throw new Error("Authentication error: missing JWT metadata");
|
|
3961
|
-
}
|
|
3962
|
-
}
|
|
3963
|
-
function parseRoomAuthToken(tokenString) {
|
|
3964
|
-
const data = parseJwtToken(tokenString);
|
|
3965
|
-
if (!(data && isRoomAuthToken(data))) {
|
|
3931
|
+
const payload = tryParseJson(b64decode(tokenParts[1]));
|
|
3932
|
+
if (!(payload && isMinimalTokenPayload(payload))) {
|
|
3966
3933
|
throw new Error(
|
|
3967
3934
|
"Authentication error: we expected a room token but did not get one. Hint: if you are using a callback, ensure the room is passed when creating the token. For more information: https://liveblocks.io/docs/api-reference/liveblocks-client#createClientCallback"
|
|
3968
3935
|
);
|
|
3969
3936
|
}
|
|
3970
|
-
const _a = data, {
|
|
3971
|
-
maxConnections: _legacyField
|
|
3972
|
-
} = _a, parsedToken = __objRest(_a, [
|
|
3973
|
-
// If this legacy field is found on the token, pretend it wasn't there,
|
|
3974
|
-
// to make all internally used token payloads uniform
|
|
3975
|
-
"maxConnections"
|
|
3976
|
-
]);
|
|
3977
3937
|
return {
|
|
3978
|
-
raw:
|
|
3979
|
-
parsed:
|
|
3938
|
+
raw: rawTokenString,
|
|
3939
|
+
parsed: payload
|
|
3980
3940
|
};
|
|
3981
3941
|
}
|
|
3982
3942
|
|
|
@@ -3986,6 +3946,8 @@ var ClientMsgCode = /* @__PURE__ */ ((ClientMsgCode2) => {
|
|
|
3986
3946
|
ClientMsgCode2[ClientMsgCode2["BROADCAST_EVENT"] = 103] = "BROADCAST_EVENT";
|
|
3987
3947
|
ClientMsgCode2[ClientMsgCode2["FETCH_STORAGE"] = 200] = "FETCH_STORAGE";
|
|
3988
3948
|
ClientMsgCode2[ClientMsgCode2["UPDATE_STORAGE"] = 201] = "UPDATE_STORAGE";
|
|
3949
|
+
ClientMsgCode2[ClientMsgCode2["FETCH_YDOC"] = 300] = "FETCH_YDOC";
|
|
3950
|
+
ClientMsgCode2[ClientMsgCode2["UPDATE_YDOC"] = 301] = "UPDATE_YDOC";
|
|
3989
3951
|
return ClientMsgCode2;
|
|
3990
3952
|
})(ClientMsgCode || {});
|
|
3991
3953
|
|
|
@@ -3999,6 +3961,7 @@ var ServerMsgCode = /* @__PURE__ */ ((ServerMsgCode2) => {
|
|
|
3999
3961
|
ServerMsgCode2[ServerMsgCode2["INITIAL_STORAGE_STATE"] = 200] = "INITIAL_STORAGE_STATE";
|
|
4000
3962
|
ServerMsgCode2[ServerMsgCode2["UPDATE_STORAGE"] = 201] = "UPDATE_STORAGE";
|
|
4001
3963
|
ServerMsgCode2[ServerMsgCode2["REJECT_STORAGE_OP"] = 299] = "REJECT_STORAGE_OP";
|
|
3964
|
+
ServerMsgCode2[ServerMsgCode2["UPDATE_YDOC"] = 300] = "UPDATE_YDOC";
|
|
4002
3965
|
return ServerMsgCode2;
|
|
4003
3966
|
})(ServerMsgCode || {});
|
|
4004
3967
|
|
|
@@ -5311,7 +5274,7 @@ function makeCreateSocketDelegateForRoom(liveblocksServer, WebSocketPolyfill) {
|
|
|
5311
5274
|
// @ts-ignore (__PACKAGE_VERSION__ will be injected by the build script)
|
|
5312
5275
|
true ? (
|
|
5313
5276
|
/* istanbul ignore next */
|
|
5314
|
-
"1.1.
|
|
5277
|
+
"1.1.1-internal1"
|
|
5315
5278
|
) : "dev"}`
|
|
5316
5279
|
);
|
|
5317
5280
|
};
|
|
@@ -5342,7 +5305,7 @@ function makeAuthDelegateForRoom(roomId, authentication, fetchPolyfill) {
|
|
|
5342
5305
|
return fetchAuthEndpoint(fetcher, authentication.url, {
|
|
5343
5306
|
room: roomId,
|
|
5344
5307
|
publicApiKey: authentication.publicApiKey
|
|
5345
|
-
}).then(({ token }) =>
|
|
5308
|
+
}).then(({ token }) => parseAuthToken(token));
|
|
5346
5309
|
});
|
|
5347
5310
|
} else if (authentication.type === "private") {
|
|
5348
5311
|
return () => __async(this, null, function* () {
|
|
@@ -5353,7 +5316,7 @@ function makeAuthDelegateForRoom(roomId, authentication, fetchPolyfill) {
|
|
|
5353
5316
|
}
|
|
5354
5317
|
return fetchAuthEndpoint(fetcher, authentication.url, {
|
|
5355
5318
|
room: roomId
|
|
5356
|
-
}).then(({ token }) =>
|
|
5319
|
+
}).then(({ token }) => parseAuthToken(token));
|
|
5357
5320
|
});
|
|
5358
5321
|
} else if (authentication.type === "custom") {
|
|
5359
5322
|
return () => __async(this, null, function* () {
|
|
@@ -5363,7 +5326,7 @@ function makeAuthDelegateForRoom(roomId, authentication, fetchPolyfill) {
|
|
|
5363
5326
|
'We expect the authentication callback to return a token, but it does not. Hint: the return value should look like: { token: "..." }'
|
|
5364
5327
|
);
|
|
5365
5328
|
}
|
|
5366
|
-
return
|
|
5329
|
+
return parseAuthToken(response.token);
|
|
5367
5330
|
});
|
|
5368
5331
|
} else {
|
|
5369
5332
|
throw new Error("Internal error. Unexpected authentication type");
|
|
@@ -5964,7 +5927,4 @@ var WebsocketCloseCodes = /* @__PURE__ */ ((WebsocketCloseCodes2) => {
|
|
|
5964
5927
|
|
|
5965
5928
|
|
|
5966
5929
|
|
|
5967
|
-
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
exports.ClientMsgCode = ClientMsgCode; exports.CrdtType = CrdtType; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.OpCode = OpCode; exports.ServerMsgCode = ServerMsgCode; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.asArrayWithLegacyMethods = asArrayWithLegacyMethods; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.b64decode = b64decode; exports.createClient = createClient; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.errorIf = errorIf; exports.freeze = freeze; exports.isAppOnlyAuthToken = isAppOnlyAuthToken; exports.isAuthToken = isAuthToken; exports.isChildCrdt = isChildCrdt; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isPlainObject = isPlainObject; exports.isRoomAuthToken = isRoomAuthToken; exports.isRootCrdt = isRootCrdt; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makePosition = makePosition; exports.nn = nn; exports.patchLiveObjectKey = patchLiveObjectKey; exports.shallow = shallow; exports.throwUsageError = throwUsageError; exports.tryParseJson = tryParseJson; exports.withTimeout = withTimeout;
|
|
5930
|
+
exports.ClientMsgCode = ClientMsgCode; exports.CrdtType = CrdtType; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.OpCode = OpCode; exports.ServerMsgCode = ServerMsgCode; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.asArrayWithLegacyMethods = asArrayWithLegacyMethods; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.b64decode = b64decode; exports.createClient = createClient; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.errorIf = errorIf; exports.freeze = freeze; exports.isChildCrdt = isChildCrdt; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makePosition = makePosition; exports.nn = nn; exports.patchLiveObjectKey = patchLiveObjectKey; exports.shallow = shallow; exports.throwUsageError = throwUsageError; exports.tryParseJson = tryParseJson; exports.withTimeout = withTimeout;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liveblocks/core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1-internal1",
|
|
4
4
|
"description": "Shared code and foundational internals for Liveblocks",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
"dev": "tsup --watch",
|
|
22
22
|
"build": "tsup",
|
|
23
|
-
"format": "eslint --fix src
|
|
23
|
+
"format": "(eslint --fix src/ || true) && prettier --write src/",
|
|
24
24
|
"lint": "eslint src/",
|
|
25
25
|
"test": "jest --silent --verbose --color=always",
|
|
26
26
|
"test:types": "tsd",
|