@abraca/nuxt 2.59.0 → 2.61.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/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=4.0.0"
6
6
  },
7
- "version": "2.59.0",
7
+ "version": "2.61.0",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -750,6 +750,7 @@ const batchedEdgePaths = computed(() => {
750
750
  });
751
751
  let savePosTimer = null;
752
752
  function savePositionsDebounced() {
753
+ if (!canWrite.value) return;
753
754
  if (savePosTimer) clearTimeout(savePosTimer);
754
755
  savePosTimer = setTimeout(() => {
755
756
  savePosTimer = null;
@@ -20,7 +20,7 @@ const DEFAULT_LABELS = {
20
20
  roleViewer: "Viewer",
21
21
  roleObserver: "Observer"
22
22
  };
23
- const ROLE_RANK = { observer: 0, viewer: 1, editor: 2, owner: 3 };
23
+ const ROLE_RANK = { observer: 0, viewer: 1, editor: 2, owner: 3, admin: 4, service: 5 };
24
24
  export function roleMax(a, b) {
25
25
  return (ROLE_RANK[a] ?? -1) >= (ROLE_RANK[b] ?? -1) ? a : b;
26
26
  }
@@ -54,13 +54,14 @@ export function useDocPermissions(docId, options) {
54
54
  const pub = docAccess.value?.public_access ?? docAccess.value?.effective_public_access;
55
55
  const publicFloor = pub && pub !== "none" ? pub : null;
56
56
  const def = serverDefaultRole.value || null;
57
- if (explicit && publicFloor) return roleMax(explicit, publicFloor);
58
- if (explicit) return explicit;
59
- if (publicFloor && def) return roleMax(publicFloor, def);
60
- if (publicFloor) return publicFloor;
61
- return def ?? providerRole.value ?? null;
57
+ const cascaded = explicit && publicFloor ? roleMax(explicit, publicFloor) : explicit ?? (publicFloor && def ? roleMax(publicFloor, def) : publicFloor ?? def ?? null);
58
+ const provider = providerRole.value;
59
+ if (cascaded && provider) return roleMax(cascaded, provider);
60
+ return cascaded ?? provider ?? null;
62
61
  });
63
- const isOwner = computed(() => effectiveRole.value === "owner");
62
+ const isOwner = computed(
63
+ () => (ROLE_RANK[effectiveRole.value ?? ""] ?? -1) >= ROLE_RANK.owner
64
+ );
64
65
  const directPermissions = computed(() => permissions.value.filter((p) => p.source === "direct"));
65
66
  const inheritedPermissions = computed(() => permissions.value.filter((p) => p.source === "inherited"));
66
67
  const hasInheritedPermissions = computed(() => inheritedPermissions.value.length > 0);
@@ -2,11 +2,12 @@ import { computed, unref } from "vue";
2
2
  import { useAbracadabra, useSyncedMap, useFetch, useHead, useSeoMeta } from "#imports";
3
3
  function extractFirstParagraph(html) {
4
4
  if (!html) return void 0;
5
- const pMatch = html.match(/<p[^>]*>(.*?)<\/p>/is);
6
- const raw = pMatch?.[1] ?? html;
7
- const text = raw.replace(/<[^>]+>/g, "").replace(/&[a-z]+;/gi, " ").trim();
8
- if (!text) return void 0;
9
- return text.length > 160 ? text.slice(0, 157) + "..." : text;
5
+ const strip = (raw) => raw.replace(/<[^>]+>/g, "").replace(/&[a-z]+;/gi, " ").trim();
6
+ for (const m of html.matchAll(/<p[^>]*>(.*?)<\/p>/gis)) {
7
+ const text = strip(m[1] ?? "");
8
+ if (text) return text.length > 160 ? text.slice(0, 157) + "..." : text;
9
+ }
10
+ return void 0;
10
11
  }
11
12
  function extractFirstImage(html) {
12
13
  if (!html) return void 0;
@@ -1,10 +1,12 @@
1
1
  import { computed, toValue } from "vue";
2
2
  const ROLE_HIERARCHY = {
3
+ service: 6,
3
4
  owner: 5,
4
5
  admin: 4,
5
6
  member: 3,
6
7
  editor: 2,
7
- viewer: 1
8
+ viewer: 1,
9
+ observer: 0
8
10
  };
9
11
  export function useDocumentPermissions(role) {
10
12
  const level = computed(() => ROLE_HIERARCHY[toValue(role) ?? ""] ?? 0);
@@ -1447,6 +1447,7 @@ export default defineNuxtPlugin({
1447
1447
  } catch {
1448
1448
  }
1449
1449
  try {
1450
+ if (!_provider.canWrite) throw new Error("read-only session");
1450
1451
  const trashMap = _doc.getMap("doc-trash");
1451
1452
  const settings = (() => {
1452
1453
  try {
@@ -1479,8 +1480,12 @@ export default defineNuxtPlugin({
1479
1480
  authFailureCount = 0;
1480
1481
  },
1481
1482
  onAuthenticationFailed({ reason }) {
1482
- authFailureCount++;
1483
1483
  const msg = reason || "Authentication failed";
1484
+ if (/write permission denied|not subscribed/i.test(msg)) {
1485
+ addLog(`Write dropped (read-only session): ${msg}`, "auth");
1486
+ return;
1487
+ }
1488
+ authFailureCount++;
1484
1489
  const isPermanent = /disabled|not allowed|forbidden|revoked/i.test(msg);
1485
1490
  if (isPermanent || authFailureCount >= AUTH_FAILURE_LIMIT) {
1486
1491
  _identityStateBeforeBlock = identityState.value;
@@ -52,14 +52,11 @@ export async function renderDocToHTML(ydoc) {
52
52
  }
53
53
  async function renderDocToJSON(ydoc) {
54
54
  try {
55
- const Y = await import("yjs");
56
55
  const result = {};
57
56
  ydoc.share.forEach((type, key) => {
58
- if (type instanceof Y.Map) {
59
- result[key] = type.toJSON();
60
- } else if (type instanceof Y.Array) {
61
- result[key] = type.toJSON();
62
- }
57
+ if (typeof type?.toJSON !== "function") return;
58
+ const json = type.toJSON();
59
+ if (json !== null && typeof json === "object") result[key] = json;
63
60
  });
64
61
  return result;
65
62
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abraca/nuxt",
3
- "version": "2.59.0",
3
+ "version": "2.61.0",
4
4
  "description": "First-class Nuxt module for the Abracadabra CRDT collaboration platform",
5
5
  "repository": "abracadabra/abracadabra-nuxt",
6
6
  "license": "MIT",