@liveblocks/core 1.3.1 → 1.3.3
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.mts +13 -3
- package/dist/index.d.ts +13 -3
- package/dist/index.js +42 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ var __export = (target, all) => {
|
|
|
6
6
|
|
|
7
7
|
// src/version.ts
|
|
8
8
|
var PKG_NAME = "@liveblocks/core";
|
|
9
|
-
var PKG_VERSION = "1.3.
|
|
9
|
+
var PKG_VERSION = "1.3.3";
|
|
10
10
|
var PKG_FORMAT = "esm";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -1281,6 +1281,7 @@ function parseAuthToken(rawTokenString) {
|
|
|
1281
1281
|
// src/auth-manager.ts
|
|
1282
1282
|
function createAuthManager(authOptions) {
|
|
1283
1283
|
const authentication = prepareAuthentication(authOptions);
|
|
1284
|
+
const seenTokens = /* @__PURE__ */ new Set();
|
|
1284
1285
|
const tokens = [];
|
|
1285
1286
|
const expiryTimes = [];
|
|
1286
1287
|
const requestPromises = /* @__PURE__ */ new Map();
|
|
@@ -1304,8 +1305,6 @@ function createAuthManager(authOptions) {
|
|
|
1304
1305
|
}
|
|
1305
1306
|
if (token.parsed.k === "id" /* ID_TOKEN */) {
|
|
1306
1307
|
return token;
|
|
1307
|
-
} else if (token.parsed.k === "sec-legacy" /* SECRET_LEGACY */) {
|
|
1308
|
-
return void 0;
|
|
1309
1308
|
} else if (token.parsed.k === "acc" /* ACCESS_TOKEN */) {
|
|
1310
1309
|
for (const [resource, scopes] of Object.entries(token.parsed.perms)) {
|
|
1311
1310
|
if (resource.includes("*") && roomId.startsWith(resource.replace("*", "")) || roomId === resource && hasCorrespondingScopes(requestedScope, scopes)) {
|
|
@@ -1327,7 +1326,13 @@ function createAuthManager(authOptions) {
|
|
|
1327
1326
|
const response = await fetchAuthEndpoint(fetcher, authentication.url, {
|
|
1328
1327
|
room: roomId
|
|
1329
1328
|
});
|
|
1330
|
-
|
|
1329
|
+
const parsed = parseAuthToken(response.token);
|
|
1330
|
+
if (seenTokens.has(parsed.raw)) {
|
|
1331
|
+
throw new StopRetrying(
|
|
1332
|
+
"The same Liveblocks auth token was issued from the backend before. Caching Liveblocks tokens is not supported."
|
|
1333
|
+
);
|
|
1334
|
+
}
|
|
1335
|
+
return parsed;
|
|
1331
1336
|
}
|
|
1332
1337
|
if (authentication.type === "custom") {
|
|
1333
1338
|
const response = await authentication.callback(roomId);
|
|
@@ -1368,8 +1373,11 @@ function createAuthManager(authOptions) {
|
|
|
1368
1373
|
const token = await currentPromise;
|
|
1369
1374
|
const BUFFER = 30;
|
|
1370
1375
|
const expiresAt = Math.floor(Date.now() / 1e3) + (token.parsed.exp - token.parsed.iat) - BUFFER;
|
|
1371
|
-
|
|
1372
|
-
|
|
1376
|
+
seenTokens.add(token.raw);
|
|
1377
|
+
if (token.parsed.k !== "sec-legacy" /* SECRET_LEGACY */) {
|
|
1378
|
+
tokens.push(token);
|
|
1379
|
+
expiryTimes.push(expiresAt);
|
|
1380
|
+
}
|
|
1373
1381
|
return { type: "secret", token };
|
|
1374
1382
|
} finally {
|
|
1375
1383
|
requestPromises.delete(roomId);
|
|
@@ -1703,7 +1711,9 @@ function createCommentsApi(roomId, getAuthValue, { serverEndpoint }) {
|
|
|
1703
1711
|
}
|
|
1704
1712
|
async function fetchApi(roomId2, endpoint, options) {
|
|
1705
1713
|
const authValue = await getAuthValue();
|
|
1706
|
-
const url = `${serverEndpoint}/c/rooms/${
|
|
1714
|
+
const url = `${serverEndpoint}/c/rooms/${encodeURIComponent(
|
|
1715
|
+
roomId2
|
|
1716
|
+
)}${endpoint}`;
|
|
1707
1717
|
return await fetch(url, {
|
|
1708
1718
|
...options,
|
|
1709
1719
|
headers: {
|
|
@@ -1749,7 +1759,7 @@ function createCommentsApi(roomId, getAuthValue, { serverEndpoint }) {
|
|
|
1749
1759
|
threadId
|
|
1750
1760
|
}) {
|
|
1751
1761
|
return fetchJson(
|
|
1752
|
-
`/threads/${threadId}/metadata`,
|
|
1762
|
+
`/threads/${encodeURIComponent(threadId)}/metadata`,
|
|
1753
1763
|
{
|
|
1754
1764
|
method: "POST",
|
|
1755
1765
|
headers: {
|
|
@@ -1764,16 +1774,19 @@ function createCommentsApi(roomId, getAuthValue, { serverEndpoint }) {
|
|
|
1764
1774
|
commentId,
|
|
1765
1775
|
body
|
|
1766
1776
|
}) {
|
|
1767
|
-
return fetchJson(
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
body
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
+
return fetchJson(
|
|
1778
|
+
`/threads/${encodeURIComponent(threadId)}/comments`,
|
|
1779
|
+
{
|
|
1780
|
+
method: "POST",
|
|
1781
|
+
headers: {
|
|
1782
|
+
"Content-Type": "application/json"
|
|
1783
|
+
},
|
|
1784
|
+
body: JSON.stringify({
|
|
1785
|
+
id: commentId,
|
|
1786
|
+
body
|
|
1787
|
+
})
|
|
1788
|
+
}
|
|
1789
|
+
);
|
|
1777
1790
|
}
|
|
1778
1791
|
function editComment({
|
|
1779
1792
|
threadId,
|
|
@@ -1781,7 +1794,9 @@ function createCommentsApi(roomId, getAuthValue, { serverEndpoint }) {
|
|
|
1781
1794
|
body
|
|
1782
1795
|
}) {
|
|
1783
1796
|
return fetchJson(
|
|
1784
|
-
`/threads/${threadId}/comments/${
|
|
1797
|
+
`/threads/${encodeURIComponent(threadId)}/comments/${encodeURIComponent(
|
|
1798
|
+
commentId
|
|
1799
|
+
)}`,
|
|
1785
1800
|
{
|
|
1786
1801
|
method: "POST",
|
|
1787
1802
|
headers: {
|
|
@@ -1797,9 +1812,14 @@ function createCommentsApi(roomId, getAuthValue, { serverEndpoint }) {
|
|
|
1797
1812
|
threadId,
|
|
1798
1813
|
commentId
|
|
1799
1814
|
}) {
|
|
1800
|
-
await fetchJson(
|
|
1801
|
-
|
|
1802
|
-
|
|
1815
|
+
await fetchJson(
|
|
1816
|
+
`/threads/${encodeURIComponent(threadId)}/comments/${encodeURIComponent(
|
|
1817
|
+
commentId
|
|
1818
|
+
)}`,
|
|
1819
|
+
{
|
|
1820
|
+
method: "DELETE"
|
|
1821
|
+
}
|
|
1822
|
+
);
|
|
1803
1823
|
}
|
|
1804
1824
|
return {
|
|
1805
1825
|
getThreads,
|