@liveblocks/core 1.11.3 → 1.12.0-test2

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.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.11.3";
9
+ var PKG_VERSION = "1.12.0-test2";
10
10
  var PKG_FORMAT = "esm";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -1389,7 +1389,6 @@ function createAuthManager(authOptions) {
1389
1389
  room: options.roomId
1390
1390
  });
1391
1391
  const parsed = parseAuthToken(response.token);
1392
- verifyTokenPermissions(parsed, options);
1393
1392
  if (seenTokens.has(parsed.raw)) {
1394
1393
  throw new StopRetrying(
1395
1394
  "The same Liveblocks auth token was issued from the backend before. Caching Liveblocks tokens is not supported."
@@ -1402,7 +1401,6 @@ function createAuthManager(authOptions) {
1402
1401
  if (response && typeof response === "object") {
1403
1402
  if (typeof response.token === "string") {
1404
1403
  const parsed = parseAuthToken(response.token);
1405
- verifyTokenPermissions(parsed, options);
1406
1404
  return parsed;
1407
1405
  } else if (typeof response.error === "string") {
1408
1406
  const reason = `Authentication failed: ${"reason" in response && typeof response.reason === "string" ? response.reason : "Forbidden"}`;
@@ -1421,23 +1419,6 @@ function createAuthManager(authOptions) {
1421
1419
  "Unexpected authentication type. Must be private or custom."
1422
1420
  );
1423
1421
  }
1424
- function verifyTokenPermissions(parsedToken, options) {
1425
- if (!options.roomId && parsedToken.parsed.k === "acc" /* ACCESS_TOKEN */) {
1426
- if (Object.entries(parsedToken.parsed.perms).length === 0) {
1427
- return;
1428
- }
1429
- for (const [resource, scopes] of Object.entries(
1430
- parsedToken.parsed.perms
1431
- )) {
1432
- if (resource.includes("*") && hasCorrespondingScopes(options.requestedScope, scopes)) {
1433
- return;
1434
- }
1435
- }
1436
- throw new StopRetrying(
1437
- "The issued access token doesn't grant enough permissions. Please follow the instructions at https://liveblocks.io/docs/errors/liveblocks-client/access-tokens-not-enough-permissions"
1438
- );
1439
- }
1440
- }
1441
1422
  async function getAuthValue(requestOptions) {
1442
1423
  if (authentication.type === "public") {
1443
1424
  return { type: "public", publicApiKey: authentication.publicApiKey };
@@ -2035,6 +2016,18 @@ function convertToCommentUserReaction(data) {
2035
2016
  function convertToInboxNotificationData(data) {
2036
2017
  const notifiedAt = new Date(data.notifiedAt);
2037
2018
  const readAt = data.readAt ? new Date(data.readAt) : null;
2019
+ if ("activities" in data) {
2020
+ const activities = data.activities.map((activity) => ({
2021
+ ...activity,
2022
+ createdAt: new Date(activity.createdAt)
2023
+ }));
2024
+ return {
2025
+ ...data,
2026
+ notifiedAt,
2027
+ readAt,
2028
+ activities
2029
+ };
2030
+ }
2038
2031
  return {
2039
2032
  ...data,
2040
2033
  notifiedAt,
@@ -4768,6 +4761,115 @@ function isJsonObject(data) {
4768
4761
  return !isJsonScalar(data) && !isJsonArray(data);
4769
4762
  }
4770
4763
 
4764
+ // src/lib/objectToQuery.ts
4765
+ var identifierRegex = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
4766
+ function objectToQuery(obj) {
4767
+ let filterList = [];
4768
+ const entries2 = Object.entries(obj);
4769
+ const keyValuePairs = [];
4770
+ const keyValuePairsWithOperator = [];
4771
+ const indexedKeys = [];
4772
+ entries2.forEach(([key, value]) => {
4773
+ if (!identifierRegex.test(key)) {
4774
+ throw new Error("Key must only contain letters, numbers, _");
4775
+ }
4776
+ if (isSimpleValue(value)) {
4777
+ keyValuePairs.push([key, value]);
4778
+ } else if (isValueWithOperator(value)) {
4779
+ keyValuePairsWithOperator.push([key, value]);
4780
+ } else if (typeof value === "object" && !("startsWith" in value)) {
4781
+ indexedKeys.push([key, value]);
4782
+ }
4783
+ });
4784
+ filterList = [
4785
+ ...getFiltersFromKeyValuePairs(keyValuePairs),
4786
+ ...getFiltersFromKeyValuePairsWithOperator(keyValuePairsWithOperator)
4787
+ ];
4788
+ indexedKeys.forEach(([key, value]) => {
4789
+ const nestedEntries = Object.entries(value);
4790
+ const nKeyValuePairs = [];
4791
+ const nKeyValuePairsWithOperator = [];
4792
+ nestedEntries.forEach(([nestedKey, nestedValue]) => {
4793
+ if (isStringEmpty(nestedKey)) {
4794
+ throw new Error("Key cannot be empty");
4795
+ }
4796
+ if (isSimpleValue(nestedValue)) {
4797
+ nKeyValuePairs.push([formatFilterKey(key, nestedKey), nestedValue]);
4798
+ } else if (isValueWithOperator(nestedValue)) {
4799
+ nKeyValuePairsWithOperator.push([
4800
+ formatFilterKey(key, nestedKey),
4801
+ nestedValue
4802
+ ]);
4803
+ }
4804
+ });
4805
+ filterList = [
4806
+ ...filterList,
4807
+ ...getFiltersFromKeyValuePairs(nKeyValuePairs),
4808
+ ...getFiltersFromKeyValuePairsWithOperator(nKeyValuePairsWithOperator)
4809
+ ];
4810
+ });
4811
+ return filterList.map(
4812
+ ({ key, operator, value }) => formatFilter(key, operator, formatFilterValue(value))
4813
+ ).join(" AND ");
4814
+ }
4815
+ var getFiltersFromKeyValuePairs = (keyValuePairs) => {
4816
+ const filters = [];
4817
+ keyValuePairs.forEach(([key, value]) => {
4818
+ filters.push({
4819
+ key,
4820
+ operator: ":",
4821
+ value
4822
+ });
4823
+ });
4824
+ return filters;
4825
+ };
4826
+ var getFiltersFromKeyValuePairsWithOperator = (keyValuePairsWithOperator) => {
4827
+ const filters = [];
4828
+ keyValuePairsWithOperator.forEach(([key, value]) => {
4829
+ if ("startsWith" in value && typeof value.startsWith === "string") {
4830
+ filters.push({
4831
+ key,
4832
+ operator: "^",
4833
+ value: value.startsWith
4834
+ });
4835
+ }
4836
+ });
4837
+ return filters;
4838
+ };
4839
+ var isSimpleValue = (value) => {
4840
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
4841
+ return true;
4842
+ }
4843
+ return false;
4844
+ };
4845
+ var isValueWithOperator = (value) => {
4846
+ if (typeof value === "object" && value !== null && "startsWith" in value) {
4847
+ return true;
4848
+ }
4849
+ return false;
4850
+ };
4851
+ var formatFilter = (key, operator, value) => {
4852
+ return `${key}${operator}${value}`;
4853
+ };
4854
+ var formatFilterKey = (key, nestedKey) => {
4855
+ if (nestedKey) {
4856
+ return `${key}[${JSON.stringify(nestedKey)}]`;
4857
+ }
4858
+ return key;
4859
+ };
4860
+ var formatFilterValue = (value) => {
4861
+ if (typeof value === "string") {
4862
+ if (isStringEmpty(value)) {
4863
+ throw new Error("Value cannot be empty");
4864
+ }
4865
+ return JSON.stringify(value);
4866
+ }
4867
+ return value.toString();
4868
+ };
4869
+ var isStringEmpty = (value) => {
4870
+ return !value || value.toString().trim() === "";
4871
+ };
4872
+
4771
4873
  // src/protocol/ClientMsg.ts
4772
4874
  var ClientMsgCode = /* @__PURE__ */ ((ClientMsgCode2) => {
4773
4875
  ClientMsgCode2[ClientMsgCode2["UPDATE_PRESENCE"] = 100] = "UPDATE_PRESENCE";
@@ -5070,19 +5172,20 @@ function createCommentsApi(roomId, getAuthValue, fetchClientApi) {
5070
5172
  return body;
5071
5173
  }
5072
5174
  async function getThreads(options) {
5175
+ let query;
5176
+ if (options?.query) {
5177
+ query = objectToQuery(options.query);
5178
+ }
5073
5179
  const response = await fetchCommentsApi(
5074
- "/threads/search",
5180
+ "/threads",
5075
5181
  {
5076
- since: options?.since?.toISOString()
5182
+ since: options?.since?.toISOString(),
5183
+ query
5077
5184
  },
5078
5185
  {
5079
- body: JSON.stringify({
5080
- ...options?.query?.metadata && { metadata: options.query.metadata }
5081
- }),
5082
5186
  headers: {
5083
5187
  "Content-Type": "application/json"
5084
- },
5085
- method: "POST"
5188
+ }
5086
5189
  }
5087
5190
  );
5088
5191
  if (response.ok) {
@@ -6617,7 +6720,7 @@ function createClientStore() {
6617
6720
  threads: deleteKeyImmutable(state.threads, threadId),
6618
6721
  inboxNotifications: Object.fromEntries(
6619
6722
  Object.entries(state.inboxNotifications).filter(
6620
- ([_id, notification]) => notification.threadId !== threadId
6723
+ ([_id, notification]) => notification.kind === "thread" && notification.threadId !== threadId
6621
6724
  )
6622
6725
  )
6623
6726
  };
@@ -6759,7 +6862,7 @@ function applyOptimisticUpdates(state) {
6759
6862
  optimisticUpdate.comment
6760
6863
  );
6761
6864
  const inboxNotification = Object.values(result.inboxNotifications).find(
6762
- (notification) => notification.threadId === thread.id
6865
+ (notification) => notification.kind === "thread" && notification.threadId !== thread.id
6763
6866
  );
6764
6867
  if (inboxNotification === void 0) {
6765
6868
  break;
@@ -8121,6 +8224,7 @@ export {
8121
8224
  fancy_console_exports as console,
8122
8225
  convertToCommentData,
8123
8226
  convertToCommentUserReaction,
8227
+ convertToInboxNotificationData,
8124
8228
  convertToThreadData,
8125
8229
  createClient,
8126
8230
  deleteComment,
@@ -8144,6 +8248,7 @@ export {
8144
8248
  makePoller,
8145
8249
  makePosition,
8146
8250
  nn,
8251
+ objectToQuery,
8147
8252
  patchLiveObjectKey,
8148
8253
  raise,
8149
8254
  removeReaction,