@liveblocks/node 3.15.4 → 3.16.0-feeds1

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.cjs CHANGED
@@ -3,7 +3,7 @@ var _core = require('@liveblocks/core');
3
3
 
4
4
  // src/version.ts
5
5
  var PKG_NAME = "@liveblocks/node";
6
- var PKG_VERSION = "3.15.4";
6
+ var PKG_VERSION = "3.16.0-feeds1";
7
7
  var PKG_FORMAT = "cjs";
8
8
 
9
9
  // src/client.ts
@@ -165,7 +165,9 @@ var ALL_PERMISSIONS = Object.freeze([
165
165
  "room:read",
166
166
  "room:presence:write",
167
167
  "comments:write",
168
- "comments:read"
168
+ "comments:read",
169
+ "feeds:write",
170
+ "feeds:read"
169
171
  ]);
170
172
  function isPermission(value) {
171
173
  return ALL_PERMISSIONS.includes(value);
@@ -174,9 +176,14 @@ var MAX_PERMS_PER_SET = 10;
174
176
  var READ_ACCESS = Object.freeze([
175
177
  "room:read",
176
178
  "room:presence:write",
177
- "comments:read"
179
+ "comments:read",
180
+ "feeds:read"
181
+ ]);
182
+ var FULL_ACCESS = Object.freeze([
183
+ "room:write",
184
+ "comments:write",
185
+ "feeds:write"
178
186
  ]);
179
- var FULL_ACCESS = Object.freeze(["room:write", "comments:write"]);
180
187
  var roomPatternRegex = /^([*]|[^*]{1,128}[*]?)$/;
181
188
  var Session = (_class = class {
182
189
  __init() {this.FULL_ACCESS = FULL_ACCESS}
@@ -360,6 +367,22 @@ var Liveblocks = class {
360
367
  xwarn(res, "POST", path);
361
368
  return res;
362
369
  }
370
+ async #patch(path, json, options) {
371
+ const url3 = _core.urljoin.call(void 0, this.#baseUrl, path);
372
+ const headers = {
373
+ Authorization: `Bearer ${this.#secret}`,
374
+ "Content-Type": "application/json"
375
+ };
376
+ const fetch = await fetchPolyfill();
377
+ const res = await fetch(url3, {
378
+ method: "PATCH",
379
+ headers,
380
+ body: JSON.stringify(json),
381
+ signal: _optionalChain([options, 'optionalAccess', _2 => _2.signal])
382
+ });
383
+ xwarn(res, "PATCH", path);
384
+ return res;
385
+ }
363
386
  async #putBinary(path, body, params, options) {
364
387
  const url3 = _core.urljoin.call(void 0, this.#baseUrl, path, params);
365
388
  const headers = {
@@ -371,7 +394,7 @@ var Liveblocks = class {
371
394
  method: "PUT",
372
395
  headers,
373
396
  body,
374
- signal: _optionalChain([options, 'optionalAccess', _2 => _2.signal])
397
+ signal: _optionalChain([options, 'optionalAccess', _3 => _3.signal])
375
398
  });
376
399
  xwarn(res, "PUT", path);
377
400
  return res;
@@ -385,7 +408,7 @@ var Liveblocks = class {
385
408
  const res = await fetch(url3, {
386
409
  method: "DELETE",
387
410
  headers,
388
- signal: _optionalChain([options, 'optionalAccess', _3 => _3.signal])
411
+ signal: _optionalChain([options, 'optionalAccess', _4 => _4.signal])
389
412
  });
390
413
  xwarn(res, "DELETE", path);
391
414
  return res;
@@ -399,7 +422,7 @@ var Liveblocks = class {
399
422
  const res = await fetch(url3, {
400
423
  method: "GET",
401
424
  headers,
402
- signal: _optionalChain([options, 'optionalAccess', _4 => _4.signal])
425
+ signal: _optionalChain([options, 'optionalAccess', _5 => _5.signal])
403
426
  });
404
427
  xwarn(res, "GET", path);
405
428
  return res;
@@ -430,8 +453,8 @@ var Liveblocks = class {
430
453
  return new Session(
431
454
  this.#post.bind(this),
432
455
  userId,
433
- _optionalChain([options, 'optionalAccess', _5 => _5.userInfo]),
434
- _nullishCoalesce(_optionalChain([options, 'optionalAccess', _6 => _6.organizationId]), () => ( _optionalChain([options, 'optionalAccess', _7 => _7.tenantId]))),
456
+ _optionalChain([options, 'optionalAccess', _6 => _6.userInfo]),
457
+ _nullishCoalesce(_optionalChain([options, 'optionalAccess', _7 => _7.organizationId]), () => ( _optionalChain([options, 'optionalAccess', _8 => _8.tenantId]))),
435
458
  this.#localDev
436
459
  );
437
460
  }
@@ -481,7 +504,7 @@ var Liveblocks = class {
481
504
  const body = {
482
505
  userId,
483
506
  groupIds,
484
- userInfo: _optionalChain([options, 'optionalAccess', _8 => _8.userInfo])
507
+ userInfo: _optionalChain([options, 'optionalAccess', _9 => _9.userInfo])
485
508
  };
486
509
  if (organizationId !== void 0) {
487
510
  body.organizationId = organizationId;
@@ -567,7 +590,7 @@ var Liveblocks = class {
567
590
  */
568
591
  async *iterRooms(criteria, options) {
569
592
  const { signal } = _nullishCoalesce(options, () => ( {}));
570
- const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess', _9 => _9.pageSize]), () => ( 40)), 20);
593
+ const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess', _10 => _10.pageSize]), () => ( 40)), 20);
571
594
  let cursor = void 0;
572
595
  while (true) {
573
596
  const { nextCursor, data } = await this.getRooms(
@@ -616,7 +639,7 @@ var Liveblocks = class {
616
639
  body.organizationId = tenantId;
617
640
  }
618
641
  const res = await this.#post(
619
- _optionalChain([options, 'optionalAccess', _10 => _10.idempotent]) ? _core.url`/v2/rooms?idempotent` : _core.url`/v2/rooms`,
642
+ _optionalChain([options, 'optionalAccess', _11 => _11.idempotent]) ? _core.url`/v2/rooms?idempotent` : _core.url`/v2/rooms`,
620
643
  body,
621
644
  options
622
645
  );
@@ -1072,7 +1095,7 @@ var Liveblocks = class {
1072
1095
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/comments`,
1073
1096
  {
1074
1097
  ...data,
1075
- createdAt: _optionalChain([data, 'access', _11 => _11.createdAt, 'optionalAccess', _12 => _12.toISOString, 'call', _13 => _13()])
1098
+ createdAt: _optionalChain([data, 'access', _12 => _12.createdAt, 'optionalAccess', _13 => _13.toISOString, 'call', _14 => _14()])
1076
1099
  },
1077
1100
  options
1078
1101
  );
@@ -1098,7 +1121,7 @@ var Liveblocks = class {
1098
1121
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}`,
1099
1122
  {
1100
1123
  body: data.body,
1101
- editedAt: _optionalChain([data, 'access', _14 => _14.editedAt, 'optionalAccess', _15 => _15.toISOString, 'call', _16 => _16()]),
1124
+ editedAt: _optionalChain([data, 'access', _15 => _15.editedAt, 'optionalAccess', _16 => _16.toISOString, 'call', _17 => _17()]),
1102
1125
  metadata: data.metadata
1103
1126
  },
1104
1127
  options
@@ -1166,7 +1189,7 @@ var Liveblocks = class {
1166
1189
  ...data,
1167
1190
  comment: {
1168
1191
  ...data.comment,
1169
- createdAt: _optionalChain([data, 'access', _17 => _17.comment, 'access', _18 => _18.createdAt, 'optionalAccess', _19 => _19.toISOString, 'call', _20 => _20()])
1192
+ createdAt: _optionalChain([data, 'access', _18 => _18.comment, 'access', _19 => _19.createdAt, 'optionalAccess', _20 => _20.toISOString, 'call', _21 => _21()])
1170
1193
  }
1171
1194
  },
1172
1195
  options
@@ -1289,7 +1312,7 @@ var Liveblocks = class {
1289
1312
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/metadata`,
1290
1313
  {
1291
1314
  ...data,
1292
- updatedAt: _optionalChain([data, 'access', _21 => _21.updatedAt, 'optionalAccess', _22 => _22.toISOString, 'call', _23 => _23()])
1315
+ updatedAt: _optionalChain([data, 'access', _22 => _22.updatedAt, 'optionalAccess', _23 => _23.toISOString, 'call', _24 => _24()])
1293
1316
  },
1294
1317
  options
1295
1318
  );
@@ -1315,7 +1338,7 @@ var Liveblocks = class {
1315
1338
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}/metadata`,
1316
1339
  {
1317
1340
  ...data,
1318
- updatedAt: _optionalChain([data, 'access', _24 => _24.updatedAt, 'optionalAccess', _25 => _25.toISOString, 'call', _26 => _26()])
1341
+ updatedAt: _optionalChain([data, 'access', _25 => _25.updatedAt, 'optionalAccess', _26 => _26.toISOString, 'call', _27 => _27()])
1319
1342
  },
1320
1343
  options
1321
1344
  );
@@ -1341,7 +1364,7 @@ var Liveblocks = class {
1341
1364
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}/add-reaction`,
1342
1365
  {
1343
1366
  ...data,
1344
- createdAt: _optionalChain([data, 'access', _27 => _27.createdAt, 'optionalAccess', _28 => _28.toISOString, 'call', _29 => _29()])
1367
+ createdAt: _optionalChain([data, 'access', _28 => _28.createdAt, 'optionalAccess', _29 => _29.toISOString, 'call', _30 => _30()])
1345
1368
  },
1346
1369
  options
1347
1370
  );
@@ -1367,7 +1390,7 @@ var Liveblocks = class {
1367
1390
  _core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${params.commentId}/remove-reaction`,
1368
1391
  {
1369
1392
  ...data,
1370
- removedAt: _optionalChain([data, 'access', _30 => _30.removedAt, 'optionalAccess', _31 => _31.toISOString, 'call', _32 => _32()])
1393
+ removedAt: _optionalChain([data, 'access', _31 => _31.removedAt, 'optionalAccess', _32 => _32.toISOString, 'call', _33 => _33()])
1371
1394
  },
1372
1395
  options
1373
1396
  );
@@ -1448,7 +1471,7 @@ var Liveblocks = class {
1448
1471
  */
1449
1472
  async *iterInboxNotifications(criteria, options) {
1450
1473
  const { signal } = _nullishCoalesce(options, () => ( {}));
1451
- const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess', _33 => _33.pageSize]), () => ( 50)), 10);
1474
+ const pageSize = _core.checkBounds.call(void 0, "pageSize", _nullishCoalesce(_optionalChain([options, 'optionalAccess', _34 => _34.pageSize]), () => ( 50)), 10);
1452
1475
  let cursor = void 0;
1453
1476
  while (true) {
1454
1477
  const { nextCursor, data } = await this.getInboxNotifications(
@@ -1795,7 +1818,7 @@ var Liveblocks = class {
1795
1818
  async getGroups(params, options) {
1796
1819
  const res = await this.#get(
1797
1820
  _core.url`/v2/groups`,
1798
- { startingAfter: _optionalChain([params, 'optionalAccess', _34 => _34.startingAfter]), limit: _optionalChain([params, 'optionalAccess', _35 => _35.limit]) },
1821
+ { startingAfter: _optionalChain([params, 'optionalAccess', _35 => _35.startingAfter]), limit: _optionalChain([params, 'optionalAccess', _36 => _36.limit]) },
1799
1822
  options
1800
1823
  );
1801
1824
  if (!res.ok) {
@@ -1857,7 +1880,7 @@ var Liveblocks = class {
1857
1880
  async massMutateStorage(criteria, callback, massOptions) {
1858
1881
  const concurrency = _core.checkBounds.call(void 0,
1859
1882
  "concurrency",
1860
- _nullishCoalesce(_optionalChain([massOptions, 'optionalAccess', _36 => _36.concurrency]), () => ( 8)),
1883
+ _nullishCoalesce(_optionalChain([massOptions, 'optionalAccess', _37 => _37.concurrency]), () => ( 8)),
1861
1884
  1,
1862
1885
  20
1863
1886
  );
@@ -1873,7 +1896,7 @@ var Liveblocks = class {
1873
1896
  }
1874
1897
  async #_mutateOneRoom(roomId, room, callback, options) {
1875
1898
  const debounceInterval = 200;
1876
- const { signal, abort } = _core.makeAbortController.call(void 0, _optionalChain([options, 'optionalAccess', _37 => _37.signal]));
1899
+ const { signal, abort } = _core.makeAbortController.call(void 0, _optionalChain([options, 'optionalAccess', _38 => _38.signal]));
1877
1900
  let opsBuffer = [];
1878
1901
  let outstandingFlush$ = void 0;
1879
1902
  let lastFlush = performance.now();
@@ -1939,7 +1962,7 @@ var Liveblocks = class {
1939
1962
  const res = await this.#post(
1940
1963
  _core.url`/v2/rooms/${roomId}/send-message`,
1941
1964
  { messages },
1942
- { signal: _optionalChain([options, 'optionalAccess', _38 => _38.signal]) }
1965
+ { signal: _optionalChain([options, 'optionalAccess', _39 => _39.signal]) }
1943
1966
  );
1944
1967
  if (!res.ok) {
1945
1968
  throw await LiveblocksError.from(res);
@@ -2076,7 +2099,7 @@ var Liveblocks = class {
2076
2099
  "Content-Type": params.file.type,
2077
2100
  "Content-Length": String(params.file.size)
2078
2101
  },
2079
- signal: _optionalChain([options, 'optionalAccess', _39 => _39.signal])
2102
+ signal: _optionalChain([options, 'optionalAccess', _40 => _40.signal])
2080
2103
  }
2081
2104
  );
2082
2105
  if (!res.ok) {
@@ -2208,6 +2231,192 @@ var Liveblocks = class {
2208
2231
  data: page.data.map(inflateWebKnowledgeSourceLink)
2209
2232
  };
2210
2233
  }
2234
+ /* -------------------------------------------------------------------------------------------------
2235
+ * Feeds
2236
+ * -----------------------------------------------------------------------------------------------*/
2237
+ /**
2238
+ * Returns a list of feeds in a room.
2239
+ * @param params.roomId The room ID to get the feeds from.
2240
+ * @param options.signal (optional) An abort signal to cancel the request.
2241
+ * @returns A list of feeds.
2242
+ */
2243
+ async getFeeds(params, options) {
2244
+ const { roomId } = params;
2245
+ const res = await this.#get(
2246
+ _core.url`/v2/rooms/${roomId}/feeds`,
2247
+ void 0,
2248
+ options
2249
+ );
2250
+ if (!res.ok) {
2251
+ throw await LiveblocksError.from(res);
2252
+ }
2253
+ return await res.json();
2254
+ }
2255
+ /**
2256
+ * Creates a new feed in a room.
2257
+ * @param params.roomId The room ID to create the feed in.
2258
+ * @param params.feedId The feed ID.
2259
+ * @param params.metadata (optional) The metadata for the feed.
2260
+ * @param params.createdAt (optional) Creation time in ms. Sent to the API as `timestamp`. If not provided, the server uses the current time.
2261
+ * @param options.signal (optional) An abort signal to cancel the request.
2262
+ * @returns The created feed.
2263
+ */
2264
+ async createFeed(params, options) {
2265
+ const { roomId, feedId, metadata, createdAt } = params;
2266
+ const res = await this.#post(
2267
+ _core.url`/v2/rooms/${roomId}/feed`,
2268
+ {
2269
+ feedId,
2270
+ ...metadata !== void 0 ? { metadata } : {},
2271
+ ...createdAt !== void 0 ? { timestamp: createdAt } : {}
2272
+ },
2273
+ options
2274
+ );
2275
+ if (!res.ok) {
2276
+ throw await LiveblocksError.from(res);
2277
+ }
2278
+ return (await res.json()).data;
2279
+ }
2280
+ /**
2281
+ * Returns a feed with the given id.
2282
+ * @param params.roomId The room ID to get the feed from.
2283
+ * @param params.feedId The feed ID.
2284
+ * @param options.signal (optional) An abort signal to cancel the request.
2285
+ * @returns The feed.
2286
+ */
2287
+ async getFeed(params, options) {
2288
+ const { roomId, feedId } = params;
2289
+ const res = await this.#get(
2290
+ _core.url`/v2/rooms/${roomId}/feeds/${feedId}`,
2291
+ void 0,
2292
+ options
2293
+ );
2294
+ if (!res.ok) {
2295
+ throw await LiveblocksError.from(res);
2296
+ }
2297
+ return (await res.json()).data;
2298
+ }
2299
+ /**
2300
+ * Updates the metadata of a feed.
2301
+ * @param params.roomId The room ID to update the feed in.
2302
+ * @param params.feedId The feed ID to update.
2303
+ * @param params.metadata The metadata for the feed.
2304
+ * @param options.signal (optional) An abort signal to cancel the request.
2305
+ */
2306
+ async updateFeed(params, options) {
2307
+ const { roomId, feedId, metadata } = params;
2308
+ const res = await this.#patch(
2309
+ _core.url`/v2/rooms/${roomId}/feeds/${feedId}`,
2310
+ { metadata },
2311
+ options
2312
+ );
2313
+ if (!res.ok) {
2314
+ throw await LiveblocksError.from(res);
2315
+ }
2316
+ }
2317
+ /**
2318
+ * Deletes a feed.
2319
+ * @param params.roomId The room ID to delete the feed from.
2320
+ * @param params.feedId The feed ID to delete.
2321
+ * @param options.signal (optional) An abort signal to cancel the request.
2322
+ */
2323
+ async deleteFeed(params, options) {
2324
+ const { roomId, feedId } = params;
2325
+ const res = await this.#delete(
2326
+ _core.url`/v2/rooms/${roomId}/feeds/${feedId}`,
2327
+ void 0,
2328
+ options
2329
+ );
2330
+ if (!res.ok) {
2331
+ throw await LiveblocksError.from(res);
2332
+ }
2333
+ }
2334
+ /**
2335
+ * Returns a list of messages in a feed.
2336
+ * @param params.roomId The room ID to get the feed messages from.
2337
+ * @param params.feedId The feed ID to get the messages from.
2338
+ * @param options.signal (optional) An abort signal to cancel the request.
2339
+ * @returns A list of feed messages.
2340
+ */
2341
+ async getFeedMessages(params, options) {
2342
+ const { roomId, feedId } = params;
2343
+ const res = await this.#get(
2344
+ _core.url`/v2/rooms/${roomId}/feeds/${feedId}/messages`,
2345
+ void 0,
2346
+ options
2347
+ );
2348
+ if (!res.ok) {
2349
+ throw await LiveblocksError.from(res);
2350
+ }
2351
+ return await res.json();
2352
+ }
2353
+ /**
2354
+ * Creates a new message in a feed.
2355
+ * @param params.roomId The room ID to create the feed message in.
2356
+ * @param params.feedId The feed ID to create the message in.
2357
+ * @param params.id (optional) The message ID. If not provided, one will be generated.
2358
+ * @param params.createdAt (optional) Creation time in ms. Sent to the API as `timestamp`. If not provided, the server uses the current time.
2359
+ * @param params.data The message data.
2360
+ * @param options.signal (optional) An abort signal to cancel the request.
2361
+ * @returns The created feed message.
2362
+ */
2363
+ async createFeedMessage(params, options) {
2364
+ const { roomId, feedId, id, createdAt, data } = params;
2365
+ const res = await this.#post(
2366
+ _core.url`/v2/rooms/${roomId}/feeds/${feedId}/messages`,
2367
+ {
2368
+ data,
2369
+ ...id !== void 0 ? { id } : {},
2370
+ ...createdAt !== void 0 ? { timestamp: createdAt } : {}
2371
+ },
2372
+ options
2373
+ );
2374
+ if (!res.ok) {
2375
+ throw await LiveblocksError.from(res);
2376
+ }
2377
+ return (await res.json()).data;
2378
+ }
2379
+ /**
2380
+ * Updates a feed message.
2381
+ * @param params.roomId The room ID to update the feed message in.
2382
+ * @param params.feedId The feed ID to update the message in.
2383
+ * @param params.messageId The message ID to update.
2384
+ * @param params.data The message data.
2385
+ * @param params.updatedAt (optional) Update time in ms. Sent to the API as `timestamp`. If omitted, the server uses the current time.
2386
+ * @param options.signal (optional) An abort signal to cancel the request.
2387
+ */
2388
+ async updateFeedMessage(params, options) {
2389
+ const { roomId, feedId, messageId, data, updatedAt } = params;
2390
+ const res = await this.#patch(
2391
+ _core.url`/v2/rooms/${roomId}/feeds/${feedId}/messages/${messageId}`,
2392
+ {
2393
+ data,
2394
+ ...updatedAt !== void 0 ? { timestamp: updatedAt } : {}
2395
+ },
2396
+ options
2397
+ );
2398
+ if (!res.ok) {
2399
+ throw await LiveblocksError.from(res);
2400
+ }
2401
+ }
2402
+ /**
2403
+ * Deletes a feed message.
2404
+ * @param params.roomId The room ID to delete the feed message from.
2405
+ * @param params.feedId The feed ID to delete the message from.
2406
+ * @param params.messageId The message ID to delete.
2407
+ * @param options.signal (optional) An abort signal to cancel the request.
2408
+ */
2409
+ async deleteFeedMessage(params, options) {
2410
+ const { roomId, feedId, messageId } = params;
2411
+ const res = await this.#delete(
2412
+ _core.url`/v2/rooms/${roomId}/feeds/${feedId}/messages/${messageId}`,
2413
+ void 0,
2414
+ options
2415
+ );
2416
+ if (!res.ok) {
2417
+ throw await LiveblocksError.from(res);
2418
+ }
2419
+ }
2211
2420
  };
2212
2421
  var LiveblocksError = class _LiveblocksError extends Error {
2213
2422