@liveblocks/core 2.8.2 → 2.9.0-rc1
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 +486 -456
- package/dist/index.d.ts +486 -456
- package/dist/index.js +113 -156
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +83 -126
- 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 = "2.
|
|
9
|
+
var PKG_VERSION = "2.9.0-rc1";
|
|
10
10
|
var PKG_FORMAT = "esm";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -2044,6 +2044,15 @@ function convertToInboxNotificationDeleteInfo(data) {
|
|
|
2044
2044
|
};
|
|
2045
2045
|
}
|
|
2046
2046
|
|
|
2047
|
+
// src/http-client.ts
|
|
2048
|
+
function getBearerTokenFromAuthValue(authValue) {
|
|
2049
|
+
if (authValue.type === "public") {
|
|
2050
|
+
return authValue.publicApiKey;
|
|
2051
|
+
} else {
|
|
2052
|
+
return authValue.token.raw;
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
|
|
2047
2056
|
// src/lib/url.ts
|
|
2048
2057
|
function toURLSearchParams(params) {
|
|
2049
2058
|
const result = new URLSearchParams();
|
|
@@ -2068,7 +2077,6 @@ function url(strings, ...values) {
|
|
|
2068
2077
|
}
|
|
2069
2078
|
|
|
2070
2079
|
// src/notifications.ts
|
|
2071
|
-
var MARK_INBOX_NOTIFICATIONS_AS_READ_BATCH_DELAY = 50;
|
|
2072
2080
|
function createNotificationsApi({
|
|
2073
2081
|
baseUrl,
|
|
2074
2082
|
authManager,
|
|
@@ -2091,7 +2099,7 @@ function createNotificationsApi({
|
|
|
2091
2099
|
...options,
|
|
2092
2100
|
headers: {
|
|
2093
2101
|
...options?.headers,
|
|
2094
|
-
Authorization: `Bearer ${
|
|
2102
|
+
Authorization: `Bearer ${getBearerTokenFromAuthValue(authValue)}`,
|
|
2095
2103
|
"X-LB-Client": PKG_VERSION || "dev"
|
|
2096
2104
|
}
|
|
2097
2105
|
});
|
|
@@ -2122,31 +2130,36 @@ function createNotificationsApi({
|
|
|
2122
2130
|
}
|
|
2123
2131
|
return body;
|
|
2124
2132
|
}
|
|
2125
|
-
async function getInboxNotifications() {
|
|
2126
|
-
const
|
|
2133
|
+
async function getInboxNotifications(options) {
|
|
2134
|
+
const PAGE_SIZE = 50;
|
|
2135
|
+
const json = await fetchJson(url`/v2/c/inbox-notifications`, void 0, {
|
|
2136
|
+
cursor: options?.cursor,
|
|
2137
|
+
limit: PAGE_SIZE
|
|
2138
|
+
});
|
|
2127
2139
|
return {
|
|
2128
|
-
threads: json.threads.map(convertToThreadData),
|
|
2129
2140
|
inboxNotifications: json.inboxNotifications.map(
|
|
2130
2141
|
convertToInboxNotificationData
|
|
2131
2142
|
),
|
|
2143
|
+
threads: json.threads.map(convertToThreadData),
|
|
2144
|
+
nextCursor: json.meta.nextCursor,
|
|
2132
2145
|
requestedAt: new Date(json.meta.requestedAt)
|
|
2133
2146
|
};
|
|
2134
2147
|
}
|
|
2135
|
-
async function getInboxNotificationsSince(
|
|
2136
|
-
const json = await fetchJson(url`/v2/c/inbox-notifications`, void 0, {
|
|
2137
|
-
since:
|
|
2148
|
+
async function getInboxNotificationsSince(since) {
|
|
2149
|
+
const json = await fetchJson(url`/v2/c/inbox-notifications/delta`, void 0, {
|
|
2150
|
+
since: since.toISOString()
|
|
2138
2151
|
});
|
|
2139
2152
|
return {
|
|
2140
|
-
threads: {
|
|
2141
|
-
updated: json.threads.map(convertToThreadData),
|
|
2142
|
-
deleted: json.deletedThreads.map(convertToThreadDeleteInfo)
|
|
2143
|
-
},
|
|
2144
2153
|
inboxNotifications: {
|
|
2145
2154
|
updated: json.inboxNotifications.map(convertToInboxNotificationData),
|
|
2146
2155
|
deleted: json.deletedInboxNotifications.map(
|
|
2147
2156
|
convertToInboxNotificationDeleteInfo
|
|
2148
2157
|
)
|
|
2149
2158
|
},
|
|
2159
|
+
threads: {
|
|
2160
|
+
updated: json.threads.map(convertToThreadData),
|
|
2161
|
+
deleted: json.deletedThreads.map(convertToThreadDeleteInfo)
|
|
2162
|
+
},
|
|
2150
2163
|
requestedAt: new Date(json.meta.requestedAt)
|
|
2151
2164
|
};
|
|
2152
2165
|
}
|
|
@@ -2178,7 +2191,7 @@ function createNotificationsApi({
|
|
|
2178
2191
|
await markInboxNotificationsAsRead(inboxNotificationIds);
|
|
2179
2192
|
return inboxNotificationIds;
|
|
2180
2193
|
},
|
|
2181
|
-
{ delay:
|
|
2194
|
+
{ delay: 50 }
|
|
2182
2195
|
);
|
|
2183
2196
|
async function markInboxNotificationAsRead(inboxNotificationId) {
|
|
2184
2197
|
await batchedMarkInboxNotificationsAsRead.get(inboxNotificationId);
|
|
@@ -2193,30 +2206,29 @@ function createNotificationsApi({
|
|
|
2193
2206
|
method: "DELETE"
|
|
2194
2207
|
});
|
|
2195
2208
|
}
|
|
2196
|
-
async function
|
|
2209
|
+
async function getUserThreads_experimental(options) {
|
|
2197
2210
|
let query;
|
|
2198
2211
|
if (options?.query) {
|
|
2199
2212
|
query = objectToQuery(options.query);
|
|
2200
2213
|
}
|
|
2214
|
+
const PAGE_SIZE = 50;
|
|
2201
2215
|
const json = await fetchJson(url`/v2/c/threads`, void 0, {
|
|
2202
|
-
|
|
2216
|
+
cursor: options.cursor,
|
|
2217
|
+
query,
|
|
2218
|
+
limit: PAGE_SIZE
|
|
2203
2219
|
});
|
|
2204
2220
|
return {
|
|
2205
2221
|
threads: json.threads.map(convertToThreadData),
|
|
2206
2222
|
inboxNotifications: json.inboxNotifications.map(
|
|
2207
2223
|
convertToInboxNotificationData
|
|
2208
2224
|
),
|
|
2225
|
+
nextCursor: json.meta.nextCursor,
|
|
2209
2226
|
requestedAt: new Date(json.meta.requestedAt)
|
|
2210
2227
|
};
|
|
2211
2228
|
}
|
|
2212
|
-
async function
|
|
2213
|
-
let query;
|
|
2214
|
-
if (options?.query) {
|
|
2215
|
-
query = objectToQuery(options.query);
|
|
2216
|
-
}
|
|
2229
|
+
async function getUserThreadsSince_experimental(options) {
|
|
2217
2230
|
const json = await fetchJson(url`/v2/c/threads`, void 0, {
|
|
2218
|
-
since: options.since.toISOString()
|
|
2219
|
-
query
|
|
2231
|
+
since: options.since.toISOString()
|
|
2220
2232
|
});
|
|
2221
2233
|
return {
|
|
2222
2234
|
threads: {
|
|
@@ -2240,8 +2252,8 @@ function createNotificationsApi({
|
|
|
2240
2252
|
markInboxNotificationAsRead,
|
|
2241
2253
|
deleteAllInboxNotifications,
|
|
2242
2254
|
deleteInboxNotification,
|
|
2243
|
-
|
|
2244
|
-
|
|
2255
|
+
getUserThreads_experimental,
|
|
2256
|
+
getUserThreadsSince_experimental
|
|
2245
2257
|
};
|
|
2246
2258
|
}
|
|
2247
2259
|
|
|
@@ -4811,7 +4823,7 @@ async function autoRetry(promiseFn, maxTries, backoff, throwError) {
|
|
|
4811
4823
|
try {
|
|
4812
4824
|
return await promise;
|
|
4813
4825
|
} catch (err) {
|
|
4814
|
-
if (throwError?.(err)) {
|
|
4826
|
+
if (throwError?.(err) || err instanceof StopRetrying2) {
|
|
4815
4827
|
throw err;
|
|
4816
4828
|
}
|
|
4817
4829
|
if (attempt >= maxTries) {
|
|
@@ -4819,9 +4831,17 @@ async function autoRetry(promiseFn, maxTries, backoff, throwError) {
|
|
|
4819
4831
|
}
|
|
4820
4832
|
}
|
|
4821
4833
|
const delay = backoff[attempt - 1] ?? fallbackBackoff;
|
|
4834
|
+
warn(
|
|
4835
|
+
`Attempt ${attempt} was unsuccessful. Retrying in ${delay} milliseconds.`
|
|
4836
|
+
);
|
|
4822
4837
|
await wait(delay);
|
|
4823
4838
|
}
|
|
4824
4839
|
}
|
|
4840
|
+
var StopRetrying2 = class extends Error {
|
|
4841
|
+
constructor(reason) {
|
|
4842
|
+
super(reason);
|
|
4843
|
+
}
|
|
4844
|
+
};
|
|
4825
4845
|
|
|
4826
4846
|
// src/lib/chunk.ts
|
|
4827
4847
|
function chunk(array, size) {
|
|
@@ -5288,7 +5308,6 @@ var CommentsApiError = class extends Error {
|
|
|
5288
5308
|
this.details = details;
|
|
5289
5309
|
}
|
|
5290
5310
|
};
|
|
5291
|
-
var MARK_INBOX_NOTIFICATIONS_AS_READ_BATCH_DELAY2 = 50;
|
|
5292
5311
|
function createRoom(options, config) {
|
|
5293
5312
|
const initialPresence = options.initialPresence;
|
|
5294
5313
|
const initialStorage = options.initialStorage;
|
|
@@ -5353,7 +5372,7 @@ function createRoom(options, config) {
|
|
|
5353
5372
|
function onStatusDidChange(newStatus) {
|
|
5354
5373
|
const authValue = managedSocket.authValue;
|
|
5355
5374
|
if (authValue !== null) {
|
|
5356
|
-
const tokenKey =
|
|
5375
|
+
const tokenKey = getBearerTokenFromAuthValue(authValue);
|
|
5357
5376
|
if (tokenKey !== lastTokenKey) {
|
|
5358
5377
|
lastTokenKey = tokenKey;
|
|
5359
5378
|
if (authValue.type === "secret") {
|
|
@@ -5518,7 +5537,7 @@ function createRoom(options, config) {
|
|
|
5518
5537
|
...options2,
|
|
5519
5538
|
headers: {
|
|
5520
5539
|
...options2?.headers,
|
|
5521
|
-
Authorization: `Bearer ${
|
|
5540
|
+
Authorization: `Bearer ${getBearerTokenFromAuthValue(authValue)}`,
|
|
5522
5541
|
"X-LB-Client": PKG_VERSION || "dev"
|
|
5523
5542
|
}
|
|
5524
5543
|
});
|
|
@@ -6477,9 +6496,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6477
6496
|
async function getThreadsSince(options2) {
|
|
6478
6497
|
const response = await fetchCommentsApi(
|
|
6479
6498
|
url`/v2/c/rooms/${config.roomId}/threads`,
|
|
6480
|
-
{
|
|
6481
|
-
since: options2?.since?.toISOString()
|
|
6482
|
-
},
|
|
6499
|
+
{ since: options2?.since?.toISOString() },
|
|
6483
6500
|
{
|
|
6484
6501
|
headers: {
|
|
6485
6502
|
"Content-Type": "application/json"
|
|
@@ -6522,9 +6539,14 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6522
6539
|
if (options2?.query) {
|
|
6523
6540
|
query = objectToQuery(options2.query);
|
|
6524
6541
|
}
|
|
6542
|
+
const PAGE_SIZE = 50;
|
|
6525
6543
|
const response = await fetchCommentsApi(
|
|
6526
6544
|
url`/v2/c/rooms/${config.roomId}/threads`,
|
|
6527
|
-
{
|
|
6545
|
+
{
|
|
6546
|
+
cursor: options2?.cursor,
|
|
6547
|
+
query,
|
|
6548
|
+
limit: PAGE_SIZE
|
|
6549
|
+
},
|
|
6528
6550
|
{ headers: { "Content-Type": "application/json" } }
|
|
6529
6551
|
);
|
|
6530
6552
|
if (response.ok) {
|
|
@@ -6534,6 +6556,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6534
6556
|
inboxNotifications: json.inboxNotifications.map(
|
|
6535
6557
|
convertToInboxNotificationData
|
|
6536
6558
|
),
|
|
6559
|
+
nextCursor: json.meta.nextCursor,
|
|
6537
6560
|
requestedAt: new Date(json.meta.requestedAt)
|
|
6538
6561
|
};
|
|
6539
6562
|
} else if (response.status === 404) {
|
|
@@ -6542,6 +6565,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6542
6565
|
inboxNotifications: [],
|
|
6543
6566
|
deletedThreads: [],
|
|
6544
6567
|
deletedInboxNotifications: [],
|
|
6568
|
+
nextCursor: null,
|
|
6545
6569
|
requestedAt: /* @__PURE__ */ new Date()
|
|
6546
6570
|
};
|
|
6547
6571
|
} else {
|
|
@@ -6924,7 +6948,7 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
6924
6948
|
await markInboxNotificationsAsRead(inboxNotificationIds);
|
|
6925
6949
|
return inboxNotificationIds;
|
|
6926
6950
|
},
|
|
6927
|
-
{ delay:
|
|
6951
|
+
{ delay: 50 }
|
|
6928
6952
|
);
|
|
6929
6953
|
async function markInboxNotificationAsRead(inboxNotificationId) {
|
|
6930
6954
|
await batchedMarkInboxNotificationsAsRead.get(inboxNotificationId);
|
|
@@ -7181,13 +7205,6 @@ function getBaseUrl(baseUrl) {
|
|
|
7181
7205
|
return DEFAULT_BASE_URL;
|
|
7182
7206
|
}
|
|
7183
7207
|
}
|
|
7184
|
-
function getAuthBearerHeaderFromAuthValue(authValue) {
|
|
7185
|
-
if (authValue.type === "public") {
|
|
7186
|
-
return authValue.publicApiKey;
|
|
7187
|
-
} else {
|
|
7188
|
-
return authValue.token.raw;
|
|
7189
|
-
}
|
|
7190
|
-
}
|
|
7191
7208
|
function createClient(options) {
|
|
7192
7209
|
const clientOptions = options;
|
|
7193
7210
|
const throttleDelay = getThrottle(clientOptions.throttle ?? DEFAULT_THROTTLE);
|
|
@@ -7289,20 +7306,11 @@ function createClient(options) {
|
|
|
7289
7306
|
}
|
|
7290
7307
|
}
|
|
7291
7308
|
const currentUserIdStore = createStore(null);
|
|
7292
|
-
const
|
|
7293
|
-
|
|
7294
|
-
|
|
7295
|
-
getUnreadInboxNotificationsCount,
|
|
7296
|
-
markAllInboxNotificationsAsRead,
|
|
7297
|
-
markInboxNotificationAsRead,
|
|
7298
|
-
deleteAllInboxNotifications,
|
|
7299
|
-
deleteInboxNotification,
|
|
7300
|
-
getThreads,
|
|
7301
|
-
getThreadsSince
|
|
7302
|
-
} = createNotificationsApi({
|
|
7309
|
+
const fetcher = clientOptions.polyfills?.fetch || /* istanbul ignore next */
|
|
7310
|
+
fetch;
|
|
7311
|
+
const httpClientLike = createNotificationsApi({
|
|
7303
7312
|
baseUrl,
|
|
7304
|
-
fetcher
|
|
7305
|
-
fetch,
|
|
7313
|
+
fetcher,
|
|
7306
7314
|
authManager,
|
|
7307
7315
|
currentUserIdStore
|
|
7308
7316
|
});
|
|
@@ -7341,14 +7349,7 @@ function createClient(options) {
|
|
|
7341
7349
|
enterRoom,
|
|
7342
7350
|
getRoom,
|
|
7343
7351
|
logout,
|
|
7344
|
-
|
|
7345
|
-
getInboxNotificationsSince,
|
|
7346
|
-
getUnreadInboxNotificationsCount,
|
|
7347
|
-
markAllInboxNotificationsAsRead,
|
|
7348
|
-
markInboxNotificationAsRead,
|
|
7349
|
-
deleteAllInboxNotifications,
|
|
7350
|
-
deleteInboxNotification,
|
|
7351
|
-
getThreads,
|
|
7352
|
+
...httpClientLike,
|
|
7352
7353
|
// Internal
|
|
7353
7354
|
[kInternal]: {
|
|
7354
7355
|
currentUserIdStore,
|
|
@@ -7358,8 +7359,9 @@ function createClient(options) {
|
|
|
7358
7359
|
getRoomIds() {
|
|
7359
7360
|
return Array.from(roomsById.keys());
|
|
7360
7361
|
},
|
|
7361
|
-
|
|
7362
|
-
|
|
7362
|
+
// "All" threads (= "user" threads)
|
|
7363
|
+
getUserThreads_experimental: httpClientLike.getUserThreads_experimental,
|
|
7364
|
+
getUserThreadsSince_experimental: httpClientLike.getUserThreadsSince_experimental
|
|
7363
7365
|
}
|
|
7364
7366
|
},
|
|
7365
7367
|
kInternal,
|
|
@@ -8093,69 +8095,26 @@ function errorIf(condition, message) {
|
|
|
8093
8095
|
}
|
|
8094
8096
|
|
|
8095
8097
|
// src/lib/Poller.ts
|
|
8096
|
-
function makePoller(callback) {
|
|
8097
|
-
let context = {
|
|
8098
|
-
state: "stopped",
|
|
8099
|
-
timeoutHandle: null,
|
|
8100
|
-
interval: null,
|
|
8101
|
-
lastScheduledAt: null,
|
|
8102
|
-
remainingInterval: null
|
|
8103
|
-
};
|
|
8098
|
+
function makePoller(callback, interval) {
|
|
8099
|
+
let context = { state: "stopped" };
|
|
8104
8100
|
function poll() {
|
|
8105
8101
|
if (context.state === "running") {
|
|
8106
|
-
schedule(
|
|
8102
|
+
schedule();
|
|
8107
8103
|
}
|
|
8108
8104
|
void callback();
|
|
8109
8105
|
}
|
|
8110
|
-
function schedule(
|
|
8106
|
+
function schedule() {
|
|
8111
8107
|
context = {
|
|
8112
8108
|
state: "running",
|
|
8113
|
-
interval: context.state !== "stopped" ? context.interval : interval,
|
|
8114
8109
|
lastScheduledAt: performance.now(),
|
|
8115
|
-
timeoutHandle: setTimeout(poll, interval)
|
|
8116
|
-
remainingInterval: null
|
|
8110
|
+
timeoutHandle: setTimeout(poll, interval)
|
|
8117
8111
|
};
|
|
8118
8112
|
}
|
|
8119
|
-
function
|
|
8120
|
-
if (context.state !== "paused") {
|
|
8121
|
-
return;
|
|
8122
|
-
}
|
|
8123
|
-
context = {
|
|
8124
|
-
state: "running",
|
|
8125
|
-
interval: context.interval,
|
|
8126
|
-
lastScheduledAt: context.lastScheduledAt,
|
|
8127
|
-
timeoutHandle: setTimeout(poll, remaining),
|
|
8128
|
-
remainingInterval: null
|
|
8129
|
-
};
|
|
8130
|
-
}
|
|
8131
|
-
function start(interval) {
|
|
8113
|
+
function start() {
|
|
8132
8114
|
if (context.state === "running") {
|
|
8133
8115
|
return;
|
|
8134
8116
|
}
|
|
8135
|
-
schedule(
|
|
8136
|
-
}
|
|
8137
|
-
function restart(interval) {
|
|
8138
|
-
stop();
|
|
8139
|
-
start(interval);
|
|
8140
|
-
}
|
|
8141
|
-
function pause() {
|
|
8142
|
-
if (context.state !== "running") {
|
|
8143
|
-
return;
|
|
8144
|
-
}
|
|
8145
|
-
clearTimeout(context.timeoutHandle);
|
|
8146
|
-
context = {
|
|
8147
|
-
state: "paused",
|
|
8148
|
-
interval: context.interval,
|
|
8149
|
-
lastScheduledAt: context.lastScheduledAt,
|
|
8150
|
-
timeoutHandle: null,
|
|
8151
|
-
remainingInterval: context.interval - (performance.now() - context.lastScheduledAt)
|
|
8152
|
-
};
|
|
8153
|
-
}
|
|
8154
|
-
function resume() {
|
|
8155
|
-
if (context.state !== "paused") {
|
|
8156
|
-
return;
|
|
8157
|
-
}
|
|
8158
|
-
scheduleRemaining(context.remainingInterval);
|
|
8117
|
+
schedule();
|
|
8159
8118
|
}
|
|
8160
8119
|
function stop() {
|
|
8161
8120
|
if (context.state === "stopped") {
|
|
@@ -8164,20 +8123,17 @@ function makePoller(callback) {
|
|
|
8164
8123
|
if (context.timeoutHandle) {
|
|
8165
8124
|
clearTimeout(context.timeoutHandle);
|
|
8166
8125
|
}
|
|
8167
|
-
context = {
|
|
8168
|
-
|
|
8169
|
-
|
|
8170
|
-
|
|
8171
|
-
|
|
8172
|
-
|
|
8173
|
-
|
|
8126
|
+
context = { state: "stopped" };
|
|
8127
|
+
}
|
|
8128
|
+
function enable(condition) {
|
|
8129
|
+
if (condition) {
|
|
8130
|
+
start();
|
|
8131
|
+
} else {
|
|
8132
|
+
stop();
|
|
8133
|
+
}
|
|
8174
8134
|
}
|
|
8175
8135
|
return {
|
|
8176
|
-
|
|
8177
|
-
restart,
|
|
8178
|
-
pause,
|
|
8179
|
-
resume,
|
|
8180
|
-
stop
|
|
8136
|
+
enable
|
|
8181
8137
|
};
|
|
8182
8138
|
}
|
|
8183
8139
|
|
|
@@ -8232,6 +8188,7 @@ export {
|
|
|
8232
8188
|
NotificationsApiError,
|
|
8233
8189
|
OpCode,
|
|
8234
8190
|
ServerMsgCode,
|
|
8191
|
+
StopRetrying2 as StopRetrying,
|
|
8235
8192
|
WebsocketCloseCodes,
|
|
8236
8193
|
ackOp,
|
|
8237
8194
|
asPos,
|