@ai4b-team/fsaos-gateway-sdk 5.1.0 → 5.2.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 +22 -2
- package/dist/iife/gateway.js +4 -4
- package/dist/iife/gateway.js.map +3 -3
- package/dist/iife/ui.js +1 -1
- package/dist/index.cjs +53 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +53 -39
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -851,6 +851,13 @@ declare global {
|
|
|
851
851
|
tracking?: {
|
|
852
852
|
enabled?: boolean;
|
|
853
853
|
};
|
|
854
|
+
/** The page's own host holds the session. Set by a host that serves the
|
|
855
|
+
* page and forwards its kernel calls to the gateway itself, attaching
|
|
856
|
+
* the caller's identity there (a RevDev desk preview). `gatewayUrl` is
|
|
857
|
+
* that host's forwarding address. The SDK then sends no bearer, does
|
|
858
|
+
* not wait for a sign-in, and opens no realtime connection: the page
|
|
859
|
+
* holds no credential and the host has no event stream to offer. */
|
|
860
|
+
hostSession?: boolean;
|
|
854
861
|
};
|
|
855
862
|
}
|
|
856
863
|
}
|
|
@@ -1373,9 +1380,13 @@ declare function invalidateOpenEnvelope(path?: string, strategy?: string): void;
|
|
|
1373
1380
|
* 4. disposeVfsRealtimeWs() — unsubscribe all and clear timers
|
|
1374
1381
|
*
|
|
1375
1382
|
* Invalidation strategy:
|
|
1376
|
-
* - INSERT/UPDATE:
|
|
1383
|
+
* - INSERT/UPDATE: re-read the item + invalidate parent's children list
|
|
1377
1384
|
* - DELETE: remove item queries + invalidate parent's children list
|
|
1378
1385
|
* - Tree queries: invalidate any tree whose root is an ancestor of the changed path
|
|
1386
|
+
*
|
|
1387
|
+
* A change event names the item that changed; it does not carry the item. So
|
|
1388
|
+
* the item's cached copy is marked for a fresh read (read at once when a view
|
|
1389
|
+
* is showing it, on its next use otherwise), never rebuilt from the event.
|
|
1379
1390
|
*/
|
|
1380
1391
|
/**
|
|
1381
1392
|
* Subscribe to VFS realtime events for the primary account via the gateway WebSocket.
|
package/dist/index.d.ts
CHANGED
|
@@ -851,6 +851,13 @@ declare global {
|
|
|
851
851
|
tracking?: {
|
|
852
852
|
enabled?: boolean;
|
|
853
853
|
};
|
|
854
|
+
/** The page's own host holds the session. Set by a host that serves the
|
|
855
|
+
* page and forwards its kernel calls to the gateway itself, attaching
|
|
856
|
+
* the caller's identity there (a RevDev desk preview). `gatewayUrl` is
|
|
857
|
+
* that host's forwarding address. The SDK then sends no bearer, does
|
|
858
|
+
* not wait for a sign-in, and opens no realtime connection: the page
|
|
859
|
+
* holds no credential and the host has no event stream to offer. */
|
|
860
|
+
hostSession?: boolean;
|
|
854
861
|
};
|
|
855
862
|
}
|
|
856
863
|
}
|
|
@@ -1373,9 +1380,13 @@ declare function invalidateOpenEnvelope(path?: string, strategy?: string): void;
|
|
|
1373
1380
|
* 4. disposeVfsRealtimeWs() — unsubscribe all and clear timers
|
|
1374
1381
|
*
|
|
1375
1382
|
* Invalidation strategy:
|
|
1376
|
-
* - INSERT/UPDATE:
|
|
1383
|
+
* - INSERT/UPDATE: re-read the item + invalidate parent's children list
|
|
1377
1384
|
* - DELETE: remove item queries + invalidate parent's children list
|
|
1378
1385
|
* - Tree queries: invalidate any tree whose root is an ancestor of the changed path
|
|
1386
|
+
*
|
|
1387
|
+
* A change event names the item that changed; it does not carry the item. So
|
|
1388
|
+
* the item's cached copy is marked for a fresh read (read at once when a view
|
|
1389
|
+
* is showing it, on its next use otherwise), never rebuilt from the event.
|
|
1379
1390
|
*/
|
|
1380
1391
|
/**
|
|
1381
1392
|
* Subscribe to VFS realtime events for the primary account via the gateway WebSocket.
|
package/dist/index.js
CHANGED
|
@@ -251,6 +251,7 @@ var EnforcementDeniedError = class _EnforcementDeniedError extends Error {
|
|
|
251
251
|
};
|
|
252
252
|
var CONFIG = typeof window !== "undefined" && window.__FSAOS_CONFIG__ || {};
|
|
253
253
|
var PUBLIC_SOURCES = Array.isArray(CONFIG.sources) ? CONFIG.sources : [];
|
|
254
|
+
var HOST_SESSION = CONFIG.hostSession === true;
|
|
254
255
|
var SUPABASE_URL = CONFIG.supabaseUrl || "https://vahbmsslxuustnlvsrkg.supabase.co";
|
|
255
256
|
var SUPABASE_ANON_KEY = CONFIG.supabaseAnonKey || "sb_publishable_ZjosozAjfpZ4InMNElTr6Q_hHB-f5nc";
|
|
256
257
|
var GATEWAY_URL = CONFIG.gatewayUrl || "https://fsaos-mcp-gw-rust.fly.dev";
|
|
@@ -296,6 +297,7 @@ function clearCachedToken() {
|
|
|
296
297
|
}
|
|
297
298
|
async function getAccessToken() {
|
|
298
299
|
const cfg = typeof window !== "undefined" && window.__FSAOS_CONFIG__ || {};
|
|
300
|
+
if (cfg.hostSession === true) return null;
|
|
299
301
|
if (cfg.embedToken) {
|
|
300
302
|
if (typeof cfg.embedToken === "function") {
|
|
301
303
|
try {
|
|
@@ -1215,6 +1217,10 @@ function hasActiveSubscriptions() {
|
|
|
1215
1217
|
return activeScopes.size > 0 || activePaths.size > 0;
|
|
1216
1218
|
}
|
|
1217
1219
|
async function ensureConnection() {
|
|
1220
|
+
if (HOST_SESSION) {
|
|
1221
|
+
log("ensureConnection: the host holds the session, no realtime connection");
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1218
1224
|
if (!hasActiveSubscriptions()) {
|
|
1219
1225
|
log("ensureConnection: no active subscriptions, skipping");
|
|
1220
1226
|
return;
|
|
@@ -1545,6 +1551,7 @@ function getPathSubscriptionState(path) {
|
|
|
1545
1551
|
}
|
|
1546
1552
|
function waitForPathReady(path, timeoutMs = 5e3) {
|
|
1547
1553
|
if (!activePaths.has(path)) return Promise.resolve(false);
|
|
1554
|
+
if (HOST_SESSION) return Promise.resolve(false);
|
|
1548
1555
|
if (pathStates.get(path) === "ready" && ws && ws.readyState === WebSocket.OPEN) {
|
|
1549
1556
|
return Promise.resolve(true);
|
|
1550
1557
|
}
|
|
@@ -2275,6 +2282,7 @@ var unsubEvents = null;
|
|
|
2275
2282
|
var unsubCcmEvents = null;
|
|
2276
2283
|
var debounceTimers = /* @__PURE__ */ new Map();
|
|
2277
2284
|
var DEBOUNCE_MS = 250;
|
|
2285
|
+
var pendingChanges = /* @__PURE__ */ new Map();
|
|
2278
2286
|
function initVfsRealtimeWs(accountId) {
|
|
2279
2287
|
if (unsubEvents) {
|
|
2280
2288
|
mountRealtimeScope(accountId);
|
|
@@ -2317,6 +2325,7 @@ function disposeVfsRealtimeWs() {
|
|
|
2317
2325
|
}
|
|
2318
2326
|
debounceTimers.forEach((timer) => clearTimeout(timer));
|
|
2319
2327
|
debounceTimers.clear();
|
|
2328
|
+
pendingChanges.clear();
|
|
2320
2329
|
}
|
|
2321
2330
|
registerCleanup(disposeVfsRealtimeWs);
|
|
2322
2331
|
function handleVfsChange(data) {
|
|
@@ -2326,11 +2335,19 @@ function handleVfsChange(data) {
|
|
|
2326
2335
|
const segments = path.split("/");
|
|
2327
2336
|
segments.pop();
|
|
2328
2337
|
const parentPath = segments.join("/") || "/root";
|
|
2338
|
+
let changes = pendingChanges.get(parentPath);
|
|
2339
|
+
if (!changes) {
|
|
2340
|
+
changes = /* @__PURE__ */ new Map();
|
|
2341
|
+
pendingChanges.set(parentPath, changes);
|
|
2342
|
+
}
|
|
2343
|
+
changes.set(path, { action, itemId: typeof data.item_id === "string" ? data.item_id : void 0 });
|
|
2329
2344
|
const existing = debounceTimers.get(parentPath);
|
|
2330
2345
|
if (existing) clearTimeout(existing);
|
|
2331
2346
|
const timer = setTimeout(() => {
|
|
2332
2347
|
debounceTimers.delete(parentPath);
|
|
2333
|
-
|
|
2348
|
+
const flushed = pendingChanges.get(parentPath);
|
|
2349
|
+
pendingChanges.delete(parentPath);
|
|
2350
|
+
if (flushed) applyInvalidation(parentPath, flushed);
|
|
2334
2351
|
}, DEBOUNCE_MS);
|
|
2335
2352
|
debounceTimers.set(parentPath, timer);
|
|
2336
2353
|
}
|
|
@@ -2354,41 +2371,30 @@ function handleCcmChange(data) {
|
|
|
2354
2371
|
}, DEBOUNCE_MS);
|
|
2355
2372
|
debounceTimers.set(debounceKey, timer);
|
|
2356
2373
|
}
|
|
2357
|
-
function applyInvalidation(
|
|
2358
|
-
const
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
item_type: data.item_type,
|
|
2370
|
-
parent_id: data.parent_id,
|
|
2371
|
-
scope_item_id: data.scope_item_id
|
|
2372
|
-
};
|
|
2373
|
-
const normalized = normalizeItem(record);
|
|
2374
|
-
if (normalized && normalized.id) {
|
|
2375
|
-
getQueryClient().setQueryData(vfsKeys.item(path), normalized);
|
|
2376
|
-
}
|
|
2377
|
-
} catch (_e) {
|
|
2374
|
+
function applyInvalidation(parentPath, changes) {
|
|
2375
|
+
const client2 = getQueryClient();
|
|
2376
|
+
for (const [path, change] of changes) {
|
|
2377
|
+
if ((change.action || "").toUpperCase() === "DELETE") {
|
|
2378
|
+
client2.removeQueries({ queryKey: vfsKeys.item(path) });
|
|
2379
|
+
client2.removeQueries({ queryKey: vfsKeys.children(path) });
|
|
2380
|
+
client2.removeQueries({ queryKey: vfsKeys.tree(path) });
|
|
2381
|
+
} else {
|
|
2382
|
+
void refreshQuery(client2, vfsKeys.item(path), { exact: true });
|
|
2383
|
+
}
|
|
2384
|
+
if (change.itemId) {
|
|
2385
|
+
client2.invalidateQueries({ queryKey: vfsKeys.itemById(change.itemId) });
|
|
2378
2386
|
}
|
|
2379
2387
|
}
|
|
2380
|
-
|
|
2381
|
-
|
|
2388
|
+
client2.invalidateQueries({ queryKey: vfsKeys.children(parentPath) });
|
|
2389
|
+
const changed = [...changes.keys()];
|
|
2390
|
+
client2.invalidateQueries({
|
|
2382
2391
|
predicate: (query) => {
|
|
2383
2392
|
const key = query.queryKey;
|
|
2384
2393
|
if (key[0] !== "vfs" || key[1] !== "tree") return false;
|
|
2385
2394
|
const treePath = key[2];
|
|
2386
|
-
return path.startsWith(treePath + "/") || path === treePath;
|
|
2395
|
+
return changed.some((path) => path.startsWith(treePath + "/") || path === treePath);
|
|
2387
2396
|
}
|
|
2388
2397
|
});
|
|
2389
|
-
if (data.item_id) {
|
|
2390
|
-
getQueryClient().invalidateQueries({ queryKey: vfsKeys.itemById(data.item_id) });
|
|
2391
|
-
}
|
|
2392
2398
|
}
|
|
2393
2399
|
|
|
2394
2400
|
// src/mounts.ts
|
|
@@ -3861,8 +3867,16 @@ function useComponent(path, options) {
|
|
|
3861
3867
|
}, []);
|
|
3862
3868
|
return { Component, loading, error };
|
|
3863
3869
|
}
|
|
3864
|
-
var IN_APP_SCRIPT =
|
|
3865
|
-
var IN_APP_STYLESHEET =
|
|
3870
|
+
var IN_APP_SCRIPT = /^embed\/bundle-[A-Za-z0-9_-]+\.js$/;
|
|
3871
|
+
var IN_APP_STYLESHEET = /^embed\/bundle-[A-Za-z0-9_-]+\.css$/;
|
|
3872
|
+
function inAppFile(artifacts, pattern, what) {
|
|
3873
|
+
const paths = Object.keys(artifacts).filter((path2) => pattern.test(path2));
|
|
3874
|
+
if (paths.length > 1) throw new Error(`The published release has more than one in-app ${what}.`);
|
|
3875
|
+
const path = paths[0];
|
|
3876
|
+
if (!path) return null;
|
|
3877
|
+
const sha256 = plainRecord(artifacts[path]).sha256;
|
|
3878
|
+
return typeof sha256 === "string" && sha256 ? { path, sha256 } : null;
|
|
3879
|
+
}
|
|
3866
3880
|
var publishedBundles = /* @__PURE__ */ new Map();
|
|
3867
3881
|
var publishedComponents = /* @__PURE__ */ new Map();
|
|
3868
3882
|
registerCleanup(() => {
|
|
@@ -3901,10 +3915,10 @@ async function readPublishedBundle(componentId, releaseItemId, version) {
|
|
|
3901
3915
|
throw new Error("This component's live version does not match its release record.");
|
|
3902
3916
|
}
|
|
3903
3917
|
const artifacts = plainRecord(record.artifacts);
|
|
3904
|
-
const
|
|
3905
|
-
if (
|
|
3906
|
-
const
|
|
3907
|
-
const wanted =
|
|
3918
|
+
const sealedScript = inAppFile(artifacts, IN_APP_SCRIPT, "script");
|
|
3919
|
+
if (!sealedScript) return { status: "no_in_app_version", releaseItemId, version };
|
|
3920
|
+
const sealedStylesheet = inAppFile(artifacts, IN_APP_STYLESHEET, "stylesheet");
|
|
3921
|
+
const wanted = sealedStylesheet ? [sealedScript.path, sealedStylesheet.path] : [sealedScript.path];
|
|
3908
3922
|
const buildItemId = record.build_item_id;
|
|
3909
3923
|
if (typeof buildItemId !== "string" || !buildItemId) throw new Error("The published release names no build.");
|
|
3910
3924
|
const { items } = await fetchItems(
|
|
@@ -3912,14 +3926,14 @@ async function readPublishedBundle(componentId, releaseItemId, version) {
|
|
|
3912
3926
|
{ throwOnError: true }
|
|
3913
3927
|
);
|
|
3914
3928
|
const fileAt = (path) => items.find((item) => plainRecord(item.type_data).package_path === path);
|
|
3915
|
-
const scriptFile = fileAt(
|
|
3916
|
-
const stylesheetFile =
|
|
3917
|
-
if (!scriptFile ||
|
|
3929
|
+
const scriptFile = fileAt(sealedScript.path);
|
|
3930
|
+
const stylesheetFile = sealedStylesheet ? fileAt(sealedStylesheet.path) : void 0;
|
|
3931
|
+
if (!scriptFile || sealedStylesheet && !stylesheetFile) {
|
|
3918
3932
|
throw new Error("The published release's in-app files could not be found in its build.");
|
|
3919
3933
|
}
|
|
3920
3934
|
const [script, stylesheet] = await Promise.all([
|
|
3921
|
-
readSealedFile(scriptFile,
|
|
3922
|
-
stylesheetFile ? readSealedFile(stylesheetFile,
|
|
3935
|
+
readSealedFile(scriptFile, sealedScript.sha256, "script"),
|
|
3936
|
+
stylesheetFile && sealedStylesheet ? readSealedFile(stylesheetFile, sealedStylesheet.sha256, "stylesheet") : Promise.resolve(null)
|
|
3923
3937
|
]);
|
|
3924
3938
|
return { status: "ready", releaseItemId, version, script, stylesheet: stylesheet?.trim() ? stylesheet : null };
|
|
3925
3939
|
}
|