@ai4b-team/fsaos-gateway-sdk 5.7.0 → 5.8.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/README.md +54 -0
- package/dist/iife/gateway.js +5 -5
- package/dist/iife/gateway.js.map +4 -4
- package/dist/iife/ui.js +1 -1
- package/dist/index.cjs +324 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +81 -15
- package/dist/index.d.ts +81 -15
- package/dist/index.js +325 -59
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/iife/ui.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* @fsaos/ui v2.0.0 — FSAOS UI Primitives — 2026-11-
|
|
1
|
+
/* @fsaos/ui v2.0.0 — FSAOS UI Primitives — 2026-11-22T15:58:44.492Z */
|
|
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
|
@@ -136,6 +136,7 @@ __export(src_exports, {
|
|
|
136
136
|
itemsFilterFromQueryFilter: () => itemsFilterFromQueryFilter,
|
|
137
137
|
listChildren: () => listChildren,
|
|
138
138
|
listInvitations: () => listInvitations,
|
|
139
|
+
loadCompiledBundle: () => loadCompiledBundle,
|
|
139
140
|
loadMounts: () => loadMounts,
|
|
140
141
|
loadPublishedBundle: () => loadPublishedBundle,
|
|
141
142
|
mount: () => mount2,
|
|
@@ -198,6 +199,7 @@ __export(src_exports, {
|
|
|
198
199
|
useChannelMessages: () => useChannelMessages,
|
|
199
200
|
useChannels: () => useChannels,
|
|
200
201
|
useChildren: () => useChildren,
|
|
202
|
+
useCompiledComponent: () => useCompiledComponent,
|
|
201
203
|
useComponent: () => useComponent,
|
|
202
204
|
useCreate: () => useCreate,
|
|
203
205
|
useCreateAgent: () => useCreateAgent,
|
|
@@ -736,7 +738,7 @@ function resetGatewayReads() {
|
|
|
736
738
|
}
|
|
737
739
|
function isScheduledRead(method, params) {
|
|
738
740
|
if (method === "query") return !("materialize" in params);
|
|
739
|
-
return ["read", "list", "search", "resolve", "resolve-items", "get-channel-messages", "list-memberships", "message-replies"].includes(method);
|
|
741
|
+
return ["read", "list", "search", "resolve", "resolve-items", "get-channel-messages", "list-memberships", "message-replies", "check-item-access"].includes(method);
|
|
740
742
|
}
|
|
741
743
|
function readRequestKey(value) {
|
|
742
744
|
if (Array.isArray(value)) return `[${value.map(readRequestKey).join(",")}]`;
|
|
@@ -759,18 +761,18 @@ function scheduleRead(key, method, options, run) {
|
|
|
759
761
|
};
|
|
760
762
|
jobs.set(key, job);
|
|
761
763
|
waiting.push(job);
|
|
762
|
-
const
|
|
764
|
+
const pending5 = job;
|
|
763
765
|
job.timer = setTimeout(() => {
|
|
764
|
-
|
|
766
|
+
pending5.controller.abort();
|
|
765
767
|
const error = new Error("The read timed out. Please retry.");
|
|
766
768
|
error.name = "TimeoutError";
|
|
767
|
-
for (const consumer of
|
|
769
|
+
for (const consumer of pending5.consumers) {
|
|
768
770
|
consumer.detach();
|
|
769
771
|
consumer.reject(error);
|
|
770
772
|
}
|
|
771
|
-
|
|
772
|
-
if (jobs.get(
|
|
773
|
-
discardQueued(
|
|
773
|
+
pending5.consumers.clear();
|
|
774
|
+
if (jobs.get(pending5.key) === pending5) jobs.delete(pending5.key);
|
|
775
|
+
discardQueued(pending5);
|
|
774
776
|
}, config.timeoutMs);
|
|
775
777
|
} else if (rank[options.priority ?? "normal"] < rank[job.priority]) {
|
|
776
778
|
job.priority = options.priority ?? "normal";
|
|
@@ -993,8 +995,8 @@ function refreshQuery(client2, queryKey, options = {}) {
|
|
|
993
995
|
queued = /* @__PURE__ */ new Map();
|
|
994
996
|
trailing.set(client2, queued);
|
|
995
997
|
}
|
|
996
|
-
const
|
|
997
|
-
if (
|
|
998
|
+
const pending5 = queued.get(hash);
|
|
999
|
+
if (pending5) return pending5;
|
|
998
1000
|
const queue = queued;
|
|
999
1001
|
const next = Promise.allSettled(running2).then(() => {
|
|
1000
1002
|
queue.delete(hash);
|
|
@@ -1053,6 +1055,52 @@ function clearArrangementRefreshes(client2) {
|
|
|
1053
1055
|
pending2.get(client2)?.forEach(clearTimeout);
|
|
1054
1056
|
pending2.delete(client2);
|
|
1055
1057
|
}
|
|
1058
|
+
|
|
1059
|
+
// src/permission-cache.ts
|
|
1060
|
+
var pending3 = /* @__PURE__ */ new WeakMap();
|
|
1061
|
+
var accessEdges = /* @__PURE__ */ new Set(["shared_with", "has_member", "member_of", "owned_by"]);
|
|
1062
|
+
function invalidate(client2, query) {
|
|
1063
|
+
let timers = pending3.get(client2);
|
|
1064
|
+
if (!timers) {
|
|
1065
|
+
timers = /* @__PURE__ */ new Map();
|
|
1066
|
+
pending3.set(client2, timers);
|
|
1067
|
+
}
|
|
1068
|
+
if (timers.has(query)) return;
|
|
1069
|
+
void client2.cancelQueries({ queryKey: query.queryKey, exact: true });
|
|
1070
|
+
void client2.invalidateQueries({ queryKey: query.queryKey, exact: true, refetchType: "none" });
|
|
1071
|
+
if (!query.isActive()) return;
|
|
1072
|
+
timers.set(query, setTimeout(() => {
|
|
1073
|
+
timers.delete(query);
|
|
1074
|
+
if (client2.getQueryCache().get(query.queryHash) !== query || !query.isActive()) return;
|
|
1075
|
+
void refreshQuery(client2, query.queryKey, { exact: true });
|
|
1076
|
+
}, 250));
|
|
1077
|
+
}
|
|
1078
|
+
function handlePermissionChange(client2, event, type) {
|
|
1079
|
+
const edge = type === "ccm_change";
|
|
1080
|
+
if (edge && !accessEdges.has(event.edge_type)) return;
|
|
1081
|
+
const paths = [event.path, event.old_path, event.source_path].filter((path) => typeof path === "string");
|
|
1082
|
+
const ids = [event.item_id, event.source_item_id, event.source_id, event.target_item_id, event.target_id].filter(Boolean);
|
|
1083
|
+
if (!paths.length && !ids.length) return;
|
|
1084
|
+
for (const query of client2.getQueryCache().findAll({ queryKey: ["vfs"] })) {
|
|
1085
|
+
const meta = query.meta?.permissionQuery;
|
|
1086
|
+
if (!meta?.scope) continue;
|
|
1087
|
+
const direct = Boolean(meta.itemId && ids.includes(meta.itemId));
|
|
1088
|
+
const ancestor = Boolean(meta.path && paths.some((path) => isChannelPath(meta.path, path)));
|
|
1089
|
+
const scope = meta.scope;
|
|
1090
|
+
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));
|
|
1091
|
+
const inherited = scoped && (event.item_type === "member" || event.item_type === "principal" || edge);
|
|
1092
|
+
if (direct || ancestor || !meta.targetLookup && inherited) invalidate(client2, query);
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
function refreshPermissionsAfterReconnect(client2) {
|
|
1096
|
+
for (const query of client2.getQueryCache().findAll({ queryKey: ["vfs"] })) {
|
|
1097
|
+
if (query.meta?.permissionQuery) invalidate(client2, query);
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
function clearPermissionRefreshes(client2) {
|
|
1101
|
+
pending3.get(client2)?.forEach((timer) => clearTimeout(timer));
|
|
1102
|
+
pending3.delete(client2);
|
|
1103
|
+
}
|
|
1056
1104
|
var client = null;
|
|
1057
1105
|
registerCleanup(() => {
|
|
1058
1106
|
if (!client) return;
|
|
@@ -1093,7 +1141,7 @@ var queryClient = new Proxy({}, {
|
|
|
1093
1141
|
});
|
|
1094
1142
|
|
|
1095
1143
|
// src/item-query-realtime.ts
|
|
1096
|
-
var
|
|
1144
|
+
var pending4 = /* @__PURE__ */ new WeakMap();
|
|
1097
1145
|
function listingFilter(query) {
|
|
1098
1146
|
return query.meta?.infiniteItemsRealtime?.filter;
|
|
1099
1147
|
}
|
|
@@ -1132,10 +1180,10 @@ function affectsListing(query, filter, event) {
|
|
|
1132
1180
|
return hasPath || Boolean(filter.parent_id && event.parent_id === filter.parent_id);
|
|
1133
1181
|
}
|
|
1134
1182
|
function schedule(client2, query) {
|
|
1135
|
-
let timers =
|
|
1183
|
+
let timers = pending4.get(client2);
|
|
1136
1184
|
if (!timers) {
|
|
1137
1185
|
timers = /* @__PURE__ */ new Map();
|
|
1138
|
-
|
|
1186
|
+
pending4.set(client2, timers);
|
|
1139
1187
|
}
|
|
1140
1188
|
const previous = timers.get(query.queryHash);
|
|
1141
1189
|
if (previous) clearTimeout(previous);
|
|
@@ -1158,8 +1206,8 @@ function refreshInfiniteItemsAfterReconnect(client2) {
|
|
|
1158
1206
|
}
|
|
1159
1207
|
}
|
|
1160
1208
|
function clearInfiniteItemsRefreshes(client2) {
|
|
1161
|
-
|
|
1162
|
-
|
|
1209
|
+
pending4.get(client2)?.forEach(clearTimeout);
|
|
1210
|
+
pending4.delete(client2);
|
|
1163
1211
|
}
|
|
1164
1212
|
|
|
1165
1213
|
// src/items-selection.ts
|
|
@@ -1509,6 +1557,7 @@ function catchUpAfterGap(reason) {
|
|
|
1509
1557
|
const qc = getQueryClient();
|
|
1510
1558
|
refreshInfiniteItemsAfterReconnect(qc);
|
|
1511
1559
|
reconnectArrangements(qc);
|
|
1560
|
+
refreshPermissionsAfterReconnect(qc);
|
|
1512
1561
|
for (const sub of activePaths.values()) {
|
|
1513
1562
|
void qc.invalidateQueries({ queryKey: vfsKeys.item(sub.path) });
|
|
1514
1563
|
void qc.invalidateQueries({ queryKey: vfsKeys.children(sub.path) });
|
|
@@ -1546,6 +1595,9 @@ function handleMessage(raw) {
|
|
|
1546
1595
|
if (msg.type === "event" || msg.event_type) {
|
|
1547
1596
|
const eventType = msg.event_type || "message";
|
|
1548
1597
|
const data = msg.data || msg;
|
|
1598
|
+
if (eventType === "vfs_change" || eventType === "ccm_change") {
|
|
1599
|
+
handlePermissionChange(getQueryClient(), data, eventType);
|
|
1600
|
+
}
|
|
1549
1601
|
if (eventType === "vfs_change") {
|
|
1550
1602
|
handleInfiniteItemsChange(getQueryClient(), data);
|
|
1551
1603
|
handleArrangementChange(getQueryClient(), data);
|
|
@@ -1675,6 +1727,7 @@ function disconnectSSE() {
|
|
|
1675
1727
|
log("disconnectSSE: tearing down");
|
|
1676
1728
|
clearInfiniteItemsRefreshes(getQueryClient());
|
|
1677
1729
|
clearArrangementRefreshes(getQueryClient());
|
|
1730
|
+
clearPermissionRefreshes(getQueryClient());
|
|
1678
1731
|
intentionalClose = true;
|
|
1679
1732
|
stopPing();
|
|
1680
1733
|
if (ws) {
|
|
@@ -3045,13 +3098,13 @@ function watchChannelTranscript(client2, key, channel, limit) {
|
|
|
3045
3098
|
let timer;
|
|
3046
3099
|
let running2 = false;
|
|
3047
3100
|
let stopped = false;
|
|
3048
|
-
const
|
|
3101
|
+
const pending5 = /* @__PURE__ */ new Map();
|
|
3049
3102
|
const current = () => client2.getQueryData(key);
|
|
3050
3103
|
const query = () => client2.getQueryCache().find({ queryKey: key, exact: true });
|
|
3051
3104
|
const reload = () => refreshQuery(client2, key, { exact: true });
|
|
3052
3105
|
const read = (after_seq, before_seq) => fetchChannelMessagesPage(channel, { transcriptOnly: true, limit, after_seq, before_seq });
|
|
3053
3106
|
const schedule2 = () => {
|
|
3054
|
-
if (stopped || running2 || timer || !
|
|
3107
|
+
if (stopped || running2 || timer || !pending5.size) return;
|
|
3055
3108
|
timer = setTimeout(() => {
|
|
3056
3109
|
timer = void 0;
|
|
3057
3110
|
void flush();
|
|
@@ -3059,8 +3112,8 @@ function watchChannelTranscript(client2, key, channel, limit) {
|
|
|
3059
3112
|
};
|
|
3060
3113
|
const flush = async () => {
|
|
3061
3114
|
running2 = true;
|
|
3062
|
-
const changes = [...
|
|
3063
|
-
|
|
3115
|
+
const changes = [...pending5.values()];
|
|
3116
|
+
pending5.clear();
|
|
3064
3117
|
const owner = query();
|
|
3065
3118
|
try {
|
|
3066
3119
|
if (owner?.state.fetchStatus === "fetching") await owner.promise?.catch(() => void 0);
|
|
@@ -3134,15 +3187,15 @@ function watchChannelTranscript(client2, key, channel, limit) {
|
|
|
3134
3187
|
};
|
|
3135
3188
|
const stop = subscribeToEvents("vfs_change", (change) => {
|
|
3136
3189
|
const id = change.item_id ?? change.path;
|
|
3137
|
-
const previous =
|
|
3138
|
-
|
|
3190
|
+
const previous = pending5.get(id);
|
|
3191
|
+
pending5.set(id, previous && (previous.inserted || isNewPost(previous, channel)) && actionOf(change) === "update" && previous.path === change.path ? { ...change, inserted: true } : change);
|
|
3139
3192
|
schedule2();
|
|
3140
3193
|
}, (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
3194
|
watch = { users: 0, stop: () => {
|
|
3142
3195
|
stopped = true;
|
|
3143
3196
|
stop();
|
|
3144
3197
|
if (timer) clearTimeout(timer);
|
|
3145
|
-
|
|
3198
|
+
pending5.clear();
|
|
3146
3199
|
} };
|
|
3147
3200
|
entries.set(hash, watch);
|
|
3148
3201
|
}
|
|
@@ -3188,7 +3241,7 @@ function watchChannels(client2, key, normalize) {
|
|
|
3188
3241
|
running2 = true;
|
|
3189
3242
|
const reload = inventory;
|
|
3190
3243
|
inventory = false;
|
|
3191
|
-
const
|
|
3244
|
+
const pending5 = [...channels];
|
|
3192
3245
|
const checkRename = new Set(renames);
|
|
3193
3246
|
renames.clear();
|
|
3194
3247
|
channels.clear();
|
|
@@ -3196,7 +3249,7 @@ function watchChannels(client2, key, normalize) {
|
|
|
3196
3249
|
if (reload) {
|
|
3197
3250
|
await refreshQuery(client2, key, { exact: true });
|
|
3198
3251
|
} else {
|
|
3199
|
-
const results = await Promise.allSettled(
|
|
3252
|
+
const results = await Promise.allSettled(pending5.map(async (id) => {
|
|
3200
3253
|
const owner = client2.getQueryCache().find({ queryKey: key, exact: true });
|
|
3201
3254
|
if (!owner) return;
|
|
3202
3255
|
const result = await gatewayCall("read", { id });
|
|
@@ -3328,6 +3381,92 @@ function watchMessageReplies(client2, key, target) {
|
|
|
3328
3381
|
}
|
|
3329
3382
|
};
|
|
3330
3383
|
}
|
|
3384
|
+
var actions = /* @__PURE__ */ new Set(["view", "edit", "delete", "admin"]);
|
|
3385
|
+
var uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
3386
|
+
function targetFromRead(response) {
|
|
3387
|
+
const raw = response.item ?? response;
|
|
3388
|
+
const id = raw.id ?? raw.item_id;
|
|
3389
|
+
const path = raw.path ?? raw.item_path;
|
|
3390
|
+
if (response.success !== true || typeof id !== "string" || !uuid.test(id)) {
|
|
3391
|
+
throw new Error("PERMISSION_TARGET_UNAVAILABLE");
|
|
3392
|
+
}
|
|
3393
|
+
return { id, ...typeof path === "string" ? { path } : {} };
|
|
3394
|
+
}
|
|
3395
|
+
function usePermissions(item, requested) {
|
|
3396
|
+
React.useSyncExternalStore(subscribeScope, getScopeVersion, getScopeVersion);
|
|
3397
|
+
const epoch = React.useSyncExternalStore(subscribeSession, getSessionVersion, getSessionVersion);
|
|
3398
|
+
const mounts = React.useSyncExternalStore(subscribeMounts, getMountVersion, getMountVersion);
|
|
3399
|
+
const scope = getScope();
|
|
3400
|
+
const principal = getSessionEntry()?.principal_id;
|
|
3401
|
+
const target = item?.trim() ?? "";
|
|
3402
|
+
const wanted = [...new Set(requested ?? [])].sort();
|
|
3403
|
+
const directId = uuid.test(target);
|
|
3404
|
+
const validTarget = directId || (target.startsWith("/root/") || target === "/root");
|
|
3405
|
+
const invalid = wanted.some((action) => !actions.has(action)) || Boolean(target && !validTarget);
|
|
3406
|
+
const enabled2 = Boolean(scope && principal && target && wanted.length && !invalid);
|
|
3407
|
+
const root = ["vfs", scope ?? "__unscoped__", "permissions", principal ?? "__anonymous__", epoch, mounts];
|
|
3408
|
+
const scopeIds = [...new Set([getAnchorRef()?.id, ...getMounts().map((mount3) => mount3.id)].filter((id) => Boolean(id)))];
|
|
3409
|
+
const targetKey = [...root, "target", target];
|
|
3410
|
+
const identity = reactQuery.useQuery({
|
|
3411
|
+
queryKey: targetKey,
|
|
3412
|
+
queryFn: async ({ signal: signal2 }) => {
|
|
3413
|
+
if (!enabled2 || !scope) throw new Error("PERMISSION_CONTEXT_REQUIRED");
|
|
3414
|
+
return targetFromRead(await gatewayCall("read", { path: target, _scope_path: scope }, { signal: signal2 }));
|
|
3415
|
+
},
|
|
3416
|
+
enabled: enabled2 && !directId,
|
|
3417
|
+
staleTime: Infinity,
|
|
3418
|
+
gcTime: 0,
|
|
3419
|
+
retry: false,
|
|
3420
|
+
refetchOnWindowFocus: false,
|
|
3421
|
+
refetchOnReconnect: false,
|
|
3422
|
+
refetchOnMount: false,
|
|
3423
|
+
meta: { permissionQuery: { scope, scopeIds, path: target, targetLookup: true } }
|
|
3424
|
+
});
|
|
3425
|
+
const resolved = directId ? { id: target } : identity.data;
|
|
3426
|
+
const identityReady = directId || identity.isSuccess && !identity.isFetching && !identity.isStale;
|
|
3427
|
+
const checks = reactQuery.useQueries({ queries: wanted.filter((action) => actions.has(action)).map((action) => ({
|
|
3428
|
+
queryKey: [...root, "check", resolved?.id ?? target, action],
|
|
3429
|
+
queryFn: async ({ signal: signal2 }) => {
|
|
3430
|
+
if (!enabled2 || !scope || !resolved) throw new Error("PERMISSION_CONTEXT_REQUIRED");
|
|
3431
|
+
const result = await gatewayCall("check-item-access", { id: resolved.id, action, _scope_path: scope }, { signal: signal2 });
|
|
3432
|
+
if (result.success !== true || typeof result.allowed !== "boolean") throw new Error("PERMISSION_RESPONSE_INVALID");
|
|
3433
|
+
return result.allowed;
|
|
3434
|
+
},
|
|
3435
|
+
enabled: enabled2 && identityReady && Boolean(resolved),
|
|
3436
|
+
staleTime: Infinity,
|
|
3437
|
+
gcTime: 0,
|
|
3438
|
+
retry: false,
|
|
3439
|
+
refetchOnWindowFocus: false,
|
|
3440
|
+
refetchOnReconnect: false,
|
|
3441
|
+
refetchOnMount: false,
|
|
3442
|
+
meta: { permissionQuery: { scope, scopeIds, itemId: resolved?.id, path: resolved?.path ?? (directId ? void 0 : target) } }
|
|
3443
|
+
})) });
|
|
3444
|
+
const error = invalid ? new Error("PERMISSION_INPUT_INVALID") : !directId && identity.error || checks.find((check) => check.error)?.error || null;
|
|
3445
|
+
const verified = enabled2 && identityReady && !error;
|
|
3446
|
+
const supported = wanted.filter((action) => actions.has(action));
|
|
3447
|
+
const data = Object.fromEntries(wanted.map((action) => {
|
|
3448
|
+
const check = checks[supported.indexOf(action)];
|
|
3449
|
+
return [action, Boolean(verified && check?.isSuccess && !check.isFetching && !check.isStale && check.data === true)];
|
|
3450
|
+
}));
|
|
3451
|
+
return {
|
|
3452
|
+
data,
|
|
3453
|
+
loading: Boolean(enabled2 && (!directId && identity.isFetching || checks.some((check) => check.isFetching || check.isPending)) && !error),
|
|
3454
|
+
error,
|
|
3455
|
+
/** Explicit refresh for a user action; no automatic retry or polling. */
|
|
3456
|
+
refetch: async () => {
|
|
3457
|
+
if (!enabled2) return;
|
|
3458
|
+
if (!directId && (!identity.data || identity.isError)) {
|
|
3459
|
+
await identity.refetch();
|
|
3460
|
+
return;
|
|
3461
|
+
}
|
|
3462
|
+
await Promise.all(checks.map((check) => check.refetch()));
|
|
3463
|
+
}
|
|
3464
|
+
};
|
|
3465
|
+
}
|
|
3466
|
+
function usePermission(action, item) {
|
|
3467
|
+
const result = usePermissions(item, action ? [action] : []);
|
|
3468
|
+
return { ...result, data: { allowed: Boolean(action && result.data[action]) } };
|
|
3469
|
+
}
|
|
3331
3470
|
|
|
3332
3471
|
// src/hooks.ts
|
|
3333
3472
|
function useScopeKey() {
|
|
@@ -3536,7 +3675,7 @@ function useIncrementalItems(filter, options = {}) {
|
|
|
3536
3675
|
let wasConnected = false;
|
|
3537
3676
|
let missed = false;
|
|
3538
3677
|
let generation = 0;
|
|
3539
|
-
const
|
|
3678
|
+
const pending5 = /* @__PURE__ */ new Map();
|
|
3540
3679
|
const reconcile = () => {
|
|
3541
3680
|
const started = generation;
|
|
3542
3681
|
void refetch.current().then((result) => {
|
|
@@ -3553,18 +3692,18 @@ function useIncrementalItems(filter, options = {}) {
|
|
|
3553
3692
|
delete upserts[path];
|
|
3554
3693
|
return { identity, upserts, deleted: new Set(state.deleted).add(path) };
|
|
3555
3694
|
});
|
|
3556
|
-
const earlier =
|
|
3695
|
+
const earlier = pending5.get("__reconcile__");
|
|
3557
3696
|
if (earlier) clearTimeout(earlier);
|
|
3558
|
-
|
|
3559
|
-
|
|
3697
|
+
pending5.set("__reconcile__", setTimeout(() => {
|
|
3698
|
+
pending5.delete("__reconcile__");
|
|
3560
3699
|
reconcile();
|
|
3561
3700
|
}, 250));
|
|
3562
3701
|
};
|
|
3563
3702
|
const readOne = (path) => {
|
|
3564
|
-
const earlier =
|
|
3703
|
+
const earlier = pending5.get(path);
|
|
3565
3704
|
if (earlier) clearTimeout(earlier);
|
|
3566
|
-
|
|
3567
|
-
|
|
3705
|
+
pending5.set(path, setTimeout(() => {
|
|
3706
|
+
pending5.delete(path);
|
|
3568
3707
|
void client2.fetchQuery({ queryKey: vfsKeys.item(path), queryFn: () => fetchVfsItem(path), staleTime: 0 }).then((item) => {
|
|
3569
3708
|
if (stopped) return;
|
|
3570
3709
|
if (!item || !itemMatchesIncrementalFilter(item, selected)) {
|
|
@@ -3627,7 +3766,7 @@ function useIncrementalItems(filter, options = {}) {
|
|
|
3627
3766
|
stopped = true;
|
|
3628
3767
|
stopEvents();
|
|
3629
3768
|
stopConnection();
|
|
3630
|
-
|
|
3769
|
+
pending5.forEach(clearTimeout);
|
|
3631
3770
|
};
|
|
3632
3771
|
}, [client2, identity]);
|
|
3633
3772
|
return { ...query, allItems };
|
|
@@ -4383,15 +4522,15 @@ async function readPublishedBundle(componentId, releaseItemId, version) {
|
|
|
4383
4522
|
return { status: "ready", releaseItemId, version, script, stylesheet: stylesheet?.trim() ? stylesheet : null };
|
|
4384
4523
|
}
|
|
4385
4524
|
function publishedBundle(componentId, releaseItemId, version) {
|
|
4386
|
-
let
|
|
4387
|
-
if (!
|
|
4388
|
-
|
|
4389
|
-
publishedBundles.set(releaseItemId,
|
|
4390
|
-
|
|
4391
|
-
if (publishedBundles.get(releaseItemId) ===
|
|
4525
|
+
let pending5 = publishedBundles.get(releaseItemId);
|
|
4526
|
+
if (!pending5) {
|
|
4527
|
+
pending5 = readPublishedBundle(componentId, releaseItemId, version);
|
|
4528
|
+
publishedBundles.set(releaseItemId, pending5);
|
|
4529
|
+
pending5.catch(() => {
|
|
4530
|
+
if (publishedBundles.get(releaseItemId) === pending5) publishedBundles.delete(releaseItemId);
|
|
4392
4531
|
});
|
|
4393
4532
|
}
|
|
4394
|
-
return
|
|
4533
|
+
return pending5;
|
|
4395
4534
|
}
|
|
4396
4535
|
function loadPublishedBundle(source) {
|
|
4397
4536
|
const live = liveRelease(source);
|
|
@@ -4486,6 +4625,143 @@ function usePublishedComponent(item) {
|
|
|
4486
4625
|
version: onScreen?.version ?? null
|
|
4487
4626
|
};
|
|
4488
4627
|
}
|
|
4628
|
+
var COMPILED_BUILD_LIMIT = 512 * 1024;
|
|
4629
|
+
var compiledBundles = /* @__PURE__ */ new Map();
|
|
4630
|
+
var compiledComponents = /* @__PURE__ */ new Map();
|
|
4631
|
+
registerCleanup(() => {
|
|
4632
|
+
compiledBundles.clear();
|
|
4633
|
+
compiledComponents.clear();
|
|
4634
|
+
});
|
|
4635
|
+
var compiledKey = (fileId, sha256) => `${fileId}:${sha256.toLowerCase()}`;
|
|
4636
|
+
async function readCompiledBundle(build) {
|
|
4637
|
+
const opened = await gatewayCall("open", {
|
|
4638
|
+
id: build.fileId,
|
|
4639
|
+
mode: "render",
|
|
4640
|
+
...build.scopePath ? { _scope_path: build.scopePath } : {}
|
|
4641
|
+
});
|
|
4642
|
+
const url = plainRecord(plainRecord(opened.render).props).url;
|
|
4643
|
+
if (opened.item_id !== build.fileId || opened.item_type !== "file" || typeof url !== "string" || !url) {
|
|
4644
|
+
throw new Error("The compiled build could not be opened.");
|
|
4645
|
+
}
|
|
4646
|
+
const response = await fetch(url, { credentials: "omit", referrerPolicy: "no-referrer" });
|
|
4647
|
+
if (!response.ok) {
|
|
4648
|
+
throw new Error(`Failed to read the compiled build: ${response.status} ${response.statusText}`.trim());
|
|
4649
|
+
}
|
|
4650
|
+
const bytes = await response.arrayBuffer();
|
|
4651
|
+
if (bytes.byteLength > COMPILED_BUILD_LIMIT) throw new Error("The compiled build is too large to run.");
|
|
4652
|
+
const digest = Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256", bytes))).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
4653
|
+
if (digest !== build.sha256.toLowerCase()) {
|
|
4654
|
+
throw new Error("The compiled build does not match the bytes it was shown with.");
|
|
4655
|
+
}
|
|
4656
|
+
let parsed;
|
|
4657
|
+
try {
|
|
4658
|
+
parsed = JSON.parse(new TextDecoder().decode(bytes));
|
|
4659
|
+
} catch {
|
|
4660
|
+
throw new Error("The compiled build is not a build file.");
|
|
4661
|
+
}
|
|
4662
|
+
const { js, css, scope } = plainRecord(parsed);
|
|
4663
|
+
if (typeof js !== "string" || !js || css != null && typeof css !== "string" || scope != null && (typeof scope !== "string" || !/^[A-Za-z0-9_-]{1,64}$/.test(scope))) {
|
|
4664
|
+
throw new Error("The compiled build is not a build file.");
|
|
4665
|
+
}
|
|
4666
|
+
return {
|
|
4667
|
+
script: js,
|
|
4668
|
+
stylesheet: typeof css === "string" && css.trim() ? css : null,
|
|
4669
|
+
scopeClass: typeof scope === "string" ? `fsaos-c-${scope}` : null
|
|
4670
|
+
};
|
|
4671
|
+
}
|
|
4672
|
+
function loadCompiledBundle(build) {
|
|
4673
|
+
if (!build.fileId || !/^[0-9a-f]{64}$/i.test(build.sha256 || "")) {
|
|
4674
|
+
return Promise.reject(new Error("A compiled build is named by its file and the SHA-256 of its bytes."));
|
|
4675
|
+
}
|
|
4676
|
+
const key = compiledKey(build.fileId, build.sha256);
|
|
4677
|
+
let pending5 = compiledBundles.get(key);
|
|
4678
|
+
if (!pending5) {
|
|
4679
|
+
pending5 = readCompiledBundle(build);
|
|
4680
|
+
compiledBundles.set(key, pending5);
|
|
4681
|
+
pending5.catch(() => {
|
|
4682
|
+
if (compiledBundles.get(key) === pending5) compiledBundles.delete(key);
|
|
4683
|
+
});
|
|
4684
|
+
}
|
|
4685
|
+
return pending5;
|
|
4686
|
+
}
|
|
4687
|
+
function useCompiledComponent(build) {
|
|
4688
|
+
const [onScreen, setOnScreen] = React.useState(null);
|
|
4689
|
+
const [status, setStatus] = React.useState("loading");
|
|
4690
|
+
const [error, setError] = React.useState(null);
|
|
4691
|
+
const shown = React.useRef(null);
|
|
4692
|
+
const fileId = build?.fileId || null;
|
|
4693
|
+
const sha256 = build?.sha256 || null;
|
|
4694
|
+
const scopePath = build?.scopePath;
|
|
4695
|
+
React.useEffect(() => {
|
|
4696
|
+
if (!fileId || !sha256) {
|
|
4697
|
+
if (shown.current?.cssKey) releaseComponentCss(shown.current.cssKey);
|
|
4698
|
+
shown.current = null;
|
|
4699
|
+
setOnScreen(null);
|
|
4700
|
+
setError(null);
|
|
4701
|
+
setStatus("loading");
|
|
4702
|
+
return;
|
|
4703
|
+
}
|
|
4704
|
+
const key = compiledKey(fileId, sha256);
|
|
4705
|
+
if (shown.current?.key === key) return;
|
|
4706
|
+
let cancelled = false;
|
|
4707
|
+
setError(null);
|
|
4708
|
+
if (!shown.current) setStatus("loading");
|
|
4709
|
+
(async () => {
|
|
4710
|
+
let heldCssKey = null;
|
|
4711
|
+
try {
|
|
4712
|
+
const bundle = await loadCompiledBundle({ fileId, sha256, scopePath });
|
|
4713
|
+
if (cancelled) return;
|
|
4714
|
+
let resolved = compiledComponents.get(key);
|
|
4715
|
+
if (!resolved) {
|
|
4716
|
+
resolved = evaluateBundle(bundle.script);
|
|
4717
|
+
if (!resolved) {
|
|
4718
|
+
throw new Error(
|
|
4719
|
+
"The compiled build did not hand over a component. Expected window.__FSAOS_COMPONENT__ (what the compile emits) or a __FSAOS_REGISTER__(Component) call."
|
|
4720
|
+
);
|
|
4721
|
+
}
|
|
4722
|
+
if (typeof resolved !== "function") {
|
|
4723
|
+
throw new Error(`The compiled build handed over something that is not a React component (${typeof resolved}).`);
|
|
4724
|
+
}
|
|
4725
|
+
compiledComponents.set(key, resolved);
|
|
4726
|
+
}
|
|
4727
|
+
const cssKey = bundle.stylesheet ? `compiled:${key}` : null;
|
|
4728
|
+
if (cssKey) {
|
|
4729
|
+
heldCssKey = cssKey;
|
|
4730
|
+
await holdComponentCss(cssKey, async () => bundle.stylesheet);
|
|
4731
|
+
}
|
|
4732
|
+
if (cancelled) {
|
|
4733
|
+
if (heldCssKey) releaseComponentCss(heldCssKey);
|
|
4734
|
+
return;
|
|
4735
|
+
}
|
|
4736
|
+
const previousCssKey = shown.current?.cssKey ?? null;
|
|
4737
|
+
shown.current = { key, cssKey };
|
|
4738
|
+
heldCssKey = null;
|
|
4739
|
+
setOnScreen({ Component: resolved, key, scopeClass: bundle.scopeClass });
|
|
4740
|
+
setStatus("ready");
|
|
4741
|
+
if (previousCssKey) releaseComponentCss(previousCssKey);
|
|
4742
|
+
} catch (err) {
|
|
4743
|
+
if (heldCssKey) releaseComponentCss(heldCssKey);
|
|
4744
|
+
if (cancelled) return;
|
|
4745
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
4746
|
+
if (!shown.current) setStatus("error");
|
|
4747
|
+
}
|
|
4748
|
+
})();
|
|
4749
|
+
return () => {
|
|
4750
|
+
cancelled = true;
|
|
4751
|
+
};
|
|
4752
|
+
}, [fileId, sha256, scopePath]);
|
|
4753
|
+
React.useEffect(() => () => {
|
|
4754
|
+
if (shown.current?.cssKey) releaseComponentCss(shown.current.cssKey);
|
|
4755
|
+
shown.current = null;
|
|
4756
|
+
}, []);
|
|
4757
|
+
return {
|
|
4758
|
+
Component: onScreen?.Component ?? null,
|
|
4759
|
+
/** The class to put on the element that wraps the component (see `CompiledBundle.scopeClass`). */
|
|
4760
|
+
scopeClass: onScreen?.scopeClass ?? null,
|
|
4761
|
+
status,
|
|
4762
|
+
error
|
|
4763
|
+
};
|
|
4764
|
+
}
|
|
4489
4765
|
var THEME_PROPERTIES = [
|
|
4490
4766
|
"--color-primary",
|
|
4491
4767
|
"--color-secondary",
|
|
@@ -4515,16 +4791,6 @@ function useTheme() {
|
|
|
4515
4791
|
}, []);
|
|
4516
4792
|
return { data: themeData, loading: false, error: null };
|
|
4517
4793
|
}
|
|
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
4794
|
var _principalIdCache = null;
|
|
4529
4795
|
var _principalIdPromise = null;
|
|
4530
4796
|
var _principalListeners = /* @__PURE__ */ new Set();
|
|
@@ -5621,7 +5887,7 @@ function usePersonalItemOrder(key, items, space) {
|
|
|
5621
5887
|
return [...unplaced, ...arranged.filter((item) => savedIds.has(item.id))];
|
|
5622
5888
|
}, [key, items, query.applyTo, query.order]);
|
|
5623
5889
|
const client2 = reactQuery.useQueryClient();
|
|
5624
|
-
const
|
|
5890
|
+
const pending5 = React.useRef(false);
|
|
5625
5891
|
const ready = Boolean(supported && !query.error && query.arrangement?.item_id && query.resolutionLevel === "member" && query.arrangement.write_target_id === query.arrangement.item_id);
|
|
5626
5892
|
const mutation = reactQuery.useMutation({
|
|
5627
5893
|
mutationFn: async (change) => {
|
|
@@ -5639,7 +5905,7 @@ function usePersonalItemOrder(key, items, space) {
|
|
|
5639
5905
|
if (!ready || !scopePath || identity !== activeIdentity.current || generation !== getScopeVersion() || getScope() !== mountedScope) {
|
|
5640
5906
|
throw new Error("Personal order is not available in this Space");
|
|
5641
5907
|
}
|
|
5642
|
-
if (
|
|
5908
|
+
if (pending5.current) throw new Error("An order change is already being saved");
|
|
5643
5909
|
const visibleIds = items.map((item) => item.id);
|
|
5644
5910
|
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
5911
|
const cached = client2.getQueryData(query.arrangementQueryKey);
|
|
@@ -5652,7 +5918,7 @@ function usePersonalItemOrder(key, items, space) {
|
|
|
5652
5918
|
let index = 0;
|
|
5653
5919
|
const saved = (query.order ?? []).map((id) => visible.has(id) ? ids[index++] : id);
|
|
5654
5920
|
const order = [...saved, ...ids.slice(index)];
|
|
5655
|
-
|
|
5921
|
+
pending5.current = true;
|
|
5656
5922
|
try {
|
|
5657
5923
|
return await mutation.mutateAsync({
|
|
5658
5924
|
ids: order,
|
|
@@ -5661,7 +5927,7 @@ function usePersonalItemOrder(key, items, space) {
|
|
|
5661
5927
|
queryKey: query.arrangementQueryKey
|
|
5662
5928
|
});
|
|
5663
5929
|
} finally {
|
|
5664
|
-
|
|
5930
|
+
pending5.current = false;
|
|
5665
5931
|
}
|
|
5666
5932
|
}
|
|
5667
5933
|
return {
|
|
@@ -7409,7 +7675,7 @@ function usePersonalSections(contextId, collection) {
|
|
|
7409
7675
|
meta: { arrangementRealtime: true, personalSections: true },
|
|
7410
7676
|
structuralSharing: (previous, next) => newestSnapshot(previous, next)
|
|
7411
7677
|
});
|
|
7412
|
-
const
|
|
7678
|
+
const pending5 = React.useRef(false);
|
|
7413
7679
|
const mutation = reactQuery.useMutation({ mutationFn: async (write) => {
|
|
7414
7680
|
const data = await call(write.scope, write.context, write.collection, {
|
|
7415
7681
|
...write.change,
|
|
@@ -7422,12 +7688,12 @@ function usePersonalSections(contextId, collection) {
|
|
|
7422
7688
|
if (!scopePath || !contextId || generation !== getScopeVersion() || getScope() !== scopePath || !query.data || query.error) {
|
|
7423
7689
|
throw new Error("Select the Space again before changing sections");
|
|
7424
7690
|
}
|
|
7425
|
-
if (
|
|
7426
|
-
|
|
7691
|
+
if (pending5.current) throw new Error("A section change is still being saved");
|
|
7692
|
+
pending5.current = true;
|
|
7427
7693
|
try {
|
|
7428
7694
|
return await mutation.mutateAsync({ change: value, scope: scopePath, context: contextId, collection, version: query.data.version });
|
|
7429
7695
|
} finally {
|
|
7430
|
-
|
|
7696
|
+
pending5.current = false;
|
|
7431
7697
|
}
|
|
7432
7698
|
}
|
|
7433
7699
|
function destination(sectionId) {
|
|
@@ -7549,6 +7815,7 @@ exports.isScopeReady = isScopeReady;
|
|
|
7549
7815
|
exports.itemsFilterFromQueryFilter = itemsFilterFromQueryFilter;
|
|
7550
7816
|
exports.listChildren = listChildren;
|
|
7551
7817
|
exports.listInvitations = listInvitations;
|
|
7818
|
+
exports.loadCompiledBundle = loadCompiledBundle;
|
|
7552
7819
|
exports.loadMounts = loadMounts;
|
|
7553
7820
|
exports.loadPublishedBundle = loadPublishedBundle;
|
|
7554
7821
|
exports.mount = mount2;
|
|
@@ -7611,6 +7878,7 @@ exports.useAuth = useAuth;
|
|
|
7611
7878
|
exports.useChannelMessages = useChannelMessages;
|
|
7612
7879
|
exports.useChannels = useChannels;
|
|
7613
7880
|
exports.useChildren = useChildren;
|
|
7881
|
+
exports.useCompiledComponent = useCompiledComponent;
|
|
7614
7882
|
exports.useComponent = useComponent;
|
|
7615
7883
|
exports.useCreate = useCreate;
|
|
7616
7884
|
exports.useCreateAgent = useCreateAgent;
|