@ai4b-team/fsaos-gateway-sdk 5.7.0 → 5.7.1

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/iife/ui.js CHANGED
@@ -1,3 +1,3 @@
1
- /* @fsaos/ui v2.0.0 — FSAOS UI Primitives — 2026-11-16T03:22:12.647Z */
1
+ /* @fsaos/ui v2.0.0 — FSAOS UI Primitives — 2026-11-16T04:34:20.646Z */
2
2
  "use strict";var __FSAOS_UI__=(()=>{var m=Object.create;var r=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty;var y=(e,i)=>()=>(i||e((i={exports:{}}).exports,i),i.exports),N=(e,i)=>{for(var a in i)r(e,a,{get:i[a],enumerable:!0})},s=(e,i,a,l)=>{if(i&&typeof i=="object"||typeof i=="function")for(let t of u(i))!h.call(e,t)&&t!==a&&r(e,t,{get:()=>i[t],enumerable:!(l=g(i,t))||l.enumerable});return e};var x=(e,i,a)=>(a=e!=null?m(f(e)):{},s(i||!e||!e.__esModule?r(a,"default",{value:e,enumerable:!0}):a,e)),b=e=>s(r({},"__esModule",{value:!0}),e);var d=y((V,c)=>{c.exports=React});var P={};N(P,{Badge:()=>z,Breadcrumbs:()=>A,Button:()=>D,Card:()=>w,DataView:()=>R,Detail:()=>_,Empty:()=>I,FilePreview:()=>O,Form:()=>F,Grid:()=>k,Image:()=>G,Link:()=>E,Page:()=>v,Router:()=>T,Sidebar:()=>S,Spinner:()=>B,Stack:()=>C,Table:()=>j,Tabs:()=>W,Video:()=>H});var n=x(d(),1);function o(){return(typeof window<"u"&&window.__FSAOS_CONFIG__||{}).edgeBaseUrl||""}function v(e){return(0,n.createElement)("div",{style:{minHeight:"100vh",display:"flex",flexDirection:"column"},className:e.className||""},e.children)}function C(e){let i=e.direction||"vertical";return(0,n.createElement)("div",{style:{display:"flex",flexDirection:i==="horizontal"?"row":"column",gap:e.gap||"0.5rem",padding:e.padding||"0",alignItems:e.align||"stretch",justifyContent:e.justify||"flex-start",flex:e.flex||"initial"},className:e.className||""},e.children)}function k(e){return(0,n.createElement)("div",{style:{display:"grid",gridTemplateColumns:"repeat("+(e.columns||3)+", 1fr)",gap:e.gap||"1rem",padding:e.padding||"0"},className:e.className||""},e.children)}function S(e){return(0,n.createElement)("div",{style:{display:"flex",flexDirection:"row",minHeight:"100vh"},className:e.className||""},e.children)}function w(e){return(0,n.createElement)("div",{style:{border:"1px solid var(--color-border, #e5e7eb)",borderRadius:"var(--border-radius, 0.5rem)",padding:e.padding||"1rem",background:"var(--color-surface, #fff)"},className:e.className||"",onClick:e.onClick},e.children)}function z(e){return(0,n.createElement)("span",{style:{display:"inline-flex",alignItems:"center",padding:"0.125rem 0.5rem",fontSize:"0.75rem",fontWeight:"500",borderRadius:"9999px",background:e.color||"#e5e7eb",color:e.textColor||"#374151"},className:e.className||""},e.children||e.label)}function B(e){let i=e.size||"1.5rem";return(0,n.createElement)("div",{style:{width:i,height:i,border:"2px solid #e5e7eb",borderTopColor:"var(--color-primary, #3b82f6)",borderRadius:"50%",animation:"fsaos-spin 0.6s linear infinite"}})}function D(e){return(0,n.createElement)("button",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:"0.5rem 1rem",fontSize:"0.875rem",fontWeight:"500",borderRadius:"var(--border-radius, 0.375rem)",border:e.variant==="outline"?"1px solid var(--color-border, #d1d5db)":"none",background:e.variant==="outline"||e.variant==="ghost"?"transparent":"var(--color-primary, #3b82f6)",color:e.variant==="outline"||e.variant==="ghost"?"var(--color-text, #1a1a1a)":"#fff",cursor:e.disabled?"not-allowed":"pointer",opacity:e.disabled?"0.5":"1",gap:"0.5rem"},className:e.className||"",onClick:e.onClick,disabled:e.disabled},e.children||e.label)}function I(e){return(0,n.createElement)("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"3rem",color:"var(--color-text-secondary, #6b7280)",textAlign:"center"}},e.icon?(0,n.createElement)("div",{style:{fontSize:"2rem",marginBottom:"0.5rem"}},e.icon):null,(0,n.createElement)("div",{style:{fontWeight:500,marginBottom:"0.25rem"}},e.title||e.message||e.children||"No items"),e.description?(0,n.createElement)("div",{style:{fontSize:"0.875rem",opacity:.7}},e.description):null)}function R(e){return(0,n.createElement)("div",{className:e.className||""},e.children)}function j(e){return(0,n.createElement)("table",{className:e.className||""},e.children)}function F(e){return(0,n.createElement)("form",{className:e.className||"",onSubmit:e.onSubmit},e.children)}function _(e){return(0,n.createElement)("div",{className:e.className||""},e.children)}function T(e){return(0,n.createElement)("div",null,e.children)}function E(e){return(0,n.createElement)("a",{href:e.href||e.to,className:e.className||"",onClick:e.onClick},e.children)}function W(e){return(0,n.createElement)("div",{className:e.className||""},e.children)}function A(e){return(0,n.createElement)("nav",{className:e.className||""},e.children)}function G(e){return(0,n.createElement)("img",{src:e.src||(e.path?o()+e.path:""),alt:e.alt||"",className:e.className||"",style:e.style})}function H(e){return(0,n.createElement)("video",{src:e.src||(e.path?o()+e.path:""),controls:!0,className:e.className||""})}function O(e){return(0,n.createElement)("div",{className:e.className||""},e.children||"File preview")}return b(P);})();
3
3
  //# sourceMappingURL=ui.js.map
package/dist/index.cjs CHANGED
@@ -736,7 +736,7 @@ function resetGatewayReads() {
736
736
  }
737
737
  function isScheduledRead(method, params) {
738
738
  if (method === "query") return !("materialize" in params);
739
- return ["read", "list", "search", "resolve", "resolve-items", "get-channel-messages", "list-memberships", "message-replies"].includes(method);
739
+ return ["read", "list", "search", "resolve", "resolve-items", "get-channel-messages", "list-memberships", "message-replies", "check-item-access"].includes(method);
740
740
  }
741
741
  function readRequestKey(value) {
742
742
  if (Array.isArray(value)) return `[${value.map(readRequestKey).join(",")}]`;
@@ -759,18 +759,18 @@ function scheduleRead(key, method, options, run) {
759
759
  };
760
760
  jobs.set(key, job);
761
761
  waiting.push(job);
762
- const pending4 = job;
762
+ const pending5 = job;
763
763
  job.timer = setTimeout(() => {
764
- pending4.controller.abort();
764
+ pending5.controller.abort();
765
765
  const error = new Error("The read timed out. Please retry.");
766
766
  error.name = "TimeoutError";
767
- for (const consumer of pending4.consumers) {
767
+ for (const consumer of pending5.consumers) {
768
768
  consumer.detach();
769
769
  consumer.reject(error);
770
770
  }
771
- pending4.consumers.clear();
772
- if (jobs.get(pending4.key) === pending4) jobs.delete(pending4.key);
773
- discardQueued(pending4);
771
+ pending5.consumers.clear();
772
+ if (jobs.get(pending5.key) === pending5) jobs.delete(pending5.key);
773
+ discardQueued(pending5);
774
774
  }, config.timeoutMs);
775
775
  } else if (rank[options.priority ?? "normal"] < rank[job.priority]) {
776
776
  job.priority = options.priority ?? "normal";
@@ -993,8 +993,8 @@ function refreshQuery(client2, queryKey, options = {}) {
993
993
  queued = /* @__PURE__ */ new Map();
994
994
  trailing.set(client2, queued);
995
995
  }
996
- const pending4 = queued.get(hash);
997
- if (pending4) return pending4;
996
+ const pending5 = queued.get(hash);
997
+ if (pending5) return pending5;
998
998
  const queue = queued;
999
999
  const next = Promise.allSettled(running2).then(() => {
1000
1000
  queue.delete(hash);
@@ -1053,6 +1053,52 @@ function clearArrangementRefreshes(client2) {
1053
1053
  pending2.get(client2)?.forEach(clearTimeout);
1054
1054
  pending2.delete(client2);
1055
1055
  }
1056
+
1057
+ // src/permission-cache.ts
1058
+ var pending3 = /* @__PURE__ */ new WeakMap();
1059
+ var accessEdges = /* @__PURE__ */ new Set(["shared_with", "has_member", "member_of", "owned_by"]);
1060
+ function invalidate(client2, query) {
1061
+ let timers = pending3.get(client2);
1062
+ if (!timers) {
1063
+ timers = /* @__PURE__ */ new Map();
1064
+ pending3.set(client2, timers);
1065
+ }
1066
+ if (timers.has(query)) return;
1067
+ void client2.cancelQueries({ queryKey: query.queryKey, exact: true });
1068
+ void client2.invalidateQueries({ queryKey: query.queryKey, exact: true, refetchType: "none" });
1069
+ if (!query.isActive()) return;
1070
+ timers.set(query, setTimeout(() => {
1071
+ timers.delete(query);
1072
+ if (client2.getQueryCache().get(query.queryHash) !== query || !query.isActive()) return;
1073
+ void refreshQuery(client2, query.queryKey, { exact: true });
1074
+ }, 250));
1075
+ }
1076
+ function handlePermissionChange(client2, event, type) {
1077
+ const edge = type === "ccm_change";
1078
+ if (edge && !accessEdges.has(event.edge_type)) return;
1079
+ const paths = [event.path, event.old_path, event.source_path].filter((path) => typeof path === "string");
1080
+ const ids = [event.item_id, event.source_item_id, event.source_id, event.target_item_id, event.target_id].filter(Boolean);
1081
+ if (!paths.length && !ids.length) return;
1082
+ for (const query of client2.getQueryCache().findAll({ queryKey: ["vfs"] })) {
1083
+ const meta = query.meta?.permissionQuery;
1084
+ if (!meta?.scope) continue;
1085
+ const direct = Boolean(meta.itemId && ids.includes(meta.itemId));
1086
+ const ancestor = Boolean(meta.path && paths.some((path) => isChannelPath(meta.path, path)));
1087
+ const scope = meta.scope;
1088
+ const scoped = paths.some((path) => isChannelPath(path, scope) || isChannelPath(scope, path)) || [event.scope_item_id, event.account_item_id, event.space_item_id].some((id) => id && meta.scopeIds.includes(id));
1089
+ const inherited = scoped && (event.item_type === "member" || event.item_type === "principal" || edge);
1090
+ if (direct || ancestor || !meta.targetLookup && inherited) invalidate(client2, query);
1091
+ }
1092
+ }
1093
+ function refreshPermissionsAfterReconnect(client2) {
1094
+ for (const query of client2.getQueryCache().findAll({ queryKey: ["vfs"] })) {
1095
+ if (query.meta?.permissionQuery) invalidate(client2, query);
1096
+ }
1097
+ }
1098
+ function clearPermissionRefreshes(client2) {
1099
+ pending3.get(client2)?.forEach((timer) => clearTimeout(timer));
1100
+ pending3.delete(client2);
1101
+ }
1056
1102
  var client = null;
1057
1103
  registerCleanup(() => {
1058
1104
  if (!client) return;
@@ -1093,7 +1139,7 @@ var queryClient = new Proxy({}, {
1093
1139
  });
1094
1140
 
1095
1141
  // src/item-query-realtime.ts
1096
- var pending3 = /* @__PURE__ */ new WeakMap();
1142
+ var pending4 = /* @__PURE__ */ new WeakMap();
1097
1143
  function listingFilter(query) {
1098
1144
  return query.meta?.infiniteItemsRealtime?.filter;
1099
1145
  }
@@ -1132,10 +1178,10 @@ function affectsListing(query, filter, event) {
1132
1178
  return hasPath || Boolean(filter.parent_id && event.parent_id === filter.parent_id);
1133
1179
  }
1134
1180
  function schedule(client2, query) {
1135
- let timers = pending3.get(client2);
1181
+ let timers = pending4.get(client2);
1136
1182
  if (!timers) {
1137
1183
  timers = /* @__PURE__ */ new Map();
1138
- pending3.set(client2, timers);
1184
+ pending4.set(client2, timers);
1139
1185
  }
1140
1186
  const previous = timers.get(query.queryHash);
1141
1187
  if (previous) clearTimeout(previous);
@@ -1158,8 +1204,8 @@ function refreshInfiniteItemsAfterReconnect(client2) {
1158
1204
  }
1159
1205
  }
1160
1206
  function clearInfiniteItemsRefreshes(client2) {
1161
- pending3.get(client2)?.forEach(clearTimeout);
1162
- pending3.delete(client2);
1207
+ pending4.get(client2)?.forEach(clearTimeout);
1208
+ pending4.delete(client2);
1163
1209
  }
1164
1210
 
1165
1211
  // src/items-selection.ts
@@ -1509,6 +1555,7 @@ function catchUpAfterGap(reason) {
1509
1555
  const qc = getQueryClient();
1510
1556
  refreshInfiniteItemsAfterReconnect(qc);
1511
1557
  reconnectArrangements(qc);
1558
+ refreshPermissionsAfterReconnect(qc);
1512
1559
  for (const sub of activePaths.values()) {
1513
1560
  void qc.invalidateQueries({ queryKey: vfsKeys.item(sub.path) });
1514
1561
  void qc.invalidateQueries({ queryKey: vfsKeys.children(sub.path) });
@@ -1546,6 +1593,9 @@ function handleMessage(raw) {
1546
1593
  if (msg.type === "event" || msg.event_type) {
1547
1594
  const eventType = msg.event_type || "message";
1548
1595
  const data = msg.data || msg;
1596
+ if (eventType === "vfs_change" || eventType === "ccm_change") {
1597
+ handlePermissionChange(getQueryClient(), data, eventType);
1598
+ }
1549
1599
  if (eventType === "vfs_change") {
1550
1600
  handleInfiniteItemsChange(getQueryClient(), data);
1551
1601
  handleArrangementChange(getQueryClient(), data);
@@ -1675,6 +1725,7 @@ function disconnectSSE() {
1675
1725
  log("disconnectSSE: tearing down");
1676
1726
  clearInfiniteItemsRefreshes(getQueryClient());
1677
1727
  clearArrangementRefreshes(getQueryClient());
1728
+ clearPermissionRefreshes(getQueryClient());
1678
1729
  intentionalClose = true;
1679
1730
  stopPing();
1680
1731
  if (ws) {
@@ -3045,13 +3096,13 @@ function watchChannelTranscript(client2, key, channel, limit) {
3045
3096
  let timer;
3046
3097
  let running2 = false;
3047
3098
  let stopped = false;
3048
- const pending4 = /* @__PURE__ */ new Map();
3099
+ const pending5 = /* @__PURE__ */ new Map();
3049
3100
  const current = () => client2.getQueryData(key);
3050
3101
  const query = () => client2.getQueryCache().find({ queryKey: key, exact: true });
3051
3102
  const reload = () => refreshQuery(client2, key, { exact: true });
3052
3103
  const read = (after_seq, before_seq) => fetchChannelMessagesPage(channel, { transcriptOnly: true, limit, after_seq, before_seq });
3053
3104
  const schedule2 = () => {
3054
- if (stopped || running2 || timer || !pending4.size) return;
3105
+ if (stopped || running2 || timer || !pending5.size) return;
3055
3106
  timer = setTimeout(() => {
3056
3107
  timer = void 0;
3057
3108
  void flush();
@@ -3059,8 +3110,8 @@ function watchChannelTranscript(client2, key, channel, limit) {
3059
3110
  };
3060
3111
  const flush = async () => {
3061
3112
  running2 = true;
3062
- const changes = [...pending4.values()];
3063
- pending4.clear();
3113
+ const changes = [...pending5.values()];
3114
+ pending5.clear();
3064
3115
  const owner = query();
3065
3116
  try {
3066
3117
  if (owner?.state.fetchStatus === "fetching") await owner.promise?.catch(() => void 0);
@@ -3134,15 +3185,15 @@ function watchChannelTranscript(client2, key, channel, limit) {
3134
3185
  };
3135
3186
  const stop = subscribeToEvents("vfs_change", (change) => {
3136
3187
  const id = change.item_id ?? change.path;
3137
- const previous = pending4.get(id);
3138
- pending4.set(id, previous && (previous.inserted || isNewPost(previous, channel)) && actionOf(change) === "update" && previous.path === change.path ? { ...change, inserted: true } : change);
3188
+ const previous = pending5.get(id);
3189
+ pending5.set(id, previous && (previous.inserted || isNewPost(previous, channel)) && actionOf(change) === "update" && previous.path === change.path ? { ...change, inserted: true } : change);
3139
3190
  schedule2();
3140
3191
  }, (change) => channelMessageChange(change, channel, void 0, []) || !!change.old_path && channelMessageChange({ ...change, path: change.old_path }, channel, void 0, []) || change.item_type === "message" && !!change.parent_id && isChannelPath(change.path, channel) && !!current()?.pages.some((page) => page.messages.some((root) => root.id === change.parent_id)));
3141
3192
  watch = { users: 0, stop: () => {
3142
3193
  stopped = true;
3143
3194
  stop();
3144
3195
  if (timer) clearTimeout(timer);
3145
- pending4.clear();
3196
+ pending5.clear();
3146
3197
  } };
3147
3198
  entries.set(hash, watch);
3148
3199
  }
@@ -3188,7 +3239,7 @@ function watchChannels(client2, key, normalize) {
3188
3239
  running2 = true;
3189
3240
  const reload = inventory;
3190
3241
  inventory = false;
3191
- const pending4 = [...channels];
3242
+ const pending5 = [...channels];
3192
3243
  const checkRename = new Set(renames);
3193
3244
  renames.clear();
3194
3245
  channels.clear();
@@ -3196,7 +3247,7 @@ function watchChannels(client2, key, normalize) {
3196
3247
  if (reload) {
3197
3248
  await refreshQuery(client2, key, { exact: true });
3198
3249
  } else {
3199
- const results = await Promise.allSettled(pending4.map(async (id) => {
3250
+ const results = await Promise.allSettled(pending5.map(async (id) => {
3200
3251
  const owner = client2.getQueryCache().find({ queryKey: key, exact: true });
3201
3252
  if (!owner) return;
3202
3253
  const result = await gatewayCall("read", { id });
@@ -3328,6 +3379,92 @@ function watchMessageReplies(client2, key, target) {
3328
3379
  }
3329
3380
  };
3330
3381
  }
3382
+ var actions = /* @__PURE__ */ new Set(["view", "edit", "delete", "admin"]);
3383
+ var uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
3384
+ function targetFromRead(response) {
3385
+ const raw = response.item ?? response;
3386
+ const id = raw.id ?? raw.item_id;
3387
+ const path = raw.path ?? raw.item_path;
3388
+ if (response.success !== true || typeof id !== "string" || !uuid.test(id)) {
3389
+ throw new Error("PERMISSION_TARGET_UNAVAILABLE");
3390
+ }
3391
+ return { id, ...typeof path === "string" ? { path } : {} };
3392
+ }
3393
+ function usePermissions(item, requested) {
3394
+ React.useSyncExternalStore(subscribeScope, getScopeVersion, getScopeVersion);
3395
+ const epoch = React.useSyncExternalStore(subscribeSession, getSessionVersion, getSessionVersion);
3396
+ const mounts = React.useSyncExternalStore(subscribeMounts, getMountVersion, getMountVersion);
3397
+ const scope = getScope();
3398
+ const principal = getSessionEntry()?.principal_id;
3399
+ const target = item?.trim() ?? "";
3400
+ const wanted = [...new Set(requested ?? [])].sort();
3401
+ const directId = uuid.test(target);
3402
+ const validTarget = directId || (target.startsWith("/root/") || target === "/root");
3403
+ const invalid = wanted.some((action) => !actions.has(action)) || Boolean(target && !validTarget);
3404
+ const enabled2 = Boolean(scope && principal && target && wanted.length && !invalid);
3405
+ const root = ["vfs", scope ?? "__unscoped__", "permissions", principal ?? "__anonymous__", epoch, mounts];
3406
+ const scopeIds = [...new Set([getAnchorRef()?.id, ...getMounts().map((mount3) => mount3.id)].filter((id) => Boolean(id)))];
3407
+ const targetKey = [...root, "target", target];
3408
+ const identity = reactQuery.useQuery({
3409
+ queryKey: targetKey,
3410
+ queryFn: async ({ signal: signal2 }) => {
3411
+ if (!enabled2 || !scope) throw new Error("PERMISSION_CONTEXT_REQUIRED");
3412
+ return targetFromRead(await gatewayCall("read", { path: target, _scope_path: scope }, { signal: signal2 }));
3413
+ },
3414
+ enabled: enabled2 && !directId,
3415
+ staleTime: Infinity,
3416
+ gcTime: 0,
3417
+ retry: false,
3418
+ refetchOnWindowFocus: false,
3419
+ refetchOnReconnect: false,
3420
+ refetchOnMount: false,
3421
+ meta: { permissionQuery: { scope, scopeIds, path: target, targetLookup: true } }
3422
+ });
3423
+ const resolved = directId ? { id: target } : identity.data;
3424
+ const identityReady = directId || identity.isSuccess && !identity.isFetching && !identity.isStale;
3425
+ const checks = reactQuery.useQueries({ queries: wanted.filter((action) => actions.has(action)).map((action) => ({
3426
+ queryKey: [...root, "check", resolved?.id ?? target, action],
3427
+ queryFn: async ({ signal: signal2 }) => {
3428
+ if (!enabled2 || !scope || !resolved) throw new Error("PERMISSION_CONTEXT_REQUIRED");
3429
+ const result = await gatewayCall("check-item-access", { id: resolved.id, action, _scope_path: scope }, { signal: signal2 });
3430
+ if (result.success !== true || typeof result.allowed !== "boolean") throw new Error("PERMISSION_RESPONSE_INVALID");
3431
+ return result.allowed;
3432
+ },
3433
+ enabled: enabled2 && identityReady && Boolean(resolved),
3434
+ staleTime: Infinity,
3435
+ gcTime: 0,
3436
+ retry: false,
3437
+ refetchOnWindowFocus: false,
3438
+ refetchOnReconnect: false,
3439
+ refetchOnMount: false,
3440
+ meta: { permissionQuery: { scope, scopeIds, itemId: resolved?.id, path: resolved?.path ?? (directId ? void 0 : target) } }
3441
+ })) });
3442
+ const error = invalid ? new Error("PERMISSION_INPUT_INVALID") : !directId && identity.error || checks.find((check) => check.error)?.error || null;
3443
+ const verified = enabled2 && identityReady && !error;
3444
+ const supported = wanted.filter((action) => actions.has(action));
3445
+ const data = Object.fromEntries(wanted.map((action) => {
3446
+ const check = checks[supported.indexOf(action)];
3447
+ return [action, Boolean(verified && check?.isSuccess && !check.isFetching && !check.isStale && check.data === true)];
3448
+ }));
3449
+ return {
3450
+ data,
3451
+ loading: Boolean(enabled2 && (!directId && identity.isFetching || checks.some((check) => check.isFetching || check.isPending)) && !error),
3452
+ error,
3453
+ /** Explicit refresh for a user action; no automatic retry or polling. */
3454
+ refetch: async () => {
3455
+ if (!enabled2) return;
3456
+ if (!directId && (!identity.data || identity.isError)) {
3457
+ await identity.refetch();
3458
+ return;
3459
+ }
3460
+ await Promise.all(checks.map((check) => check.refetch()));
3461
+ }
3462
+ };
3463
+ }
3464
+ function usePermission(action, item) {
3465
+ const result = usePermissions(item, action ? [action] : []);
3466
+ return { ...result, data: { allowed: Boolean(action && result.data[action]) } };
3467
+ }
3331
3468
 
3332
3469
  // src/hooks.ts
3333
3470
  function useScopeKey() {
@@ -3536,7 +3673,7 @@ function useIncrementalItems(filter, options = {}) {
3536
3673
  let wasConnected = false;
3537
3674
  let missed = false;
3538
3675
  let generation = 0;
3539
- const pending4 = /* @__PURE__ */ new Map();
3676
+ const pending5 = /* @__PURE__ */ new Map();
3540
3677
  const reconcile = () => {
3541
3678
  const started = generation;
3542
3679
  void refetch.current().then((result) => {
@@ -3553,18 +3690,18 @@ function useIncrementalItems(filter, options = {}) {
3553
3690
  delete upserts[path];
3554
3691
  return { identity, upserts, deleted: new Set(state.deleted).add(path) };
3555
3692
  });
3556
- const earlier = pending4.get("__reconcile__");
3693
+ const earlier = pending5.get("__reconcile__");
3557
3694
  if (earlier) clearTimeout(earlier);
3558
- pending4.set("__reconcile__", setTimeout(() => {
3559
- pending4.delete("__reconcile__");
3695
+ pending5.set("__reconcile__", setTimeout(() => {
3696
+ pending5.delete("__reconcile__");
3560
3697
  reconcile();
3561
3698
  }, 250));
3562
3699
  };
3563
3700
  const readOne = (path) => {
3564
- const earlier = pending4.get(path);
3701
+ const earlier = pending5.get(path);
3565
3702
  if (earlier) clearTimeout(earlier);
3566
- pending4.set(path, setTimeout(() => {
3567
- pending4.delete(path);
3703
+ pending5.set(path, setTimeout(() => {
3704
+ pending5.delete(path);
3568
3705
  void client2.fetchQuery({ queryKey: vfsKeys.item(path), queryFn: () => fetchVfsItem(path), staleTime: 0 }).then((item) => {
3569
3706
  if (stopped) return;
3570
3707
  if (!item || !itemMatchesIncrementalFilter(item, selected)) {
@@ -3627,7 +3764,7 @@ function useIncrementalItems(filter, options = {}) {
3627
3764
  stopped = true;
3628
3765
  stopEvents();
3629
3766
  stopConnection();
3630
- pending4.forEach(clearTimeout);
3767
+ pending5.forEach(clearTimeout);
3631
3768
  };
3632
3769
  }, [client2, identity]);
3633
3770
  return { ...query, allItems };
@@ -4383,15 +4520,15 @@ async function readPublishedBundle(componentId, releaseItemId, version) {
4383
4520
  return { status: "ready", releaseItemId, version, script, stylesheet: stylesheet?.trim() ? stylesheet : null };
4384
4521
  }
4385
4522
  function publishedBundle(componentId, releaseItemId, version) {
4386
- let pending4 = publishedBundles.get(releaseItemId);
4387
- if (!pending4) {
4388
- pending4 = readPublishedBundle(componentId, releaseItemId, version);
4389
- publishedBundles.set(releaseItemId, pending4);
4390
- pending4.catch(() => {
4391
- if (publishedBundles.get(releaseItemId) === pending4) publishedBundles.delete(releaseItemId);
4523
+ let pending5 = publishedBundles.get(releaseItemId);
4524
+ if (!pending5) {
4525
+ pending5 = readPublishedBundle(componentId, releaseItemId, version);
4526
+ publishedBundles.set(releaseItemId, pending5);
4527
+ pending5.catch(() => {
4528
+ if (publishedBundles.get(releaseItemId) === pending5) publishedBundles.delete(releaseItemId);
4392
4529
  });
4393
4530
  }
4394
- return pending4;
4531
+ return pending5;
4395
4532
  }
4396
4533
  function loadPublishedBundle(source) {
4397
4534
  const live = liveRelease(source);
@@ -4515,16 +4652,6 @@ function useTheme() {
4515
4652
  }, []);
4516
4653
  return { data: themeData, loading: false, error: null };
4517
4654
  }
4518
- function usePermission(_action, _path) {
4519
- return { data: { allowed: true }, loading: false, error: null };
4520
- }
4521
- function usePermissions(_path, actions) {
4522
- const perms = {};
4523
- (actions || []).forEach((a) => {
4524
- perms[a] = true;
4525
- });
4526
- return { data: perms, loading: false, error: null };
4527
- }
4528
4655
  var _principalIdCache = null;
4529
4656
  var _principalIdPromise = null;
4530
4657
  var _principalListeners = /* @__PURE__ */ new Set();
@@ -5621,7 +5748,7 @@ function usePersonalItemOrder(key, items, space) {
5621
5748
  return [...unplaced, ...arranged.filter((item) => savedIds.has(item.id))];
5622
5749
  }, [key, items, query.applyTo, query.order]);
5623
5750
  const client2 = reactQuery.useQueryClient();
5624
- const pending4 = React.useRef(false);
5751
+ const pending5 = React.useRef(false);
5625
5752
  const ready = Boolean(supported && !query.error && query.arrangement?.item_id && query.resolutionLevel === "member" && query.arrangement.write_target_id === query.arrangement.item_id);
5626
5753
  const mutation = reactQuery.useMutation({
5627
5754
  mutationFn: async (change) => {
@@ -5639,7 +5766,7 @@ function usePersonalItemOrder(key, items, space) {
5639
5766
  if (!ready || !scopePath || identity !== activeIdentity.current || generation !== getScopeVersion() || getScope() !== mountedScope) {
5640
5767
  throw new Error("Personal order is not available in this Space");
5641
5768
  }
5642
- if (pending4.current) throw new Error("An order change is already being saved");
5769
+ if (pending5.current) throw new Error("An order change is already being saved");
5643
5770
  const visibleIds = items.map((item) => item.id);
5644
5771
  if (ids.length !== visibleIds.length || new Set(ids).size !== visibleIds.length || visibleIds.some((id) => !ids.includes(id))) throw new Error("Order must include each displayed item exactly once");
5645
5772
  const cached = client2.getQueryData(query.arrangementQueryKey);
@@ -5652,7 +5779,7 @@ function usePersonalItemOrder(key, items, space) {
5652
5779
  let index = 0;
5653
5780
  const saved = (query.order ?? []).map((id) => visible.has(id) ? ids[index++] : id);
5654
5781
  const order = [...saved, ...ids.slice(index)];
5655
- pending4.current = true;
5782
+ pending5.current = true;
5656
5783
  try {
5657
5784
  return await mutation.mutateAsync({
5658
5785
  ids: order,
@@ -5661,7 +5788,7 @@ function usePersonalItemOrder(key, items, space) {
5661
5788
  queryKey: query.arrangementQueryKey
5662
5789
  });
5663
5790
  } finally {
5664
- pending4.current = false;
5791
+ pending5.current = false;
5665
5792
  }
5666
5793
  }
5667
5794
  return {
@@ -7409,7 +7536,7 @@ function usePersonalSections(contextId, collection) {
7409
7536
  meta: { arrangementRealtime: true, personalSections: true },
7410
7537
  structuralSharing: (previous, next) => newestSnapshot(previous, next)
7411
7538
  });
7412
- const pending4 = React.useRef(false);
7539
+ const pending5 = React.useRef(false);
7413
7540
  const mutation = reactQuery.useMutation({ mutationFn: async (write) => {
7414
7541
  const data = await call(write.scope, write.context, write.collection, {
7415
7542
  ...write.change,
@@ -7422,12 +7549,12 @@ function usePersonalSections(contextId, collection) {
7422
7549
  if (!scopePath || !contextId || generation !== getScopeVersion() || getScope() !== scopePath || !query.data || query.error) {
7423
7550
  throw new Error("Select the Space again before changing sections");
7424
7551
  }
7425
- if (pending4.current) throw new Error("A section change is still being saved");
7426
- pending4.current = true;
7552
+ if (pending5.current) throw new Error("A section change is still being saved");
7553
+ pending5.current = true;
7427
7554
  try {
7428
7555
  return await mutation.mutateAsync({ change: value, scope: scopePath, context: contextId, collection, version: query.data.version });
7429
7556
  } finally {
7430
- pending4.current = false;
7557
+ pending5.current = false;
7431
7558
  }
7432
7559
  }
7433
7560
  function destination(sectionId) {