@ai4b-team/fsaos-gateway-sdk 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/iife/ui.js CHANGED
@@ -1,3 +1,3 @@
1
- /* @fsaos/ui v2.0.0 — FSAOS UI Primitives — 2026-11-11T18:24:37.520Z */
1
+ /* @fsaos/ui v2.0.0 — FSAOS UI Primitives — 2026-11-12T12:16:10.312Z */
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
@@ -125,6 +125,7 @@ __export(src_exports, {
125
125
  itemsFilterFromQueryFilter: () => itemsFilterFromQueryFilter,
126
126
  listChildren: () => listChildren,
127
127
  loadMounts: () => loadMounts,
128
+ loadPublishedBundle: () => loadPublishedBundle,
128
129
  mount: () => mount2,
129
130
  mountRealtimeScope: () => mountRealtimeScope,
130
131
  normalizeItem: () => normalizeItem,
@@ -213,6 +214,7 @@ __export(src_exports, {
213
214
  usePersonalSections: () => usePersonalSections,
214
215
  usePinnedItems: () => usePinnedItems,
215
216
  usePrincipal: () => usePrincipal,
217
+ usePublishedComponent: () => usePublishedComponent,
216
218
  useRealtimeQuery: () => useRealtimeQuery,
217
219
  useRecentActivity: () => useRecentActivity,
218
220
  useResolve: () => useResolve,
@@ -3742,10 +3744,10 @@ async function fetchComponentCss(cssUrl) {
3742
3744
  return null;
3743
3745
  }
3744
3746
  }
3745
- async function holdComponentCss(cssUrl) {
3747
+ async function holdComponentCss(cssUrl, text = () => fetchComponentCss(cssUrl)) {
3746
3748
  let entry = componentCss[cssUrl];
3747
3749
  if (!entry) {
3748
- entry = componentCss[cssUrl] = { users: 0, text: fetchComponentCss(cssUrl), style: null };
3750
+ entry = componentCss[cssUrl] = { users: 0, text: text(), style: null };
3749
3751
  }
3750
3752
  entry.users += 1;
3751
3753
  const cssText = await entry.text;
@@ -3884,6 +3886,172 @@ function useComponent(path, options) {
3884
3886
  }, []);
3885
3887
  return { Component, loading, error };
3886
3888
  }
3889
+ var IN_APP_SCRIPT = "embed/bundle.js";
3890
+ var IN_APP_STYLESHEET = "embed/bundle.css";
3891
+ var publishedBundles = /* @__PURE__ */ new Map();
3892
+ var publishedComponents = /* @__PURE__ */ new Map();
3893
+ registerCleanup(() => {
3894
+ publishedBundles.clear();
3895
+ publishedComponents.clear();
3896
+ });
3897
+ function plainRecord(value) {
3898
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
3899
+ }
3900
+ function liveRelease(source) {
3901
+ const published = plainRecord(plainRecord(source.type_data).published);
3902
+ const releaseItemId = published.published_release_item_id;
3903
+ const version = published.published_version;
3904
+ if (typeof releaseItemId !== "string" || !releaseItemId) return null;
3905
+ if (typeof version !== "number" || !Number.isSafeInteger(version) || version < 1) return null;
3906
+ return { releaseItemId, version };
3907
+ }
3908
+ async function readSealedFile(file, sha256, what) {
3909
+ const envelope = await fetchOpenEnvelope(file.path, { mode: "render" });
3910
+ const url = plainRecord(plainRecord(envelope.render).props).url;
3911
+ if (typeof url !== "string" || !url) throw new Error(`The published ${what} could not be opened.`);
3912
+ const response = await fetch(url);
3913
+ if (!response.ok) {
3914
+ throw new Error(`Failed to read the published ${what}: ${response.status} ${response.statusText}`.trim());
3915
+ }
3916
+ const bytes = await response.arrayBuffer();
3917
+ const digest = Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256", bytes))).map((byte) => byte.toString(16).padStart(2, "0")).join("");
3918
+ if (digest !== sha256) throw new Error(`The published ${what} does not match the bytes its release sealed.`);
3919
+ return new TextDecoder().decode(bytes);
3920
+ }
3921
+ async function readPublishedBundle(componentId, releaseItemId, version) {
3922
+ const release = await fetchVfsItemById(releaseItemId);
3923
+ if (!release) throw new Error("The published release could not be read.");
3924
+ const record = plainRecord(release.type_data);
3925
+ if (release.item_type !== "revdev_release" || record.component_item_id !== componentId || record.status !== "committed" || Number(record.version) !== version) {
3926
+ throw new Error("This component's live version does not match its release record.");
3927
+ }
3928
+ const artifacts = plainRecord(record.artifacts);
3929
+ const scriptSha = plainRecord(artifacts[IN_APP_SCRIPT]).sha256;
3930
+ if (typeof scriptSha !== "string" || !scriptSha) return { status: "no_in_app_version", releaseItemId, version };
3931
+ const stylesheetSha = plainRecord(artifacts[IN_APP_STYLESHEET]).sha256;
3932
+ const wanted = typeof stylesheetSha === "string" && stylesheetSha ? [IN_APP_SCRIPT, IN_APP_STYLESHEET] : [IN_APP_SCRIPT];
3933
+ const buildItemId = record.build_item_id;
3934
+ if (typeof buildItemId !== "string" || !buildItemId) throw new Error("The published release names no build.");
3935
+ const { items } = await fetchItems(
3936
+ { type: "file", parent_id: buildItemId, field_in: { package_path: wanted }, limit: wanted.length },
3937
+ { throwOnError: true }
3938
+ );
3939
+ const fileAt = (path) => items.find((item) => plainRecord(item.type_data).package_path === path);
3940
+ const scriptFile = fileAt(IN_APP_SCRIPT);
3941
+ const stylesheetFile = wanted.length > 1 ? fileAt(IN_APP_STYLESHEET) : void 0;
3942
+ if (!scriptFile || wanted.length > 1 && !stylesheetFile) {
3943
+ throw new Error("The published release's in-app files could not be found in its build.");
3944
+ }
3945
+ const [script, stylesheet] = await Promise.all([
3946
+ readSealedFile(scriptFile, scriptSha, "script"),
3947
+ stylesheetFile ? readSealedFile(stylesheetFile, stylesheetSha, "stylesheet") : Promise.resolve(null)
3948
+ ]);
3949
+ return { status: "ready", releaseItemId, version, script, stylesheet: stylesheet?.trim() ? stylesheet : null };
3950
+ }
3951
+ function publishedBundle(componentId, releaseItemId, version) {
3952
+ let pending3 = publishedBundles.get(releaseItemId);
3953
+ if (!pending3) {
3954
+ pending3 = readPublishedBundle(componentId, releaseItemId, version);
3955
+ publishedBundles.set(releaseItemId, pending3);
3956
+ pending3.catch(() => {
3957
+ if (publishedBundles.get(releaseItemId) === pending3) publishedBundles.delete(releaseItemId);
3958
+ });
3959
+ }
3960
+ return pending3;
3961
+ }
3962
+ function loadPublishedBundle(source) {
3963
+ const live = liveRelease(source);
3964
+ if (!source.id || !live) return Promise.resolve({ status: "unpublished" });
3965
+ return publishedBundle(source.id, live.releaseItemId, live.version);
3966
+ }
3967
+ function usePublishedComponent(item) {
3968
+ const [onScreen, setOnScreen] = React.useState(null);
3969
+ const [status, setStatus] = React.useState("loading");
3970
+ const [error, setError] = React.useState(null);
3971
+ const shown = React.useRef(null);
3972
+ const known = item != null;
3973
+ const componentId = item?.id || null;
3974
+ const live = item ? liveRelease(item) : null;
3975
+ const releaseItemId = live?.releaseItemId ?? null;
3976
+ const version = live?.version ?? null;
3977
+ React.useEffect(() => {
3978
+ if (!known) return;
3979
+ const takeDown = () => {
3980
+ if (shown.current?.cssKey) releaseComponentCss(shown.current.cssKey);
3981
+ shown.current = null;
3982
+ setOnScreen(null);
3983
+ };
3984
+ if (!componentId || !releaseItemId || version === null) {
3985
+ takeDown();
3986
+ setError(null);
3987
+ setStatus("unpublished");
3988
+ return;
3989
+ }
3990
+ let cancelled = false;
3991
+ setError(null);
3992
+ if (shown.current && shown.current.componentId !== componentId) takeDown();
3993
+ if (!shown.current) setStatus("loading");
3994
+ (async () => {
3995
+ let heldCssKey = null;
3996
+ try {
3997
+ const bundle = await publishedBundle(componentId, releaseItemId, version);
3998
+ if (cancelled) return;
3999
+ if (bundle.status !== "ready") {
4000
+ takeDown();
4001
+ setStatus(bundle.status);
4002
+ return;
4003
+ }
4004
+ let resolved = publishedComponents.get(releaseItemId);
4005
+ if (!resolved) {
4006
+ resolved = evaluateBundle(bundle.script);
4007
+ if (!resolved) {
4008
+ throw new Error(
4009
+ "The published script did not hand over a component. Expected a __FSAOS_REGISTER__(Component) call or window.__FSAOS_COMPONENT__."
4010
+ );
4011
+ }
4012
+ if (typeof resolved !== "function") {
4013
+ throw new Error(`The published script handed over something that is not a React component (${typeof resolved}).`);
4014
+ }
4015
+ publishedComponents.set(releaseItemId, resolved);
4016
+ }
4017
+ const cssKey = bundle.stylesheet ? `release:${releaseItemId}` : null;
4018
+ if (cssKey) {
4019
+ heldCssKey = cssKey;
4020
+ await holdComponentCss(cssKey, async () => bundle.stylesheet);
4021
+ }
4022
+ if (cancelled) {
4023
+ if (heldCssKey) releaseComponentCss(heldCssKey);
4024
+ return;
4025
+ }
4026
+ const previousCssKey = shown.current?.cssKey ?? null;
4027
+ shown.current = { componentId, releaseItemId, cssKey };
4028
+ heldCssKey = null;
4029
+ setOnScreen({ Component: resolved, version });
4030
+ setStatus("ready");
4031
+ if (previousCssKey) releaseComponentCss(previousCssKey);
4032
+ } catch (err) {
4033
+ if (heldCssKey) releaseComponentCss(heldCssKey);
4034
+ if (cancelled) return;
4035
+ setError(err instanceof Error ? err : new Error(String(err)));
4036
+ if (!shown.current) setStatus("error");
4037
+ }
4038
+ })();
4039
+ return () => {
4040
+ cancelled = true;
4041
+ };
4042
+ }, [known, componentId, releaseItemId, version]);
4043
+ React.useEffect(() => () => {
4044
+ if (shown.current?.cssKey) releaseComponentCss(shown.current.cssKey);
4045
+ shown.current = null;
4046
+ }, []);
4047
+ return {
4048
+ Component: onScreen?.Component ?? null,
4049
+ status,
4050
+ error,
4051
+ /** The version on screen. */
4052
+ version: onScreen?.version ?? null
4053
+ };
4054
+ }
3887
4055
  var THEME_PROPERTIES = [
3888
4056
  "--color-primary",
3889
4057
  "--color-secondary",
@@ -6709,6 +6877,7 @@ exports.isScopeReady = isScopeReady;
6709
6877
  exports.itemsFilterFromQueryFilter = itemsFilterFromQueryFilter;
6710
6878
  exports.listChildren = listChildren;
6711
6879
  exports.loadMounts = loadMounts;
6880
+ exports.loadPublishedBundle = loadPublishedBundle;
6712
6881
  exports.mount = mount2;
6713
6882
  exports.mountRealtimeScope = mountRealtimeScope;
6714
6883
  exports.normalizeItem = normalizeItem;
@@ -6797,6 +6966,7 @@ exports.usePersonalItemOrder = usePersonalItemOrder;
6797
6966
  exports.usePersonalSections = usePersonalSections;
6798
6967
  exports.usePinnedItems = usePinnedItems;
6799
6968
  exports.usePrincipal = usePrincipal;
6969
+ exports.usePublishedComponent = usePublishedComponent;
6800
6970
  exports.useRealtimeQuery = useRealtimeQuery;
6801
6971
  exports.useRecentActivity = useRecentActivity;
6802
6972
  exports.useResolve = useResolve;