@ai4b-team/fsaos-gateway-sdk 5.6.2 → 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/README.md +64 -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 +234 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +75 -15
- package/dist/index.d.ts +75 -15
- package/dist/index.js +233 -59
- package/dist/index.js.map +1 -1
- package/dist/ui.d.cts +1 -1
- package/dist/ui.d.ts +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, { createElement, useMemo, useState, useRef, useEffect,
|
|
2
|
-
import { QueryClient, QueryClientProvider, useQuery, useInfiniteQuery, useQueryClient, useMutation as useMutation$1 } from '@tanstack/react-query';
|
|
1
|
+
import React, { createElement, useSyncExternalStore, useMemo, useState, useRef, useEffect, useCallback, useLayoutEffect } from 'react';
|
|
2
|
+
import { QueryClient, QueryClientProvider, useQuery, useQueries, useInfiniteQuery, useQueryClient, useMutation as useMutation$1 } from '@tanstack/react-query';
|
|
3
3
|
export { QueryClientProvider } from '@tanstack/react-query';
|
|
4
4
|
import { createClient } from '@supabase/supabase-js';
|
|
5
5
|
import * as ReactDOM from 'react-dom';
|
|
@@ -67,6 +67,8 @@ __export(src_exports, {
|
|
|
67
67
|
fetchVfsItem: () => fetchVfsItem,
|
|
68
68
|
fetchVfsItemById: () => fetchVfsItemById,
|
|
69
69
|
fetchVfsTree: () => fetchVfsTree,
|
|
70
|
+
filePurchaseNextUrl: () => filePurchaseNextUrl,
|
|
71
|
+
funnelCheckoutLink: () => funnelCheckoutLink,
|
|
70
72
|
gatewayCall: () => gatewayCall,
|
|
71
73
|
getAccessToken: () => getAccessToken,
|
|
72
74
|
getAnchor: () => getAnchor,
|
|
@@ -74,6 +76,7 @@ __export(src_exports, {
|
|
|
74
76
|
getAnchorVersion: () => getAnchorVersion,
|
|
75
77
|
getAssetUrl: () => getAssetUrl,
|
|
76
78
|
getDefaultSort: () => getDefaultSort,
|
|
79
|
+
getFilePurchase: () => getFilePurchase,
|
|
77
80
|
getHomeAnchor: () => getHomeAnchor,
|
|
78
81
|
getInvitation: () => getInvitation,
|
|
79
82
|
getMountVersion: () => getMountVersion,
|
|
@@ -141,6 +144,7 @@ __export(src_exports, {
|
|
|
141
144
|
setScope: () => setScope,
|
|
142
145
|
setupRequireShim: () => setupRequireShim,
|
|
143
146
|
signal: () => signal,
|
|
147
|
+
startFileCheckout: () => startFileCheckout,
|
|
144
148
|
startTracking: () => startTracking,
|
|
145
149
|
steerTurn: () => steerTurn,
|
|
146
150
|
submitForm: () => submitForm,
|
|
@@ -707,7 +711,7 @@ function resetGatewayReads() {
|
|
|
707
711
|
}
|
|
708
712
|
function isScheduledRead(method, params) {
|
|
709
713
|
if (method === "query") return !("materialize" in params);
|
|
710
|
-
return ["read", "list", "search", "resolve", "resolve-items", "get-channel-messages", "list-memberships", "message-replies"].includes(method);
|
|
714
|
+
return ["read", "list", "search", "resolve", "resolve-items", "get-channel-messages", "list-memberships", "message-replies", "check-item-access"].includes(method);
|
|
711
715
|
}
|
|
712
716
|
function readRequestKey(value) {
|
|
713
717
|
if (Array.isArray(value)) return `[${value.map(readRequestKey).join(",")}]`;
|
|
@@ -730,18 +734,18 @@ function scheduleRead(key, method, options, run) {
|
|
|
730
734
|
};
|
|
731
735
|
jobs.set(key, job);
|
|
732
736
|
waiting.push(job);
|
|
733
|
-
const
|
|
737
|
+
const pending5 = job;
|
|
734
738
|
job.timer = setTimeout(() => {
|
|
735
|
-
|
|
739
|
+
pending5.controller.abort();
|
|
736
740
|
const error = new Error("The read timed out. Please retry.");
|
|
737
741
|
error.name = "TimeoutError";
|
|
738
|
-
for (const consumer of
|
|
742
|
+
for (const consumer of pending5.consumers) {
|
|
739
743
|
consumer.detach();
|
|
740
744
|
consumer.reject(error);
|
|
741
745
|
}
|
|
742
|
-
|
|
743
|
-
if (jobs.get(
|
|
744
|
-
discardQueued(
|
|
746
|
+
pending5.consumers.clear();
|
|
747
|
+
if (jobs.get(pending5.key) === pending5) jobs.delete(pending5.key);
|
|
748
|
+
discardQueued(pending5);
|
|
745
749
|
}, config.timeoutMs);
|
|
746
750
|
} else if (rank[options.priority ?? "normal"] < rank[job.priority]) {
|
|
747
751
|
job.priority = options.priority ?? "normal";
|
|
@@ -964,8 +968,8 @@ function refreshQuery(client2, queryKey, options = {}) {
|
|
|
964
968
|
queued = /* @__PURE__ */ new Map();
|
|
965
969
|
trailing.set(client2, queued);
|
|
966
970
|
}
|
|
967
|
-
const
|
|
968
|
-
if (
|
|
971
|
+
const pending5 = queued.get(hash);
|
|
972
|
+
if (pending5) return pending5;
|
|
969
973
|
const queue = queued;
|
|
970
974
|
const next = Promise.allSettled(running2).then(() => {
|
|
971
975
|
queue.delete(hash);
|
|
@@ -1024,6 +1028,52 @@ function clearArrangementRefreshes(client2) {
|
|
|
1024
1028
|
pending2.get(client2)?.forEach(clearTimeout);
|
|
1025
1029
|
pending2.delete(client2);
|
|
1026
1030
|
}
|
|
1031
|
+
|
|
1032
|
+
// src/permission-cache.ts
|
|
1033
|
+
var pending3 = /* @__PURE__ */ new WeakMap();
|
|
1034
|
+
var accessEdges = /* @__PURE__ */ new Set(["shared_with", "has_member", "member_of", "owned_by"]);
|
|
1035
|
+
function invalidate(client2, query) {
|
|
1036
|
+
let timers = pending3.get(client2);
|
|
1037
|
+
if (!timers) {
|
|
1038
|
+
timers = /* @__PURE__ */ new Map();
|
|
1039
|
+
pending3.set(client2, timers);
|
|
1040
|
+
}
|
|
1041
|
+
if (timers.has(query)) return;
|
|
1042
|
+
void client2.cancelQueries({ queryKey: query.queryKey, exact: true });
|
|
1043
|
+
void client2.invalidateQueries({ queryKey: query.queryKey, exact: true, refetchType: "none" });
|
|
1044
|
+
if (!query.isActive()) return;
|
|
1045
|
+
timers.set(query, setTimeout(() => {
|
|
1046
|
+
timers.delete(query);
|
|
1047
|
+
if (client2.getQueryCache().get(query.queryHash) !== query || !query.isActive()) return;
|
|
1048
|
+
void refreshQuery(client2, query.queryKey, { exact: true });
|
|
1049
|
+
}, 250));
|
|
1050
|
+
}
|
|
1051
|
+
function handlePermissionChange(client2, event, type) {
|
|
1052
|
+
const edge = type === "ccm_change";
|
|
1053
|
+
if (edge && !accessEdges.has(event.edge_type)) return;
|
|
1054
|
+
const paths = [event.path, event.old_path, event.source_path].filter((path) => typeof path === "string");
|
|
1055
|
+
const ids = [event.item_id, event.source_item_id, event.source_id, event.target_item_id, event.target_id].filter(Boolean);
|
|
1056
|
+
if (!paths.length && !ids.length) return;
|
|
1057
|
+
for (const query of client2.getQueryCache().findAll({ queryKey: ["vfs"] })) {
|
|
1058
|
+
const meta = query.meta?.permissionQuery;
|
|
1059
|
+
if (!meta?.scope) continue;
|
|
1060
|
+
const direct = Boolean(meta.itemId && ids.includes(meta.itemId));
|
|
1061
|
+
const ancestor = Boolean(meta.path && paths.some((path) => isChannelPath(meta.path, path)));
|
|
1062
|
+
const scope = meta.scope;
|
|
1063
|
+
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));
|
|
1064
|
+
const inherited = scoped && (event.item_type === "member" || event.item_type === "principal" || edge);
|
|
1065
|
+
if (direct || ancestor || !meta.targetLookup && inherited) invalidate(client2, query);
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
function refreshPermissionsAfterReconnect(client2) {
|
|
1069
|
+
for (const query of client2.getQueryCache().findAll({ queryKey: ["vfs"] })) {
|
|
1070
|
+
if (query.meta?.permissionQuery) invalidate(client2, query);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
function clearPermissionRefreshes(client2) {
|
|
1074
|
+
pending3.get(client2)?.forEach((timer) => clearTimeout(timer));
|
|
1075
|
+
pending3.delete(client2);
|
|
1076
|
+
}
|
|
1027
1077
|
var client = null;
|
|
1028
1078
|
registerCleanup(() => {
|
|
1029
1079
|
if (!client) return;
|
|
@@ -1064,7 +1114,7 @@ var queryClient = new Proxy({}, {
|
|
|
1064
1114
|
});
|
|
1065
1115
|
|
|
1066
1116
|
// src/item-query-realtime.ts
|
|
1067
|
-
var
|
|
1117
|
+
var pending4 = /* @__PURE__ */ new WeakMap();
|
|
1068
1118
|
function listingFilter(query) {
|
|
1069
1119
|
return query.meta?.infiniteItemsRealtime?.filter;
|
|
1070
1120
|
}
|
|
@@ -1103,10 +1153,10 @@ function affectsListing(query, filter, event) {
|
|
|
1103
1153
|
return hasPath || Boolean(filter.parent_id && event.parent_id === filter.parent_id);
|
|
1104
1154
|
}
|
|
1105
1155
|
function schedule(client2, query) {
|
|
1106
|
-
let timers =
|
|
1156
|
+
let timers = pending4.get(client2);
|
|
1107
1157
|
if (!timers) {
|
|
1108
1158
|
timers = /* @__PURE__ */ new Map();
|
|
1109
|
-
|
|
1159
|
+
pending4.set(client2, timers);
|
|
1110
1160
|
}
|
|
1111
1161
|
const previous = timers.get(query.queryHash);
|
|
1112
1162
|
if (previous) clearTimeout(previous);
|
|
@@ -1129,8 +1179,8 @@ function refreshInfiniteItemsAfterReconnect(client2) {
|
|
|
1129
1179
|
}
|
|
1130
1180
|
}
|
|
1131
1181
|
function clearInfiniteItemsRefreshes(client2) {
|
|
1132
|
-
|
|
1133
|
-
|
|
1182
|
+
pending4.get(client2)?.forEach(clearTimeout);
|
|
1183
|
+
pending4.delete(client2);
|
|
1134
1184
|
}
|
|
1135
1185
|
|
|
1136
1186
|
// src/items-selection.ts
|
|
@@ -1480,6 +1530,7 @@ function catchUpAfterGap(reason) {
|
|
|
1480
1530
|
const qc = getQueryClient();
|
|
1481
1531
|
refreshInfiniteItemsAfterReconnect(qc);
|
|
1482
1532
|
reconnectArrangements(qc);
|
|
1533
|
+
refreshPermissionsAfterReconnect(qc);
|
|
1483
1534
|
for (const sub of activePaths.values()) {
|
|
1484
1535
|
void qc.invalidateQueries({ queryKey: vfsKeys.item(sub.path) });
|
|
1485
1536
|
void qc.invalidateQueries({ queryKey: vfsKeys.children(sub.path) });
|
|
@@ -1517,6 +1568,9 @@ function handleMessage(raw) {
|
|
|
1517
1568
|
if (msg.type === "event" || msg.event_type) {
|
|
1518
1569
|
const eventType = msg.event_type || "message";
|
|
1519
1570
|
const data = msg.data || msg;
|
|
1571
|
+
if (eventType === "vfs_change" || eventType === "ccm_change") {
|
|
1572
|
+
handlePermissionChange(getQueryClient(), data, eventType);
|
|
1573
|
+
}
|
|
1520
1574
|
if (eventType === "vfs_change") {
|
|
1521
1575
|
handleInfiniteItemsChange(getQueryClient(), data);
|
|
1522
1576
|
handleArrangementChange(getQueryClient(), data);
|
|
@@ -1646,6 +1700,7 @@ function disconnectSSE() {
|
|
|
1646
1700
|
log("disconnectSSE: tearing down");
|
|
1647
1701
|
clearInfiniteItemsRefreshes(getQueryClient());
|
|
1648
1702
|
clearArrangementRefreshes(getQueryClient());
|
|
1703
|
+
clearPermissionRefreshes(getQueryClient());
|
|
1649
1704
|
intentionalClose = true;
|
|
1650
1705
|
stopPing();
|
|
1651
1706
|
if (ws) {
|
|
@@ -3016,13 +3071,13 @@ function watchChannelTranscript(client2, key, channel, limit) {
|
|
|
3016
3071
|
let timer;
|
|
3017
3072
|
let running2 = false;
|
|
3018
3073
|
let stopped = false;
|
|
3019
|
-
const
|
|
3074
|
+
const pending5 = /* @__PURE__ */ new Map();
|
|
3020
3075
|
const current = () => client2.getQueryData(key);
|
|
3021
3076
|
const query = () => client2.getQueryCache().find({ queryKey: key, exact: true });
|
|
3022
3077
|
const reload = () => refreshQuery(client2, key, { exact: true });
|
|
3023
3078
|
const read = (after_seq, before_seq) => fetchChannelMessagesPage(channel, { transcriptOnly: true, limit, after_seq, before_seq });
|
|
3024
3079
|
const schedule2 = () => {
|
|
3025
|
-
if (stopped || running2 || timer || !
|
|
3080
|
+
if (stopped || running2 || timer || !pending5.size) return;
|
|
3026
3081
|
timer = setTimeout(() => {
|
|
3027
3082
|
timer = void 0;
|
|
3028
3083
|
void flush();
|
|
@@ -3030,8 +3085,8 @@ function watchChannelTranscript(client2, key, channel, limit) {
|
|
|
3030
3085
|
};
|
|
3031
3086
|
const flush = async () => {
|
|
3032
3087
|
running2 = true;
|
|
3033
|
-
const changes = [...
|
|
3034
|
-
|
|
3088
|
+
const changes = [...pending5.values()];
|
|
3089
|
+
pending5.clear();
|
|
3035
3090
|
const owner = query();
|
|
3036
3091
|
try {
|
|
3037
3092
|
if (owner?.state.fetchStatus === "fetching") await owner.promise?.catch(() => void 0);
|
|
@@ -3105,15 +3160,15 @@ function watchChannelTranscript(client2, key, channel, limit) {
|
|
|
3105
3160
|
};
|
|
3106
3161
|
const stop = subscribeToEvents("vfs_change", (change) => {
|
|
3107
3162
|
const id = change.item_id ?? change.path;
|
|
3108
|
-
const previous =
|
|
3109
|
-
|
|
3163
|
+
const previous = pending5.get(id);
|
|
3164
|
+
pending5.set(id, previous && (previous.inserted || isNewPost(previous, channel)) && actionOf(change) === "update" && previous.path === change.path ? { ...change, inserted: true } : change);
|
|
3110
3165
|
schedule2();
|
|
3111
3166
|
}, (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)));
|
|
3112
3167
|
watch = { users: 0, stop: () => {
|
|
3113
3168
|
stopped = true;
|
|
3114
3169
|
stop();
|
|
3115
3170
|
if (timer) clearTimeout(timer);
|
|
3116
|
-
|
|
3171
|
+
pending5.clear();
|
|
3117
3172
|
} };
|
|
3118
3173
|
entries.set(hash, watch);
|
|
3119
3174
|
}
|
|
@@ -3159,7 +3214,7 @@ function watchChannels(client2, key, normalize) {
|
|
|
3159
3214
|
running2 = true;
|
|
3160
3215
|
const reload = inventory;
|
|
3161
3216
|
inventory = false;
|
|
3162
|
-
const
|
|
3217
|
+
const pending5 = [...channels];
|
|
3163
3218
|
const checkRename = new Set(renames);
|
|
3164
3219
|
renames.clear();
|
|
3165
3220
|
channels.clear();
|
|
@@ -3167,7 +3222,7 @@ function watchChannels(client2, key, normalize) {
|
|
|
3167
3222
|
if (reload) {
|
|
3168
3223
|
await refreshQuery(client2, key, { exact: true });
|
|
3169
3224
|
} else {
|
|
3170
|
-
const results = await Promise.allSettled(
|
|
3225
|
+
const results = await Promise.allSettled(pending5.map(async (id) => {
|
|
3171
3226
|
const owner = client2.getQueryCache().find({ queryKey: key, exact: true });
|
|
3172
3227
|
if (!owner) return;
|
|
3173
3228
|
const result = await gatewayCall("read", { id });
|
|
@@ -3299,6 +3354,92 @@ function watchMessageReplies(client2, key, target) {
|
|
|
3299
3354
|
}
|
|
3300
3355
|
};
|
|
3301
3356
|
}
|
|
3357
|
+
var actions = /* @__PURE__ */ new Set(["view", "edit", "delete", "admin"]);
|
|
3358
|
+
var uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
3359
|
+
function targetFromRead(response) {
|
|
3360
|
+
const raw = response.item ?? response;
|
|
3361
|
+
const id = raw.id ?? raw.item_id;
|
|
3362
|
+
const path = raw.path ?? raw.item_path;
|
|
3363
|
+
if (response.success !== true || typeof id !== "string" || !uuid.test(id)) {
|
|
3364
|
+
throw new Error("PERMISSION_TARGET_UNAVAILABLE");
|
|
3365
|
+
}
|
|
3366
|
+
return { id, ...typeof path === "string" ? { path } : {} };
|
|
3367
|
+
}
|
|
3368
|
+
function usePermissions(item, requested) {
|
|
3369
|
+
useSyncExternalStore(subscribeScope, getScopeVersion, getScopeVersion);
|
|
3370
|
+
const epoch = useSyncExternalStore(subscribeSession, getSessionVersion, getSessionVersion);
|
|
3371
|
+
const mounts = useSyncExternalStore(subscribeMounts, getMountVersion, getMountVersion);
|
|
3372
|
+
const scope = getScope();
|
|
3373
|
+
const principal = getSessionEntry()?.principal_id;
|
|
3374
|
+
const target = item?.trim() ?? "";
|
|
3375
|
+
const wanted = [...new Set(requested ?? [])].sort();
|
|
3376
|
+
const directId = uuid.test(target);
|
|
3377
|
+
const validTarget = directId || (target.startsWith("/root/") || target === "/root");
|
|
3378
|
+
const invalid = wanted.some((action) => !actions.has(action)) || Boolean(target && !validTarget);
|
|
3379
|
+
const enabled2 = Boolean(scope && principal && target && wanted.length && !invalid);
|
|
3380
|
+
const root = ["vfs", scope ?? "__unscoped__", "permissions", principal ?? "__anonymous__", epoch, mounts];
|
|
3381
|
+
const scopeIds = [...new Set([getAnchorRef()?.id, ...getMounts().map((mount3) => mount3.id)].filter((id) => Boolean(id)))];
|
|
3382
|
+
const targetKey = [...root, "target", target];
|
|
3383
|
+
const identity = useQuery({
|
|
3384
|
+
queryKey: targetKey,
|
|
3385
|
+
queryFn: async ({ signal: signal2 }) => {
|
|
3386
|
+
if (!enabled2 || !scope) throw new Error("PERMISSION_CONTEXT_REQUIRED");
|
|
3387
|
+
return targetFromRead(await gatewayCall("read", { path: target, _scope_path: scope }, { signal: signal2 }));
|
|
3388
|
+
},
|
|
3389
|
+
enabled: enabled2 && !directId,
|
|
3390
|
+
staleTime: Infinity,
|
|
3391
|
+
gcTime: 0,
|
|
3392
|
+
retry: false,
|
|
3393
|
+
refetchOnWindowFocus: false,
|
|
3394
|
+
refetchOnReconnect: false,
|
|
3395
|
+
refetchOnMount: false,
|
|
3396
|
+
meta: { permissionQuery: { scope, scopeIds, path: target, targetLookup: true } }
|
|
3397
|
+
});
|
|
3398
|
+
const resolved = directId ? { id: target } : identity.data;
|
|
3399
|
+
const identityReady = directId || identity.isSuccess && !identity.isFetching && !identity.isStale;
|
|
3400
|
+
const checks = useQueries({ queries: wanted.filter((action) => actions.has(action)).map((action) => ({
|
|
3401
|
+
queryKey: [...root, "check", resolved?.id ?? target, action],
|
|
3402
|
+
queryFn: async ({ signal: signal2 }) => {
|
|
3403
|
+
if (!enabled2 || !scope || !resolved) throw new Error("PERMISSION_CONTEXT_REQUIRED");
|
|
3404
|
+
const result = await gatewayCall("check-item-access", { id: resolved.id, action, _scope_path: scope }, { signal: signal2 });
|
|
3405
|
+
if (result.success !== true || typeof result.allowed !== "boolean") throw new Error("PERMISSION_RESPONSE_INVALID");
|
|
3406
|
+
return result.allowed;
|
|
3407
|
+
},
|
|
3408
|
+
enabled: enabled2 && identityReady && Boolean(resolved),
|
|
3409
|
+
staleTime: Infinity,
|
|
3410
|
+
gcTime: 0,
|
|
3411
|
+
retry: false,
|
|
3412
|
+
refetchOnWindowFocus: false,
|
|
3413
|
+
refetchOnReconnect: false,
|
|
3414
|
+
refetchOnMount: false,
|
|
3415
|
+
meta: { permissionQuery: { scope, scopeIds, itemId: resolved?.id, path: resolved?.path ?? (directId ? void 0 : target) } }
|
|
3416
|
+
})) });
|
|
3417
|
+
const error = invalid ? new Error("PERMISSION_INPUT_INVALID") : !directId && identity.error || checks.find((check) => check.error)?.error || null;
|
|
3418
|
+
const verified = enabled2 && identityReady && !error;
|
|
3419
|
+
const supported = wanted.filter((action) => actions.has(action));
|
|
3420
|
+
const data = Object.fromEntries(wanted.map((action) => {
|
|
3421
|
+
const check = checks[supported.indexOf(action)];
|
|
3422
|
+
return [action, Boolean(verified && check?.isSuccess && !check.isFetching && !check.isStale && check.data === true)];
|
|
3423
|
+
}));
|
|
3424
|
+
return {
|
|
3425
|
+
data,
|
|
3426
|
+
loading: Boolean(enabled2 && (!directId && identity.isFetching || checks.some((check) => check.isFetching || check.isPending)) && !error),
|
|
3427
|
+
error,
|
|
3428
|
+
/** Explicit refresh for a user action; no automatic retry or polling. */
|
|
3429
|
+
refetch: async () => {
|
|
3430
|
+
if (!enabled2) return;
|
|
3431
|
+
if (!directId && (!identity.data || identity.isError)) {
|
|
3432
|
+
await identity.refetch();
|
|
3433
|
+
return;
|
|
3434
|
+
}
|
|
3435
|
+
await Promise.all(checks.map((check) => check.refetch()));
|
|
3436
|
+
}
|
|
3437
|
+
};
|
|
3438
|
+
}
|
|
3439
|
+
function usePermission(action, item) {
|
|
3440
|
+
const result = usePermissions(item, action ? [action] : []);
|
|
3441
|
+
return { ...result, data: { allowed: Boolean(action && result.data[action]) } };
|
|
3442
|
+
}
|
|
3302
3443
|
|
|
3303
3444
|
// src/hooks.ts
|
|
3304
3445
|
function useScopeKey() {
|
|
@@ -3507,7 +3648,7 @@ function useIncrementalItems(filter, options = {}) {
|
|
|
3507
3648
|
let wasConnected = false;
|
|
3508
3649
|
let missed = false;
|
|
3509
3650
|
let generation = 0;
|
|
3510
|
-
const
|
|
3651
|
+
const pending5 = /* @__PURE__ */ new Map();
|
|
3511
3652
|
const reconcile = () => {
|
|
3512
3653
|
const started = generation;
|
|
3513
3654
|
void refetch.current().then((result) => {
|
|
@@ -3524,18 +3665,18 @@ function useIncrementalItems(filter, options = {}) {
|
|
|
3524
3665
|
delete upserts[path];
|
|
3525
3666
|
return { identity, upserts, deleted: new Set(state.deleted).add(path) };
|
|
3526
3667
|
});
|
|
3527
|
-
const earlier =
|
|
3668
|
+
const earlier = pending5.get("__reconcile__");
|
|
3528
3669
|
if (earlier) clearTimeout(earlier);
|
|
3529
|
-
|
|
3530
|
-
|
|
3670
|
+
pending5.set("__reconcile__", setTimeout(() => {
|
|
3671
|
+
pending5.delete("__reconcile__");
|
|
3531
3672
|
reconcile();
|
|
3532
3673
|
}, 250));
|
|
3533
3674
|
};
|
|
3534
3675
|
const readOne = (path) => {
|
|
3535
|
-
const earlier =
|
|
3676
|
+
const earlier = pending5.get(path);
|
|
3536
3677
|
if (earlier) clearTimeout(earlier);
|
|
3537
|
-
|
|
3538
|
-
|
|
3678
|
+
pending5.set(path, setTimeout(() => {
|
|
3679
|
+
pending5.delete(path);
|
|
3539
3680
|
void client2.fetchQuery({ queryKey: vfsKeys.item(path), queryFn: () => fetchVfsItem(path), staleTime: 0 }).then((item) => {
|
|
3540
3681
|
if (stopped) return;
|
|
3541
3682
|
if (!item || !itemMatchesIncrementalFilter(item, selected)) {
|
|
@@ -3598,7 +3739,7 @@ function useIncrementalItems(filter, options = {}) {
|
|
|
3598
3739
|
stopped = true;
|
|
3599
3740
|
stopEvents();
|
|
3600
3741
|
stopConnection();
|
|
3601
|
-
|
|
3742
|
+
pending5.forEach(clearTimeout);
|
|
3602
3743
|
};
|
|
3603
3744
|
}, [client2, identity]);
|
|
3604
3745
|
return { ...query, allItems };
|
|
@@ -4354,15 +4495,15 @@ async function readPublishedBundle(componentId, releaseItemId, version) {
|
|
|
4354
4495
|
return { status: "ready", releaseItemId, version, script, stylesheet: stylesheet?.trim() ? stylesheet : null };
|
|
4355
4496
|
}
|
|
4356
4497
|
function publishedBundle(componentId, releaseItemId, version) {
|
|
4357
|
-
let
|
|
4358
|
-
if (!
|
|
4359
|
-
|
|
4360
|
-
publishedBundles.set(releaseItemId,
|
|
4361
|
-
|
|
4362
|
-
if (publishedBundles.get(releaseItemId) ===
|
|
4498
|
+
let pending5 = publishedBundles.get(releaseItemId);
|
|
4499
|
+
if (!pending5) {
|
|
4500
|
+
pending5 = readPublishedBundle(componentId, releaseItemId, version);
|
|
4501
|
+
publishedBundles.set(releaseItemId, pending5);
|
|
4502
|
+
pending5.catch(() => {
|
|
4503
|
+
if (publishedBundles.get(releaseItemId) === pending5) publishedBundles.delete(releaseItemId);
|
|
4363
4504
|
});
|
|
4364
4505
|
}
|
|
4365
|
-
return
|
|
4506
|
+
return pending5;
|
|
4366
4507
|
}
|
|
4367
4508
|
function loadPublishedBundle(source) {
|
|
4368
4509
|
const live = liveRelease(source);
|
|
@@ -4486,16 +4627,6 @@ function useTheme() {
|
|
|
4486
4627
|
}, []);
|
|
4487
4628
|
return { data: themeData, loading: false, error: null };
|
|
4488
4629
|
}
|
|
4489
|
-
function usePermission(_action, _path) {
|
|
4490
|
-
return { data: { allowed: true }, loading: false, error: null };
|
|
4491
|
-
}
|
|
4492
|
-
function usePermissions(_path, actions) {
|
|
4493
|
-
const perms = {};
|
|
4494
|
-
(actions || []).forEach((a) => {
|
|
4495
|
-
perms[a] = true;
|
|
4496
|
-
});
|
|
4497
|
-
return { data: perms, loading: false, error: null };
|
|
4498
|
-
}
|
|
4499
4630
|
var _principalIdCache = null;
|
|
4500
4631
|
var _principalIdPromise = null;
|
|
4501
4632
|
var _principalListeners = /* @__PURE__ */ new Set();
|
|
@@ -5592,7 +5723,7 @@ function usePersonalItemOrder(key, items, space) {
|
|
|
5592
5723
|
return [...unplaced, ...arranged.filter((item) => savedIds.has(item.id))];
|
|
5593
5724
|
}, [key, items, query.applyTo, query.order]);
|
|
5594
5725
|
const client2 = useQueryClient();
|
|
5595
|
-
const
|
|
5726
|
+
const pending5 = useRef(false);
|
|
5596
5727
|
const ready = Boolean(supported && !query.error && query.arrangement?.item_id && query.resolutionLevel === "member" && query.arrangement.write_target_id === query.arrangement.item_id);
|
|
5597
5728
|
const mutation = useMutation$1({
|
|
5598
5729
|
mutationFn: async (change) => {
|
|
@@ -5610,7 +5741,7 @@ function usePersonalItemOrder(key, items, space) {
|
|
|
5610
5741
|
if (!ready || !scopePath || identity !== activeIdentity.current || generation !== getScopeVersion() || getScope() !== mountedScope) {
|
|
5611
5742
|
throw new Error("Personal order is not available in this Space");
|
|
5612
5743
|
}
|
|
5613
|
-
if (
|
|
5744
|
+
if (pending5.current) throw new Error("An order change is already being saved");
|
|
5614
5745
|
const visibleIds = items.map((item) => item.id);
|
|
5615
5746
|
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");
|
|
5616
5747
|
const cached = client2.getQueryData(query.arrangementQueryKey);
|
|
@@ -5623,7 +5754,7 @@ function usePersonalItemOrder(key, items, space) {
|
|
|
5623
5754
|
let index = 0;
|
|
5624
5755
|
const saved = (query.order ?? []).map((id) => visible.has(id) ? ids[index++] : id);
|
|
5625
5756
|
const order = [...saved, ...ids.slice(index)];
|
|
5626
|
-
|
|
5757
|
+
pending5.current = true;
|
|
5627
5758
|
try {
|
|
5628
5759
|
return await mutation.mutateAsync({
|
|
5629
5760
|
ids: order,
|
|
@@ -5632,7 +5763,7 @@ function usePersonalItemOrder(key, items, space) {
|
|
|
5632
5763
|
queryKey: query.arrangementQueryKey
|
|
5633
5764
|
});
|
|
5634
5765
|
} finally {
|
|
5635
|
-
|
|
5766
|
+
pending5.current = false;
|
|
5636
5767
|
}
|
|
5637
5768
|
}
|
|
5638
5769
|
return {
|
|
@@ -6283,6 +6414,49 @@ async function submitForm(capabilityId, fields, options = {}) {
|
|
|
6283
6414
|
}, fillId, pageUrl, identity, options.signal);
|
|
6284
6415
|
return payload;
|
|
6285
6416
|
}
|
|
6417
|
+
|
|
6418
|
+
// src/commerce.ts
|
|
6419
|
+
async function startFileCheckout(options) {
|
|
6420
|
+
return gatewayCall("commerce-file-sale", {
|
|
6421
|
+
action: "checkout",
|
|
6422
|
+
product_id: options.productId,
|
|
6423
|
+
expected_product_revision_id: options.productRevisionId,
|
|
6424
|
+
destination_id: options.destinationId,
|
|
6425
|
+
request_key: options.requestKey,
|
|
6426
|
+
_scope_path: options.scopePath,
|
|
6427
|
+
...options.journey ? { journey: options.journey } : {}
|
|
6428
|
+
});
|
|
6429
|
+
}
|
|
6430
|
+
async function getFilePurchase(licenseId, scopePath) {
|
|
6431
|
+
return gatewayCall("commerce-file-sale", { action: "get", license_id: licenseId, _scope_path: scopePath });
|
|
6432
|
+
}
|
|
6433
|
+
function funnelCheckoutLink(options) {
|
|
6434
|
+
const host = new URL(options.hostOrigin);
|
|
6435
|
+
if (host.protocol !== "https:" && !(host.protocol === "http:" && host.hostname === "127.0.0.1") || host.username || host.password || host.search || host.hash || host.pathname !== "/") {
|
|
6436
|
+
throw new TypeError("hostOrigin must be an HTTPS origin or the local 127.0.0.1 app");
|
|
6437
|
+
}
|
|
6438
|
+
const page = new URL(options.pageUrl ?? window.location.href);
|
|
6439
|
+
if (page.protocol !== "https:" || page.username || page.password || page.hash || page.port) {
|
|
6440
|
+
throw new TypeError("The funnel must be a published HTTPS page");
|
|
6441
|
+
}
|
|
6442
|
+
const link = new URL("/v2/revven", host);
|
|
6443
|
+
link.search = new URLSearchParams({
|
|
6444
|
+
surface: "library",
|
|
6445
|
+
offer: options.productId,
|
|
6446
|
+
sale_page: page.href,
|
|
6447
|
+
sale_action: options.capabilityId
|
|
6448
|
+
}).toString();
|
|
6449
|
+
return link.href;
|
|
6450
|
+
}
|
|
6451
|
+
function filePurchaseNextUrl(receipt) {
|
|
6452
|
+
if (receipt.success !== true || receipt.state !== "ready" || !receipt.item_id || !receipt.file_id || !receipt.journey?.next_url) return null;
|
|
6453
|
+
const next = new URL(receipt.journey.next_url);
|
|
6454
|
+
const source = new URL(receipt.journey.return_url);
|
|
6455
|
+
if (next.protocol !== "https:" || source.protocol !== "https:" || next.origin !== source.origin || next.username || next.password || next.hash || next.searchParams.getAll("funnel_id").length !== 1 || next.searchParams.get("funnel_id") !== receipt.journey.funnel_id) {
|
|
6456
|
+
throw new Error("The purchase destination could not be verified");
|
|
6457
|
+
}
|
|
6458
|
+
return next.href;
|
|
6459
|
+
}
|
|
6286
6460
|
function readItem(path) {
|
|
6287
6461
|
return gatewayCall("read", { path });
|
|
6288
6462
|
}
|
|
@@ -7337,7 +7511,7 @@ function usePersonalSections(contextId, collection) {
|
|
|
7337
7511
|
meta: { arrangementRealtime: true, personalSections: true },
|
|
7338
7512
|
structuralSharing: (previous, next) => newestSnapshot(previous, next)
|
|
7339
7513
|
});
|
|
7340
|
-
const
|
|
7514
|
+
const pending5 = useRef(false);
|
|
7341
7515
|
const mutation = useMutation$1({ mutationFn: async (write) => {
|
|
7342
7516
|
const data = await call(write.scope, write.context, write.collection, {
|
|
7343
7517
|
...write.change,
|
|
@@ -7350,12 +7524,12 @@ function usePersonalSections(contextId, collection) {
|
|
|
7350
7524
|
if (!scopePath || !contextId || generation !== getScopeVersion() || getScope() !== scopePath || !query.data || query.error) {
|
|
7351
7525
|
throw new Error("Select the Space again before changing sections");
|
|
7352
7526
|
}
|
|
7353
|
-
if (
|
|
7354
|
-
|
|
7527
|
+
if (pending5.current) throw new Error("A section change is still being saved");
|
|
7528
|
+
pending5.current = true;
|
|
7355
7529
|
try {
|
|
7356
7530
|
return await mutation.mutateAsync({ change: value, scope: scopePath, context: contextId, collection, version: query.data.version });
|
|
7357
7531
|
} finally {
|
|
7358
|
-
|
|
7532
|
+
pending5.current = false;
|
|
7359
7533
|
}
|
|
7360
7534
|
}
|
|
7361
7535
|
function destination(sectionId) {
|
|
@@ -7378,6 +7552,6 @@ function usePersonalSections(contextId, collection) {
|
|
|
7378
7552
|
// src/index.ts
|
|
7379
7553
|
__registerSdkExports(src_exports);
|
|
7380
7554
|
|
|
7381
|
-
export { CHANNEL_AI_MODES, ComponentRenderer, EnforcementDeniedError, FormSubmissionError, GatewayRequestError, HostSessionUnavailableError, InteractionTrackingError, KernelProvider, acceptInvitation, acceptInvite, answerInput, assignPersonalSection, auth, awaitAnchorReady, awaitScopeReady, callTool, cancelInvitation, cancelQueuedTurn, cancelTurn, clearCachedToken, clearSession, configureGatewayReads, connectHostSession, createAgent, createInvitation, createItem, disconnectSSE, disposeVfsRealtimeWs, electHomeAnchor, emitEvent, fetchChannelMessages, fetchChannelMessagesPage, fetchChannelMessagesWithCards, fetchEdgesForItem, fetchItemHistory, fetchItemVersions, fetchItems, fetchMemberFocus, fetchMessageReplies, fetchMessageReplyContexts, fetchOpenEnvelope, fetchRecentActivity, fetchResolvedItems, fetchTimelineHistory, fetchTurnQueueEntries, fetchTypeDefinitions, fetchVfsChildren, fetchVfsChildrenPage, fetchVfsItem, fetchVfsItemById, fetchVfsTree, gatewayCall, getAccessToken, getAnchor, getAnchorRef, getAnchorVersion, getAssetUrl, getDefaultSort, getHomeAnchor, getInvitation, getMountVersion, getMounts, getPathSubscriptionState, getQueryClient, getRequiredFormFields, getScope, getScopeVersion, getServerClockOffsetMs, getServerClockSyncedAt, getSessionEntry, hasServerClock, initSession, initVfsRealtimeWs, initializeFsaos, initializeWorkspace, interpretSchema, invalidateAllVfs, invalidateChannelMessages, invalidateChildren, invalidateItem, invalidateOpenEnvelope, invalidatePathAndParent, invalidateSubtree, invalidateTypes, inviteMember, isAnchorReady, isChannelPath, isListableItemsFilter, isScopeReady, itemsFilterFromQueryFilter, listChildren, listInvitations, loadMounts, loadPublishedBundle, mount2 as mount, mountRealtimeScope, normalizeItem, onConnectionStateChange, pathSubscriptionMatches, personalSectionsKey, ping, pushChanges, queryClient, readItem, refreshQuery, registerCleanup, rejectInvitation, replaceMounts, resendInvitation, resetAllSdkState, resolvePrincipalId, resubscribePath, seatMember, selectMount, sendMessage2 as sendMessage, serveHostSession, serverDeadlinePassed, serverMsUntil, serverNow, setAnchor, setCachedToken, setQueryClient, setScope, setupRequireShim, signal, startTracking, steerTurn, submitForm, subscribeAnchor, subscribeArtifactStream, subscribeMounts, subscribeScope, subscribeToEvents, subscribeToPath, subscribeToScope, trackAction, trackEvent, trackPageView, unmountRealtimeScope, updateItem, uploadFile, useAcceptInvite, useAccounts, useAgentTimeline, useAllChannels, useAnswerInput, useArrangement, useArtifactStream, useAsset, useAuth, useChannelMessages, useChannels, useChildren, useComponent, useCreate, useCreateAgent, useDelete, useDmChannels, useEdges, useEventStream, useFileUpload, useIncrementalItems, useInfiniteChannelMessages, useInfiniteChildren, useInfiniteItems, useInviteMember, useItem, useItemById, useItemHistory, useItemVersions, useItems, useLink, useList, useMemberFocus, useMessageReplies, useMintedAsset, useMounts, useMove, useMutation, useNotifications, useOpen, usePermission, usePermissions, usePersonalItemOrder, usePersonalSections, usePinnedItems, usePrincipal, usePublishedComponent, useRealtimeQuery, useRecentActivity, useResolve, useResolvedItems, useScope, useScopeReady, useSearch, useSeatMember, useTheme, useTimelineHistory, useTree, useType, useTypeHelpers, useTypes, useUnreadCounts, useUpdate, useUpdatePrincipal, vfsKeys, waitForPathReady };
|
|
7555
|
+
export { CHANNEL_AI_MODES, ComponentRenderer, EnforcementDeniedError, FormSubmissionError, GatewayRequestError, HostSessionUnavailableError, InteractionTrackingError, KernelProvider, acceptInvitation, acceptInvite, answerInput, assignPersonalSection, auth, awaitAnchorReady, awaitScopeReady, callTool, cancelInvitation, cancelQueuedTurn, cancelTurn, clearCachedToken, clearSession, configureGatewayReads, connectHostSession, createAgent, createInvitation, createItem, disconnectSSE, disposeVfsRealtimeWs, electHomeAnchor, emitEvent, fetchChannelMessages, fetchChannelMessagesPage, fetchChannelMessagesWithCards, fetchEdgesForItem, fetchItemHistory, fetchItemVersions, fetchItems, fetchMemberFocus, fetchMessageReplies, fetchMessageReplyContexts, fetchOpenEnvelope, fetchRecentActivity, fetchResolvedItems, fetchTimelineHistory, fetchTurnQueueEntries, fetchTypeDefinitions, fetchVfsChildren, fetchVfsChildrenPage, fetchVfsItem, fetchVfsItemById, fetchVfsTree, filePurchaseNextUrl, funnelCheckoutLink, gatewayCall, getAccessToken, getAnchor, getAnchorRef, getAnchorVersion, getAssetUrl, getDefaultSort, getFilePurchase, getHomeAnchor, getInvitation, getMountVersion, getMounts, getPathSubscriptionState, getQueryClient, getRequiredFormFields, getScope, getScopeVersion, getServerClockOffsetMs, getServerClockSyncedAt, getSessionEntry, hasServerClock, initSession, initVfsRealtimeWs, initializeFsaos, initializeWorkspace, interpretSchema, invalidateAllVfs, invalidateChannelMessages, invalidateChildren, invalidateItem, invalidateOpenEnvelope, invalidatePathAndParent, invalidateSubtree, invalidateTypes, inviteMember, isAnchorReady, isChannelPath, isListableItemsFilter, isScopeReady, itemsFilterFromQueryFilter, listChildren, listInvitations, loadMounts, loadPublishedBundle, mount2 as mount, mountRealtimeScope, normalizeItem, onConnectionStateChange, pathSubscriptionMatches, personalSectionsKey, ping, pushChanges, queryClient, readItem, refreshQuery, registerCleanup, rejectInvitation, replaceMounts, resendInvitation, resetAllSdkState, resolvePrincipalId, resubscribePath, seatMember, selectMount, sendMessage2 as sendMessage, serveHostSession, serverDeadlinePassed, serverMsUntil, serverNow, setAnchor, setCachedToken, setQueryClient, setScope, setupRequireShim, signal, startFileCheckout, startTracking, steerTurn, submitForm, subscribeAnchor, subscribeArtifactStream, subscribeMounts, subscribeScope, subscribeToEvents, subscribeToPath, subscribeToScope, trackAction, trackEvent, trackPageView, unmountRealtimeScope, updateItem, uploadFile, useAcceptInvite, useAccounts, useAgentTimeline, useAllChannels, useAnswerInput, useArrangement, useArtifactStream, useAsset, useAuth, useChannelMessages, useChannels, useChildren, useComponent, useCreate, useCreateAgent, useDelete, useDmChannels, useEdges, useEventStream, useFileUpload, useIncrementalItems, useInfiniteChannelMessages, useInfiniteChildren, useInfiniteItems, useInviteMember, useItem, useItemById, useItemHistory, useItemVersions, useItems, useLink, useList, useMemberFocus, useMessageReplies, useMintedAsset, useMounts, useMove, useMutation, useNotifications, useOpen, usePermission, usePermissions, usePersonalItemOrder, usePersonalSections, usePinnedItems, usePrincipal, usePublishedComponent, useRealtimeQuery, useRecentActivity, useResolve, useResolvedItems, useScope, useScopeReady, useSearch, useSeatMember, useTheme, useTimelineHistory, useTree, useType, useTypeHelpers, useTypes, useUnreadCounts, useUpdate, useUpdatePrincipal, vfsKeys, waitForPathReady };
|
|
7382
7556
|
//# sourceMappingURL=index.js.map
|
|
7383
7557
|
//# sourceMappingURL=index.js.map
|