@liveblocks/client 0.15.0-alpha.4 → 0.15.0
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/lib/esm/index.js +25 -40
- package/lib/esm/index.mjs +25 -40
- package/lib/index.js +56 -197
- package/package.json +3 -1
package/lib/esm/index.js
CHANGED
|
@@ -285,9 +285,6 @@ const _LiveRegister = class extends AbstractCrdt {
|
|
|
285
285
|
_apply(op, isLocal) {
|
|
286
286
|
return super._apply(op, isLocal);
|
|
287
287
|
}
|
|
288
|
-
_getType() {
|
|
289
|
-
return "LiveRegister";
|
|
290
|
-
}
|
|
291
288
|
};
|
|
292
289
|
let LiveRegister = _LiveRegister;
|
|
293
290
|
_data = new WeakMap();
|
|
@@ -469,9 +466,6 @@ const _LiveList = class extends AbstractCrdt {
|
|
|
469
466
|
_apply(op, isLocal) {
|
|
470
467
|
return super._apply(op, isLocal);
|
|
471
468
|
}
|
|
472
|
-
_getType() {
|
|
473
|
-
return "LiveList";
|
|
474
|
-
}
|
|
475
469
|
_toSerializedCrdt() {
|
|
476
470
|
var _a;
|
|
477
471
|
return {
|
|
@@ -830,9 +824,6 @@ const _LiveMap = class extends AbstractCrdt {
|
|
|
830
824
|
};
|
|
831
825
|
return { modified: storageUpdate, reverse };
|
|
832
826
|
}
|
|
833
|
-
_getType() {
|
|
834
|
-
return "LiveMap";
|
|
835
|
-
}
|
|
836
827
|
_toSerializedCrdt() {
|
|
837
828
|
var _a;
|
|
838
829
|
return {
|
|
@@ -1361,9 +1352,6 @@ const _LiveObject = class extends AbstractCrdt {
|
|
|
1361
1352
|
data: this.toObject()
|
|
1362
1353
|
};
|
|
1363
1354
|
}
|
|
1364
|
-
_getType() {
|
|
1365
|
-
return "LiveObject";
|
|
1366
|
-
}
|
|
1367
1355
|
toObject() {
|
|
1368
1356
|
return Object.fromEntries(__privateGet(this, _map));
|
|
1369
1357
|
}
|
|
@@ -1625,15 +1613,12 @@ function makeOthers(presenceMap) {
|
|
|
1625
1613
|
}
|
|
1626
1614
|
function makeStateMachine(state, context, mockedEffects) {
|
|
1627
1615
|
const effects = mockedEffects || {
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
const { token } = await auth(context.room);
|
|
1616
|
+
authenticate(auth, createWebSocket) {
|
|
1617
|
+
return auth(context.room).then(({ token }) => {
|
|
1631
1618
|
const parsedToken = parseToken(token);
|
|
1632
1619
|
const socket = createWebSocket(token);
|
|
1633
1620
|
authenticationSuccess(parsedToken, socket);
|
|
1634
|
-
}
|
|
1635
|
-
authenticationFailure(er);
|
|
1636
|
-
}
|
|
1621
|
+
}).catch((er) => authenticationFailure(er));
|
|
1637
1622
|
},
|
|
1638
1623
|
send(messageOrMessages) {
|
|
1639
1624
|
if (state.socket == null) {
|
|
@@ -2332,21 +2317,22 @@ See v0.13 release notes for more information.
|
|
|
2332
2317
|
}
|
|
2333
2318
|
let _getInitialStatePromise = null;
|
|
2334
2319
|
let _getInitialStateResolver = null;
|
|
2335
|
-
|
|
2320
|
+
function getStorage() {
|
|
2336
2321
|
if (state.root) {
|
|
2337
|
-
return {
|
|
2322
|
+
return new Promise((resolve) => resolve({
|
|
2338
2323
|
root: state.root
|
|
2339
|
-
};
|
|
2324
|
+
}));
|
|
2340
2325
|
}
|
|
2341
2326
|
if (_getInitialStatePromise == null) {
|
|
2342
2327
|
state.buffer.messages.push({ type: ClientMessageType.FetchStorage });
|
|
2343
2328
|
tryFlushing();
|
|
2344
2329
|
_getInitialStatePromise = new Promise((resolve) => _getInitialStateResolver = resolve);
|
|
2345
2330
|
}
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2331
|
+
return _getInitialStatePromise.then(() => {
|
|
2332
|
+
return {
|
|
2333
|
+
root: state.root
|
|
2334
|
+
};
|
|
2335
|
+
});
|
|
2350
2336
|
}
|
|
2351
2337
|
function undo() {
|
|
2352
2338
|
if (state.isBatching) {
|
|
@@ -2606,27 +2592,26 @@ function prepareAuthEndpoint(authentication, fetchPolyfill) {
|
|
|
2606
2592
|
}
|
|
2607
2593
|
throw new Error("Internal error. Unexpected authentication type");
|
|
2608
2594
|
}
|
|
2609
|
-
|
|
2610
|
-
|
|
2595
|
+
function fetchAuthEndpoint(fetch2, endpoint, body) {
|
|
2596
|
+
return fetch2(endpoint, {
|
|
2611
2597
|
method: "POST",
|
|
2612
2598
|
headers: {
|
|
2613
2599
|
"Content-Type": "application/json"
|
|
2614
2600
|
},
|
|
2615
2601
|
body: JSON.stringify(body)
|
|
2602
|
+
}).then((res) => {
|
|
2603
|
+
if (!res.ok) {
|
|
2604
|
+
throw new AuthenticationError(`Expected a status 200 but got ${res.status} when doing a POST request on "${endpoint}"`);
|
|
2605
|
+
}
|
|
2606
|
+
return res.json().catch((er) => {
|
|
2607
|
+
throw new AuthenticationError(`Expected a json when doing a POST request on "${endpoint}". ${er}`);
|
|
2608
|
+
});
|
|
2609
|
+
}).then((authResponse) => {
|
|
2610
|
+
if (typeof authResponse.token !== "string") {
|
|
2611
|
+
throw new AuthenticationError(`Expected a json with a string token when doing a POST request on "${endpoint}", but got ${JSON.stringify(authResponse)}`);
|
|
2612
|
+
}
|
|
2613
|
+
return authResponse;
|
|
2616
2614
|
});
|
|
2617
|
-
if (!res.ok) {
|
|
2618
|
-
throw new AuthenticationError(`Authentication error. Liveblocks could not parse the response of your authentication "${endpoint}"`);
|
|
2619
|
-
}
|
|
2620
|
-
let authResponse = null;
|
|
2621
|
-
try {
|
|
2622
|
-
authResponse = await res.json();
|
|
2623
|
-
} catch (er) {
|
|
2624
|
-
throw new AuthenticationError(`Authentication error. Liveblocks could not parse the response of your authentication "${endpoint}"`);
|
|
2625
|
-
}
|
|
2626
|
-
if (typeof authResponse.token !== "string") {
|
|
2627
|
-
throw new AuthenticationError(`Authentication error. Liveblocks could not parse the response of your authentication "${endpoint}"`);
|
|
2628
|
-
}
|
|
2629
|
-
return authResponse;
|
|
2630
2615
|
}
|
|
2631
2616
|
class AuthenticationError extends Error {
|
|
2632
2617
|
constructor(message) {
|
package/lib/esm/index.mjs
CHANGED
|
@@ -285,9 +285,6 @@ const _LiveRegister = class extends AbstractCrdt {
|
|
|
285
285
|
_apply(op, isLocal) {
|
|
286
286
|
return super._apply(op, isLocal);
|
|
287
287
|
}
|
|
288
|
-
_getType() {
|
|
289
|
-
return "LiveRegister";
|
|
290
|
-
}
|
|
291
288
|
};
|
|
292
289
|
let LiveRegister = _LiveRegister;
|
|
293
290
|
_data = new WeakMap();
|
|
@@ -469,9 +466,6 @@ const _LiveList = class extends AbstractCrdt {
|
|
|
469
466
|
_apply(op, isLocal) {
|
|
470
467
|
return super._apply(op, isLocal);
|
|
471
468
|
}
|
|
472
|
-
_getType() {
|
|
473
|
-
return "LiveList";
|
|
474
|
-
}
|
|
475
469
|
_toSerializedCrdt() {
|
|
476
470
|
var _a;
|
|
477
471
|
return {
|
|
@@ -830,9 +824,6 @@ const _LiveMap = class extends AbstractCrdt {
|
|
|
830
824
|
};
|
|
831
825
|
return { modified: storageUpdate, reverse };
|
|
832
826
|
}
|
|
833
|
-
_getType() {
|
|
834
|
-
return "LiveMap";
|
|
835
|
-
}
|
|
836
827
|
_toSerializedCrdt() {
|
|
837
828
|
var _a;
|
|
838
829
|
return {
|
|
@@ -1361,9 +1352,6 @@ const _LiveObject = class extends AbstractCrdt {
|
|
|
1361
1352
|
data: this.toObject()
|
|
1362
1353
|
};
|
|
1363
1354
|
}
|
|
1364
|
-
_getType() {
|
|
1365
|
-
return "LiveObject";
|
|
1366
|
-
}
|
|
1367
1355
|
toObject() {
|
|
1368
1356
|
return Object.fromEntries(__privateGet(this, _map));
|
|
1369
1357
|
}
|
|
@@ -1625,15 +1613,12 @@ function makeOthers(presenceMap) {
|
|
|
1625
1613
|
}
|
|
1626
1614
|
function makeStateMachine(state, context, mockedEffects) {
|
|
1627
1615
|
const effects = mockedEffects || {
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
const { token } = await auth(context.room);
|
|
1616
|
+
authenticate(auth, createWebSocket) {
|
|
1617
|
+
return auth(context.room).then(({ token }) => {
|
|
1631
1618
|
const parsedToken = parseToken(token);
|
|
1632
1619
|
const socket = createWebSocket(token);
|
|
1633
1620
|
authenticationSuccess(parsedToken, socket);
|
|
1634
|
-
}
|
|
1635
|
-
authenticationFailure(er);
|
|
1636
|
-
}
|
|
1621
|
+
}).catch((er) => authenticationFailure(er));
|
|
1637
1622
|
},
|
|
1638
1623
|
send(messageOrMessages) {
|
|
1639
1624
|
if (state.socket == null) {
|
|
@@ -2332,21 +2317,22 @@ See v0.13 release notes for more information.
|
|
|
2332
2317
|
}
|
|
2333
2318
|
let _getInitialStatePromise = null;
|
|
2334
2319
|
let _getInitialStateResolver = null;
|
|
2335
|
-
|
|
2320
|
+
function getStorage() {
|
|
2336
2321
|
if (state.root) {
|
|
2337
|
-
return {
|
|
2322
|
+
return new Promise((resolve) => resolve({
|
|
2338
2323
|
root: state.root
|
|
2339
|
-
};
|
|
2324
|
+
}));
|
|
2340
2325
|
}
|
|
2341
2326
|
if (_getInitialStatePromise == null) {
|
|
2342
2327
|
state.buffer.messages.push({ type: ClientMessageType.FetchStorage });
|
|
2343
2328
|
tryFlushing();
|
|
2344
2329
|
_getInitialStatePromise = new Promise((resolve) => _getInitialStateResolver = resolve);
|
|
2345
2330
|
}
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2331
|
+
return _getInitialStatePromise.then(() => {
|
|
2332
|
+
return {
|
|
2333
|
+
root: state.root
|
|
2334
|
+
};
|
|
2335
|
+
});
|
|
2350
2336
|
}
|
|
2351
2337
|
function undo() {
|
|
2352
2338
|
if (state.isBatching) {
|
|
@@ -2606,27 +2592,26 @@ function prepareAuthEndpoint(authentication, fetchPolyfill) {
|
|
|
2606
2592
|
}
|
|
2607
2593
|
throw new Error("Internal error. Unexpected authentication type");
|
|
2608
2594
|
}
|
|
2609
|
-
|
|
2610
|
-
|
|
2595
|
+
function fetchAuthEndpoint(fetch2, endpoint, body) {
|
|
2596
|
+
return fetch2(endpoint, {
|
|
2611
2597
|
method: "POST",
|
|
2612
2598
|
headers: {
|
|
2613
2599
|
"Content-Type": "application/json"
|
|
2614
2600
|
},
|
|
2615
2601
|
body: JSON.stringify(body)
|
|
2602
|
+
}).then((res) => {
|
|
2603
|
+
if (!res.ok) {
|
|
2604
|
+
throw new AuthenticationError(`Expected a status 200 but got ${res.status} when doing a POST request on "${endpoint}"`);
|
|
2605
|
+
}
|
|
2606
|
+
return res.json().catch((er) => {
|
|
2607
|
+
throw new AuthenticationError(`Expected a json when doing a POST request on "${endpoint}". ${er}`);
|
|
2608
|
+
});
|
|
2609
|
+
}).then((authResponse) => {
|
|
2610
|
+
if (typeof authResponse.token !== "string") {
|
|
2611
|
+
throw new AuthenticationError(`Expected a json with a string token when doing a POST request on "${endpoint}", but got ${JSON.stringify(authResponse)}`);
|
|
2612
|
+
}
|
|
2613
|
+
return authResponse;
|
|
2616
2614
|
});
|
|
2617
|
-
if (!res.ok) {
|
|
2618
|
-
throw new AuthenticationError(`Authentication error. Liveblocks could not parse the response of your authentication "${endpoint}"`);
|
|
2619
|
-
}
|
|
2620
|
-
let authResponse = null;
|
|
2621
|
-
try {
|
|
2622
|
-
authResponse = await res.json();
|
|
2623
|
-
} catch (er) {
|
|
2624
|
-
throw new AuthenticationError(`Authentication error. Liveblocks could not parse the response of your authentication "${endpoint}"`);
|
|
2625
|
-
}
|
|
2626
|
-
if (typeof authResponse.token !== "string") {
|
|
2627
|
-
throw new AuthenticationError(`Authentication error. Liveblocks could not parse the response of your authentication "${endpoint}"`);
|
|
2628
|
-
}
|
|
2629
|
-
return authResponse;
|
|
2630
2615
|
}
|
|
2631
2616
|
class AuthenticationError extends Error {
|
|
2632
2617
|
constructor(message) {
|
package/lib/index.js
CHANGED
|
@@ -2,42 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
6
|
-
try {
|
|
7
|
-
var info = gen[key](arg);
|
|
8
|
-
var value = info.value;
|
|
9
|
-
} catch (error) {
|
|
10
|
-
reject(error);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (info.done) {
|
|
15
|
-
resolve(value);
|
|
16
|
-
} else {
|
|
17
|
-
Promise.resolve(value).then(_next, _throw);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function _asyncToGenerator(fn) {
|
|
22
|
-
return function () {
|
|
23
|
-
var self = this,
|
|
24
|
-
args = arguments;
|
|
25
|
-
return new Promise(function (resolve, reject) {
|
|
26
|
-
var gen = fn.apply(self, args);
|
|
27
|
-
|
|
28
|
-
function _next(value) {
|
|
29
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function _throw(err) {
|
|
33
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
_next(undefined);
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
5
|
function _defineProperties(target, props) {
|
|
42
6
|
for (var i = 0; i < props.length; i++) {
|
|
43
7
|
var descriptor = props[i];
|
|
@@ -627,10 +591,6 @@ var LiveRegister = function (_AbstractCrdt) {
|
|
|
627
591
|
return _AbstractCrdt.prototype._apply.call(this, op, isLocal);
|
|
628
592
|
};
|
|
629
593
|
|
|
630
|
-
_proto._getType = function _getType() {
|
|
631
|
-
return "LiveRegister";
|
|
632
|
-
};
|
|
633
|
-
|
|
634
594
|
_createClass(LiveRegister, [{
|
|
635
595
|
key: "data",
|
|
636
596
|
get: function get() {
|
|
@@ -917,10 +877,6 @@ var LiveList = function (_AbstractCrdt) {
|
|
|
917
877
|
return _AbstractCrdt.prototype._apply.call(this, op, isLocal);
|
|
918
878
|
};
|
|
919
879
|
|
|
920
|
-
_proto._getType = function _getType() {
|
|
921
|
-
return "LiveList";
|
|
922
|
-
};
|
|
923
|
-
|
|
924
880
|
_proto._toSerializedCrdt = function _toSerializedCrdt() {
|
|
925
881
|
var _this$_parent;
|
|
926
882
|
|
|
@@ -1445,10 +1401,6 @@ var LiveMap = function (_AbstractCrdt) {
|
|
|
1445
1401
|
};
|
|
1446
1402
|
};
|
|
1447
1403
|
|
|
1448
|
-
_proto._getType = function _getType() {
|
|
1449
|
-
return "LiveMap";
|
|
1450
|
-
};
|
|
1451
|
-
|
|
1452
1404
|
_proto._toSerializedCrdt = function _toSerializedCrdt() {
|
|
1453
1405
|
var _this$_parent;
|
|
1454
1406
|
|
|
@@ -2143,10 +2095,6 @@ var LiveObject = function (_AbstractCrdt) {
|
|
|
2143
2095
|
};
|
|
2144
2096
|
};
|
|
2145
2097
|
|
|
2146
|
-
_proto._getType = function _getType() {
|
|
2147
|
-
return "LiveObject";
|
|
2148
|
-
};
|
|
2149
|
-
|
|
2150
2098
|
_proto.toObject = function toObject() {
|
|
2151
2099
|
return Object.fromEntries(_classPrivateFieldGet(this, _map));
|
|
2152
2100
|
};
|
|
@@ -2485,38 +2433,14 @@ function makeOthers(presenceMap) {
|
|
|
2485
2433
|
function makeStateMachine(state, context, mockedEffects) {
|
|
2486
2434
|
var effects = mockedEffects || {
|
|
2487
2435
|
authenticate: function authenticate(auth, createWebSocket) {
|
|
2488
|
-
return
|
|
2489
|
-
var
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
_context.next = 3;
|
|
2497
|
-
return auth(context.room);
|
|
2498
|
-
|
|
2499
|
-
case 3:
|
|
2500
|
-
_yield$auth = _context.sent;
|
|
2501
|
-
_token = _yield$auth.token;
|
|
2502
|
-
parsedToken = parseToken(_token);
|
|
2503
|
-
socket = createWebSocket(_token);
|
|
2504
|
-
authenticationSuccess(parsedToken, socket);
|
|
2505
|
-
_context.next = 13;
|
|
2506
|
-
break;
|
|
2507
|
-
|
|
2508
|
-
case 10:
|
|
2509
|
-
_context.prev = 10;
|
|
2510
|
-
_context.t0 = _context["catch"](0);
|
|
2511
|
-
authenticationFailure(_context.t0);
|
|
2512
|
-
|
|
2513
|
-
case 13:
|
|
2514
|
-
case "end":
|
|
2515
|
-
return _context.stop();
|
|
2516
|
-
}
|
|
2517
|
-
}
|
|
2518
|
-
}, _callee, null, [[0, 10]]);
|
|
2519
|
-
}))();
|
|
2436
|
+
return auth(context.room).then(function (_ref2) {
|
|
2437
|
+
var token = _ref2.token;
|
|
2438
|
+
var parsedToken = parseToken(token);
|
|
2439
|
+
var socket = createWebSocket(token);
|
|
2440
|
+
authenticationSuccess(parsedToken, socket);
|
|
2441
|
+
}).catch(function (er) {
|
|
2442
|
+
return authenticationFailure(er);
|
|
2443
|
+
});
|
|
2520
2444
|
},
|
|
2521
2445
|
send: function send(messageOrMessages) {
|
|
2522
2446
|
if (state.socket == null) {
|
|
@@ -2691,13 +2615,13 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
2691
2615
|
}
|
|
2692
2616
|
}
|
|
2693
2617
|
|
|
2694
|
-
function notify(
|
|
2695
|
-
var
|
|
2696
|
-
storageUpdates =
|
|
2697
|
-
|
|
2698
|
-
presence =
|
|
2699
|
-
|
|
2700
|
-
others =
|
|
2618
|
+
function notify(_ref3) {
|
|
2619
|
+
var _ref3$storageUpdates = _ref3.storageUpdates,
|
|
2620
|
+
storageUpdates = _ref3$storageUpdates === void 0 ? new Map() : _ref3$storageUpdates,
|
|
2621
|
+
_ref3$presence = _ref3.presence,
|
|
2622
|
+
presence = _ref3$presence === void 0 ? false : _ref3$presence,
|
|
2623
|
+
_ref3$others = _ref3.others,
|
|
2624
|
+
others = _ref3$others === void 0 ? [] : _ref3$others;
|
|
2701
2625
|
|
|
2702
2626
|
if (others.length > 0) {
|
|
2703
2627
|
state.others = makeOthers(state.users);
|
|
@@ -3502,51 +3426,29 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
3502
3426
|
var _getInitialStateResolver = null;
|
|
3503
3427
|
|
|
3504
3428
|
function getStorage() {
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
switch (_context2.prev = _context2.next) {
|
|
3513
|
-
case 0:
|
|
3514
|
-
if (!state.root) {
|
|
3515
|
-
_context2.next = 2;
|
|
3516
|
-
break;
|
|
3517
|
-
}
|
|
3518
|
-
|
|
3519
|
-
return _context2.abrupt("return", {
|
|
3520
|
-
root: state.root
|
|
3521
|
-
});
|
|
3522
|
-
|
|
3523
|
-
case 2:
|
|
3524
|
-
if (_getInitialStatePromise == null) {
|
|
3525
|
-
state.buffer.messages.push({
|
|
3526
|
-
type: ClientMessageType.FetchStorage
|
|
3527
|
-
});
|
|
3528
|
-
tryFlushing();
|
|
3529
|
-
_getInitialStatePromise = new Promise(function (resolve) {
|
|
3530
|
-
return _getInitialStateResolver = resolve;
|
|
3531
|
-
});
|
|
3532
|
-
}
|
|
3533
|
-
|
|
3534
|
-
_context2.next = 5;
|
|
3535
|
-
return _getInitialStatePromise;
|
|
3429
|
+
if (state.root) {
|
|
3430
|
+
return new Promise(function (resolve) {
|
|
3431
|
+
return resolve({
|
|
3432
|
+
root: state.root
|
|
3433
|
+
});
|
|
3434
|
+
});
|
|
3435
|
+
}
|
|
3536
3436
|
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3437
|
+
if (_getInitialStatePromise == null) {
|
|
3438
|
+
state.buffer.messages.push({
|
|
3439
|
+
type: ClientMessageType.FetchStorage
|
|
3440
|
+
});
|
|
3441
|
+
tryFlushing();
|
|
3442
|
+
_getInitialStatePromise = new Promise(function (resolve) {
|
|
3443
|
+
return _getInitialStateResolver = resolve;
|
|
3444
|
+
});
|
|
3445
|
+
}
|
|
3541
3446
|
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
}, _callee2);
|
|
3548
|
-
}));
|
|
3549
|
-
return _getStorage.apply(this, arguments);
|
|
3447
|
+
return _getInitialStatePromise.then(function () {
|
|
3448
|
+
return {
|
|
3449
|
+
root: state.root
|
|
3450
|
+
};
|
|
3451
|
+
});
|
|
3550
3452
|
}
|
|
3551
3453
|
|
|
3552
3454
|
function undo() {
|
|
@@ -3868,71 +3770,28 @@ function prepareAuthEndpoint(authentication, fetchPolyfill) {
|
|
|
3868
3770
|
throw new Error("Internal error. Unexpected authentication type");
|
|
3869
3771
|
}
|
|
3870
3772
|
|
|
3871
|
-
function fetchAuthEndpoint(
|
|
3872
|
-
return
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
_context3.next = 2;
|
|
3883
|
-
return fetch(endpoint, {
|
|
3884
|
-
method: "POST",
|
|
3885
|
-
headers: {
|
|
3886
|
-
"Content-Type": "application/json"
|
|
3887
|
-
},
|
|
3888
|
-
body: JSON.stringify(body)
|
|
3889
|
-
});
|
|
3890
|
-
|
|
3891
|
-
case 2:
|
|
3892
|
-
res = _context3.sent;
|
|
3893
|
-
|
|
3894
|
-
if (res.ok) {
|
|
3895
|
-
_context3.next = 5;
|
|
3896
|
-
break;
|
|
3897
|
-
}
|
|
3898
|
-
|
|
3899
|
-
throw new AuthenticationError("Authentication error. Liveblocks could not parse the response of your authentication \"" + endpoint + "\"");
|
|
3900
|
-
|
|
3901
|
-
case 5:
|
|
3902
|
-
authResponse = null;
|
|
3903
|
-
_context3.prev = 6;
|
|
3904
|
-
_context3.next = 9;
|
|
3905
|
-
return res.json();
|
|
3906
|
-
|
|
3907
|
-
case 9:
|
|
3908
|
-
authResponse = _context3.sent;
|
|
3909
|
-
_context3.next = 15;
|
|
3910
|
-
break;
|
|
3911
|
-
|
|
3912
|
-
case 12:
|
|
3913
|
-
_context3.prev = 12;
|
|
3914
|
-
_context3.t0 = _context3["catch"](6);
|
|
3915
|
-
throw new AuthenticationError("Authentication error. Liveblocks could not parse the response of your authentication \"" + endpoint + "\"");
|
|
3916
|
-
|
|
3917
|
-
case 15:
|
|
3918
|
-
if (!(typeof authResponse.token !== "string")) {
|
|
3919
|
-
_context3.next = 17;
|
|
3920
|
-
break;
|
|
3921
|
-
}
|
|
3922
|
-
|
|
3923
|
-
throw new AuthenticationError("Authentication error. Liveblocks could not parse the response of your authentication \"" + endpoint + "\"");
|
|
3773
|
+
function fetchAuthEndpoint(fetch, endpoint, body) {
|
|
3774
|
+
return fetch(endpoint, {
|
|
3775
|
+
method: "POST",
|
|
3776
|
+
headers: {
|
|
3777
|
+
"Content-Type": "application/json"
|
|
3778
|
+
},
|
|
3779
|
+
body: JSON.stringify(body)
|
|
3780
|
+
}).then(function (res) {
|
|
3781
|
+
if (!res.ok) {
|
|
3782
|
+
throw new AuthenticationError("Expected a status 200 but got " + res.status + " when doing a POST request on \"" + endpoint + "\"");
|
|
3783
|
+
}
|
|
3924
3784
|
|
|
3925
|
-
|
|
3926
|
-
|
|
3785
|
+
return res.json().catch(function (er) {
|
|
3786
|
+
throw new AuthenticationError("Expected a json when doing a POST request on \"" + endpoint + "\". " + er);
|
|
3787
|
+
});
|
|
3788
|
+
}).then(function (authResponse) {
|
|
3789
|
+
if (typeof authResponse.token !== "string") {
|
|
3790
|
+
throw new AuthenticationError("Expected a json with a string token when doing a POST request on \"" + endpoint + "\", but got " + JSON.stringify(authResponse));
|
|
3791
|
+
}
|
|
3927
3792
|
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
return _context3.stop();
|
|
3931
|
-
}
|
|
3932
|
-
}
|
|
3933
|
-
}, _callee3, null, [[6, 12]]);
|
|
3934
|
-
}));
|
|
3935
|
-
return _fetchAuthEndpoint.apply(this, arguments);
|
|
3793
|
+
return authResponse;
|
|
3794
|
+
});
|
|
3936
3795
|
}
|
|
3937
3796
|
|
|
3938
3797
|
var AuthenticationError = function (_Error2) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liveblocks/client",
|
|
3
|
-
"version": "0.15.0
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -51,11 +51,13 @@
|
|
|
51
51
|
"babel-jest": "^26.6.3",
|
|
52
52
|
"jest": "^26.6.3",
|
|
53
53
|
"jest-each": "^27.5.1",
|
|
54
|
+
"msw": "^0.39.1",
|
|
54
55
|
"node-fetch": "2.6.7",
|
|
55
56
|
"rollup": "^2.68.0",
|
|
56
57
|
"rollup-plugin-dts": "^4.1.0",
|
|
57
58
|
"rollup-plugin-esbuild": "^4.8.2",
|
|
58
59
|
"typescript": "^4.4.0",
|
|
60
|
+
"whatwg-fetch": "^3.6.2",
|
|
59
61
|
"ws": "^8.5.0"
|
|
60
62
|
},
|
|
61
63
|
"repository": {
|