autosolutions-os 0.2.3 → 0.2.5

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.
@@ -0,0 +1,224 @@
1
+ /**
2
+ * The os_context() cache, with no React: one read per page and person, a
3
+ * failure never kept and asked again, and every mounted reader told of a new
4
+ * answer. context.ts wraps it in hooks; it is apart so a test (or a worker)
5
+ * can load it without React.
6
+ */
7
+ import { coreProjectRef } from "./config.js";
8
+ /* The person the stored session belongs to: the user id in this origin's
9
+ Supabase session, or undefined when it cannot be told (no window, storage
10
+ blocked). An app that keeps its session in cookies has none here, which
11
+ reads as nobody, the same before and after: the cache then follows sign-in
12
+ changes only through `watchOsAuth`. */
13
+ function storedUser() {
14
+ if (typeof window === "undefined")
15
+ return undefined;
16
+ let raw;
17
+ try {
18
+ raw = window.localStorage.getItem(`sb-${coreProjectRef()}-auth-token`);
19
+ }
20
+ catch {
21
+ return undefined;
22
+ }
23
+ if (!raw)
24
+ return null;
25
+ try {
26
+ const session = JSON.parse(raw);
27
+ if (typeof session.user?.id === "string")
28
+ return session.user.id;
29
+ if (typeof session.access_token === "string") {
30
+ const payload = session.access_token.split(".")[1] ?? "";
31
+ const claims = JSON.parse(atob(payload.replace(/-/g, "+").replace(/_/g, "/")));
32
+ if (typeof claims.sub === "string")
33
+ return claims.sub;
34
+ }
35
+ }
36
+ catch {
37
+ /* not a session we can read */
38
+ }
39
+ return null;
40
+ }
41
+ /**
42
+ * One fetch per page and person, and a FAILURE is never cached. A call that
43
+ * races a token refresh would otherwise blank both switchers until a full
44
+ * reload. The answer is the signed-in person's: when another person signs in
45
+ * on the same browser without a reload (in this tab or another), the next
46
+ * read asks again rather than handing them the last person's companies.
47
+ */
48
+ let pending = null;
49
+ /* Whose answer `pending` is: the stored session's user when it was asked. */
50
+ let pendingFor;
51
+ /* The person `watchOsAuth` last heard about, for apps whose session is not in localStorage. */
52
+ let authUser;
53
+ let failed = false;
54
+ let lastOs = null;
55
+ const who = () => {
56
+ const stored = storedUser();
57
+ return stored ?? authUser ?? stored;
58
+ };
59
+ export function loadOsContext(os) {
60
+ lastOs = os;
61
+ watchWindow();
62
+ const person = who();
63
+ if (pending && person !== undefined && pendingFor !== undefined && person !== pendingFor)
64
+ pending = null;
65
+ if (!pending) {
66
+ pendingFor = person;
67
+ const call = Promise.resolve(os.rpc("os_context"))
68
+ .then(({ data, error }) => {
69
+ if (error || !data)
70
+ throw new Error("os_context");
71
+ if (pending === call)
72
+ failed = false;
73
+ return data;
74
+ })
75
+ .catch(() => {
76
+ if (pending === call) {
77
+ pending = null;
78
+ failed = true;
79
+ }
80
+ return null;
81
+ });
82
+ pending = call;
83
+ }
84
+ return pending;
85
+ }
86
+ /** Forget the cached answer, so the next read reflects a company switch. */
87
+ export function invalidateOsContext() {
88
+ pending = null;
89
+ failed = false;
90
+ attempt = 0;
91
+ if (timer !== null) {
92
+ clearTimeout(timer);
93
+ timer = null;
94
+ }
95
+ }
96
+ /* Every mounted reader (useOsContextState), so an in-place switch, a retry
97
+ and a change of person reach them all. */
98
+ const readers = new Set();
99
+ /** Hear every new answer (and a change of person) until the returned function is called. */
100
+ export function subscribeOsContext(read) {
101
+ readers.add(read);
102
+ return () => { readers.delete(read); };
103
+ }
104
+ const tell = (context, status) => {
105
+ readers.forEach((read) => read(context, status));
106
+ };
107
+ /**
108
+ * Ask again and hand the answer to every mounted reader: after a company
109
+ * switch that does not reload the page. A failed call changes nothing.
110
+ */
111
+ export async function refreshOsContext(os) {
112
+ pending = null;
113
+ const value = await loadOsContext(os);
114
+ if (value)
115
+ tell(value, "ready");
116
+ return value;
117
+ }
118
+ /* After a failed read, ask again: 1, 3, 10, 30 and 60 seconds on, and
119
+ whenever the window comes back (focus, online, visible again) or the app
120
+ moves (retryOsContext). */
121
+ const DELAYS = [1000, 3000, 10000, 30000, 60000];
122
+ let timer = null;
123
+ let attempt = 0;
124
+ function again(os) {
125
+ return loadOsContext(os).then((value) => {
126
+ if (value) {
127
+ attempt = 0;
128
+ if (timer !== null) {
129
+ clearTimeout(timer);
130
+ timer = null;
131
+ }
132
+ tell(value, "ready");
133
+ }
134
+ else {
135
+ scheduleOsContextRetry(os);
136
+ }
137
+ return value;
138
+ });
139
+ }
140
+ /** After a failed read: ask again on a timer (1, 3, 10, 30, 60 seconds). */
141
+ export function scheduleOsContextRetry(os) {
142
+ if (timer !== null || typeof window === "undefined" || attempt >= DELAYS.length)
143
+ return;
144
+ timer = setTimeout(() => {
145
+ timer = null;
146
+ attempt += 1;
147
+ void again(os);
148
+ }, DELAYS[attempt]);
149
+ }
150
+ /**
151
+ * Ask again now if the last read failed (the frame calls it when the app's
152
+ * location changes); otherwise the cached answer. Every mounted reader gets a
153
+ * new answer.
154
+ */
155
+ export function retryOsContext(os) {
156
+ return failed ? again(os) : loadOsContext(os);
157
+ }
158
+ /* A change of person in another tab of this origin rewrites the stored
159
+ session (a storage event here); coming back to the window after a failed
160
+ read asks again. Installed once, in the browser only. */
161
+ let watching = false;
162
+ function watchWindow() {
163
+ if (watching || typeof window === "undefined" || typeof window.addEventListener !== "function")
164
+ return;
165
+ watching = true;
166
+ const wake = () => {
167
+ if (failed && lastOs)
168
+ void again(lastOs);
169
+ };
170
+ window.addEventListener("focus", wake);
171
+ window.addEventListener("online", wake);
172
+ if (typeof document !== "undefined") {
173
+ document.addEventListener("visibilitychange", () => {
174
+ if (document.visibilityState === "visible")
175
+ wake();
176
+ });
177
+ }
178
+ window.addEventListener("storage", (event) => {
179
+ if (event.key !== null && event.key !== `sb-${coreProjectRef()}-auth-token`)
180
+ return;
181
+ personChanged(storedUser());
182
+ });
183
+ }
184
+ function personChanged(person) {
185
+ if (person === undefined || person === pendingFor)
186
+ return;
187
+ invalidateOsContext();
188
+ pendingFor = person;
189
+ if (person === null) {
190
+ tell(null, "loading");
191
+ return;
192
+ }
193
+ if (lastOs)
194
+ void again(lastOs);
195
+ }
196
+ /**
197
+ * Follow sign-ins and sign-outs through the app's Supabase auth client
198
+ * (`supabase.auth`), live, in this tab too, and for an app whose session is
199
+ * not in localStorage (one that keeps it in cookies). OsWorkspaceFrame calls
200
+ * it with its `auth`. A token refresh for the same person changes nothing.
201
+ */
202
+ const watchedAuth = new WeakSet();
203
+ export function watchOsAuth(auth) {
204
+ const client = auth;
205
+ if (!client || typeof client !== "object" || typeof client.onAuthStateChange !== "function" || watchedAuth.has(client))
206
+ return;
207
+ watchedAuth.add(client);
208
+ try {
209
+ client.onAuthStateChange((_event, session) => {
210
+ const person = session?.user?.id ?? null;
211
+ if (authUser === undefined) {
212
+ authUser = person;
213
+ return;
214
+ }
215
+ if (person === authUser)
216
+ return;
217
+ authUser = person;
218
+ personChanged(person);
219
+ });
220
+ }
221
+ catch {
222
+ /* following sign-ins is a nicety: never let it break the page */
223
+ }
224
+ }
package/dist/frame.d.ts CHANGED
@@ -10,10 +10,12 @@
10
10
  * It knows nothing about routers. Hand it the current location (pathname plus
11
11
  * query) and an `onNavigate(href)` that pushes an in-app path. Rows for other
12
12
  * apps are links, which it follows itself in the same tab (a middle-click or
13
- * a modified click opens them where the browser does). Browser Back and
14
- * Forward move the menus because the frame follows `location`, and it only
15
- * calls `onNavigate` when someone clicks. A click on the tab or row it already shows, from a page
16
- * filed under it (a draft under Requests), goes to that tab's own page.
13
+ * a modified click opens them where the browser does); this app's own rows and
14
+ * tabs are links to their paths too (`hrefFor`). Browser Back and Forward
15
+ * move the menus because the frame follows `location`, and it only calls
16
+ * `onNavigate` when someone clicks. A click on the tab or row it already
17
+ * shows, from a page filed under it (a draft under Requests), goes to that
18
+ * tab's own page.
17
19
  */
18
20
  import { type ReactNode } from "react";
19
21
  import type { WorkspaceState } from "autosolutions-design-system";
@@ -27,16 +29,24 @@ import { type OsAppTool, type OsHubSection } from "./nav.js";
27
29
  * whose company is fixed some other way (an assignment, say).
28
30
  * - a function: the app's own in-place switch. The frame calls it with the
29
31
  * chosen company, closes the menu and does not reload; when it resolves,
30
- * the plate and the menu links follow the new company. The function reports
31
- * its own failures (a toast); a rejection only leaves the plate as it was.
32
+ * the plate and the menu links follow the new company at once, and the
33
+ * frame reads the core again (asking again if that read fails). The function
34
+ * reports its own failures (a toast); a rejection only leaves the plate as
35
+ * it was.
32
36
  */
33
37
  export type OsCompanySwitch = "os" | "none" | ((tenant: OsTenant) => Promise<void>);
34
38
  export type OsWorkspaceFrameProps = {
35
39
  /** The client's `os` (public schema) connection. */
36
40
  os: unknown;
37
- /** Used for Sign out when `onSignOut` is not given: signs out, then reloads. */
41
+ /**
42
+ * The app's Supabase auth client (`supabase.auth`). Used for Sign out when
43
+ * `onSignOut` is not given (signs out, then reloads), and followed for
44
+ * sign-ins and sign-outs, so a person who signs in after another, without a
45
+ * reload, sees their own companies.
46
+ */
38
47
  auth?: {
39
48
  signOut: () => Promise<unknown>;
49
+ onAuthStateChange?: (...args: never[]) => unknown;
40
50
  };
41
51
  /** This app's catalogue key; "hub" for the Hub. */
42
52
  appKey: string;
@@ -46,8 +56,28 @@ export type OsWorkspaceFrameProps = {
46
56
  hubItems?: OsHubSection[];
47
57
  /** Where the app is: pathname plus query. */
48
58
  location: string;
49
- /** Push an in-app path. Links to other apps are opened by the frame. */
50
- onNavigate: (href: string) => void;
59
+ /**
60
+ * Push an in-app path. Links to other apps are opened by the frame. Return
61
+ * the router's navigation promise (TanStack Router's `navigate`) and a
62
+ * navigation the app does not make after all (an unsaved-changes prompt
63
+ * the person stays on, which leaves the address bar where it was) puts the
64
+ * frame back where the URL is.
65
+ */
66
+ onNavigate: (href: string) => void | PromiseLike<unknown>;
67
+ /**
68
+ * How this app's own paths are written as links, so its rows and tabs are
69
+ * real links (a middle-click, a modified click and Copy link work, as on
70
+ * the apps' own menus before the frame); a plain click still goes through
71
+ * `onNavigate`. Default: the path as it is, for a router that reads the
72
+ * address bar's path. A hash router passes `(path) => "#" + path`; an app
73
+ * whose places are not addresses at all (state, not routes) passes `null`,
74
+ * and its rows and tabs stay buttons.
75
+ */
76
+ hrefFor?: ((path: string) => string | null) | null;
77
+ /**
78
+ * The top bar's search field. With the design system 6.4.0 it is drawn only
79
+ * when `onChange` is given: without one the bar has no search box.
80
+ */
51
81
  search?: {
52
82
  placeholder?: string;
53
83
  value?: string;
@@ -70,9 +100,13 @@ export type OsWorkspaceFrameProps = {
70
100
  /** Set the browser-tab icon from the current menu glyph. Default true. */
71
101
  favicon?: boolean;
72
102
  /**
73
- * Whether the menu starts open, for the first location only (false on a
74
- * narrow screen, say). After that the frame's own rule applies: open on a
75
- * function with a menu. Default: that rule from the start.
103
+ * Whether the menu starts open, for the first location only. After that the
104
+ * frame's own rule applies: open on a function with a menu. Default: that
105
+ * rule from the start. A phone's screen needs none: with the design system
106
+ * 6.4.0 the menu is closed there on every location and after every pick,
107
+ * once the page is live. A page rendered on the server shows it open on a
108
+ * phone until it hydrates (the server cannot know the screen), and
109
+ * `initialOpen={true}` keeps it open there on purpose.
76
110
  */
77
111
  initialOpen?: boolean;
78
112
  className?: string;
@@ -82,4 +116,4 @@ export type OsWorkspaceFrameProps = {
82
116
  } & {
83
117
  [key: `aria-${string}`]: string | number | boolean | undefined;
84
118
  };
85
- export declare function OsWorkspaceFrame({ os, auth, appKey, tools, hubItems, location, onNavigate, search, actions, companySwitch, panelFooter, onSignOut, settingsPath, homePath, admin, favicon, initialOpen, className, children, ...rest }: OsWorkspaceFrameProps): import("react").JSX.Element;
119
+ export declare function OsWorkspaceFrame({ os, auth, appKey, tools, hubItems, location, onNavigate, hrefFor, search, actions, companySwitch, panelFooter, onSignOut, settingsPath, homePath, admin, favicon, initialOpen, className, children, ...rest }: OsWorkspaceFrameProps): import("react").JSX.Element;
package/dist/frame.js CHANGED
@@ -11,58 +11,107 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
11
11
  * It knows nothing about routers. Hand it the current location (pathname plus
12
12
  * query) and an `onNavigate(href)` that pushes an in-app path. Rows for other
13
13
  * apps are links, which it follows itself in the same tab (a middle-click or
14
- * a modified click opens them where the browser does). Browser Back and
15
- * Forward move the menus because the frame follows `location`, and it only
16
- * calls `onNavigate` when someone clicks. A click on the tab or row it already shows, from a page
17
- * filed under it (a draft under Requests), goes to that tab's own page.
14
+ * a modified click opens them where the browser does); this app's own rows and
15
+ * tabs are links to their paths too (`hrefFor`). Browser Back and Forward
16
+ * move the menus because the frame follows `location`, and it only calls
17
+ * `onNavigate` when someone clicks. A click on the tab or row it already
18
+ * shows, from a page filed under it (a draft under Requests), goes to that
19
+ * tab's own page.
18
20
  */
19
- import { useEffect, useMemo, useState } from "react";
21
+ import { useEffect, useMemo, useRef, useState } from "react";
20
22
  import { ActionList, TopBar, WorkspaceFrame } from "autosolutions-design-system";
21
23
  import { useCompanySwitch } from "./chrome.js";
22
- import { markFor, refreshOsContext } from "./context.js";
24
+ import { markFor, refreshOsContext, retryOsContext, watchOsAuth } from "./context.js";
23
25
  import { myAdminScope } from "./identity.js";
24
26
  import { catalogueLinks, osFrame } from "./nav.js";
25
- /* A company's mark in the company menu; nothing, never a broken image, when
26
- its artwork does not load (the row already says the company's name). */
27
+ /* A company's mark in the company menu. When its artwork does not load, the
28
+ slot stays, empty (the row already says the company's name), so the names
29
+ stay lined up; never a broken image. */
27
30
  function CompanyMenuMark({ src }) {
28
31
  const [failed, setFailed] = useState(null);
29
32
  if (failed === src)
30
- return null;
33
+ return _jsx("span", { className: "as-ws__company-mark", "aria-hidden": "true" });
31
34
  return _jsx("img", { className: "as-ws__company-mark", src: src, alt: "", onError: () => { if (failed !== src)
32
35
  setFailed(src); } });
33
36
  }
34
- export function OsWorkspaceFrame({ os, auth, appKey, tools, hubItems, location, onNavigate, search, actions, companySwitch = "os", panelFooter, onSignOut, settingsPath, homePath, admin, favicon = true, initialOpen, className, children, ...rest }) {
37
+ /* This app's own rows and tabs as links to their paths. Rows for other apps
38
+ already carry their address; a locked row is never a link. */
39
+ function linked(sections, hrefFor) {
40
+ const tab = (t) => {
41
+ const href = t.path && !t.disabled ? hrefFor(t.path) : null;
42
+ return href ? { ...t, href } : t;
43
+ };
44
+ const tabs = (list) => (list.length > 0 && "items" in list[0]
45
+ ? list.map((group) => ({ ...group, items: group.items.map(tab) }))
46
+ : list.map(tab));
47
+ const out = {};
48
+ for (const [fn, list] of Object.entries(sections)) {
49
+ out[fn] = list.map((section) => ({
50
+ ...section,
51
+ items: section.items.map((row) => {
52
+ const own = row.path && !row.href && !row.disabled ? hrefFor(row.path) : null;
53
+ return { ...row, ...(own ? { href: own } : {}), ...(row.tabs ? { tabs: tabs(row.tabs) } : {}) };
54
+ }),
55
+ }));
56
+ }
57
+ return out;
58
+ }
59
+ /* Where the address bar is: a navigation the app does not make leaves it. */
60
+ const here = () => (typeof window === "undefined" ? "" : window.location.pathname + window.location.search + window.location.hash);
61
+ export function OsWorkspaceFrame({ os, auth, appKey, tools, hubItems, location, onNavigate, hrefFor, search, actions, companySwitch = "os", panelFooter, onSignOut, settingsPath, homePath, admin, favicon = true, initialOpen, className, children, ...rest }) {
35
62
  /* Only data-* and aria-* reach the frame's root. */
36
63
  const attributes = Object.fromEntries(Object.entries(rest).filter(([key]) => /^(data|aria)-/.test(key)));
37
- const { context, current, tenants, busy: switching, error, choose } = useCompanySwitch(os, appKey);
64
+ const { context, status, current: read, tenants, busy: switching, error, choose } = useCompanySwitch(os, appKey);
38
65
  const [menuOpen, setMenuOpen] = useState(false);
39
66
  const [ownBusy, setOwnBusy] = useState(false);
40
67
  const busy = switching || ownBusy;
68
+ /* An in-place switch (companySwitch as a function) makes the chosen company
69
+ the acting one at once: the plate, the menu's check and the links follow
70
+ it until the core is read again, whether or not that read succeeds, so a
71
+ read that fails never leaves the plate on the company the session has
72
+ left (and a pick of that company is a real switch back). */
73
+ const [acting, setActing] = useState(null);
74
+ const current = acting && acting.over === context ? acting.tenant : read;
75
+ const contextNow = useRef(context);
76
+ contextNow.current = context;
77
+ const live = useRef(true);
78
+ useEffect(() => () => { live.current = false; }, []);
41
79
  /* The core decides who manages something; the footer only reflects it. */
42
80
  const [manages, setManages] = useState(false);
43
81
  useEffect(() => {
44
82
  if (admin !== undefined)
45
83
  return undefined;
46
- let live = true;
84
+ let alive = true;
47
85
  myAdminScope(os)
48
86
  .then((scope) => {
49
- if (live)
87
+ if (alive)
50
88
  setManages(scope.isPlatformAdmin || scope.managesTenants.length > 0);
51
89
  })
52
90
  .catch(() => {
53
91
  /* No Admin row is the safe failure; the admin console checks again anyway. */
54
92
  });
55
93
  return () => {
56
- live = false;
94
+ alive = false;
57
95
  };
58
96
  }, [os, admin]);
97
+ /* Follow sign-ins through the app's auth client, when it hands one. */
98
+ useEffect(() => {
99
+ if (auth && typeof auth.onAuthStateChange === "function")
100
+ watchOsAuth(auth);
101
+ }, [auth]);
102
+ /* A read that failed is asked again when the app moves, as well as on a
103
+ timer and when the window comes back (context.ts). */
104
+ useEffect(() => {
105
+ if (status === "failed")
106
+ void retryOsContext(os);
107
+ }, [location]);
59
108
  const apps = context?.apps;
60
109
  const slug = current?.slug ?? null;
61
110
  const frame = useMemo(() => {
62
- /* Only the catalogue says what this person holds. Until it arrives
63
- nothing is linked and nothing is "not held": other apps' tools read as
64
- not linked, never as a fixed address the person may not hold. */
65
- const { links, locked } = apps ? catalogueLinks(apps, slug) : { links: {}, locked: {} };
111
+ /* Only the catalogue says what this person holds. Until it arrives (or
112
+ while a failed read is asked again) nothing is linked and nothing is
113
+ "not held" or "not linked": other apps' tools read as being checked. */
114
+ const { links, locked } = catalogueLinks(apps ?? null, slug);
66
115
  return osFrame({
67
116
  appKey, links, locked, admin: admin ?? manages, tenantSlug: slug,
68
117
  ...(tools ? { tools } : {}),
@@ -71,21 +120,40 @@ export function OsWorkspaceFrame({ os, auth, appKey, tools, hubItems, location,
71
120
  ...(homePath ? { homePath } : {}),
72
121
  });
73
122
  }, [appKey, apps, admin, manages, slug, tools, hubItems, settingsPath, homePath]);
123
+ const linkTo = hrefFor === undefined ? (path) => path : hrefFor;
124
+ const sections = useMemo(() => (linkTo ? linked(frame.sections, linkTo) : frame.sections), [frame, hrefFor]);
74
125
  /* `false` tells the frame a click went nowhere (Settings on the page
75
- Settings goes to), so it stays where the location puts it. */
126
+ Settings goes to), so it stays where the location puts it. A promise of
127
+ `false`: the app's router did not make the navigation after all (the
128
+ address bar never moved), so the frame goes back where the URL is. */
76
129
  const navigate = (state) => {
77
130
  const target = frame.targetFor(state, location);
78
131
  if (!target)
79
132
  return false;
80
- if (target.external)
133
+ if (target.external) {
81
134
  window.location.assign(target.href);
82
- else
83
- onNavigate(target.href);
135
+ return true;
136
+ }
137
+ const before = here();
138
+ const result = onNavigate(target.href);
139
+ if (result && typeof result.then === "function") {
140
+ return Promise.resolve(result).then(() => here() !== before, () => here() !== before);
141
+ }
84
142
  return true;
85
143
  };
86
144
  const signOut = onSignOut ?? (() => {
87
145
  void auth?.signOut().then(() => window.location.reload());
88
146
  });
147
+ /* After an in-place switch: read the core again, and again if that fails,
148
+ a few times, while the frame is mounted. */
149
+ const readAgain = (tries) => {
150
+ void refreshOsContext(os).then((value) => {
151
+ if (value || tries <= 1 || !live.current)
152
+ return;
153
+ setTimeout(() => { if (live.current)
154
+ readAgain(tries - 1); }, 1500);
155
+ });
156
+ };
89
157
  /* The company menu, offered only when there is somewhere to switch to: a
90
158
  menu of radio items, the acting company checked. */
91
159
  const pick = (tenant) => {
@@ -98,11 +166,17 @@ export function OsWorkspaceFrame({ os, auth, appKey, tools, hubItems, location,
98
166
  return;
99
167
  setOwnBusy(true);
100
168
  companySwitch(tenant)
101
- .then(() => refreshOsContext(os))
169
+ .then(() => {
170
+ if (!live.current)
171
+ return;
172
+ setActing({ tenant, over: contextNow.current });
173
+ readAgain(3);
174
+ })
102
175
  .catch(() => {
103
176
  /* The app's switch says what went wrong; the plate stays as it was. */
104
177
  })
105
- .finally(() => setOwnBusy(false));
178
+ .finally(() => { if (live.current)
179
+ setOwnBusy(false); });
106
180
  };
107
181
  const switchable = companySwitch !== "none" && Boolean(current) && tenants.length > 1;
108
182
  const companyMenu = switchable && current ? (_jsxs(_Fragment, { children: [_jsx(ActionList, { role: "menu", "aria-label": "Switch company", sections: [{
@@ -118,6 +192,8 @@ export function OsWorkspaceFrame({ os, auth, appKey, tools, hubItems, location,
118
192
  }] }), busy && _jsx("div", { className: "as-ws__company-note", role: "status", children: "Switching\u2026" }), error && _jsx("div", { className: "as-ws__company-note as-ws__company-note--error", role: "alert", children: error })] })) : undefined;
119
193
  const topBar = (_jsx(TopBar, { variant: "workspace", searchPlaceholder: search?.placeholder ?? "Search", searchValue: search?.value, onSearchChange: search?.onChange, actions: actions, company: current?.slug ?? null, companySrc: current ? markFor(current, "plain") : undefined,
120
194
  /* Also what the plate shows when the company has no artwork, or it fails to load. */
121
- companyName: current?.name, onSwitchCompany: switchable ? () => setMenuOpen((open) => !open) : undefined, companyMenu: companyMenu, companyMenuOpen: menuOpen, onCompanyMenuClose: () => setMenuOpen(false) }));
122
- return (_jsx(WorkspaceFrame, { className: className, topBar: topBar, functions: frame.functions, sections: frame.sections, footerItems: frame.footerItems, homeFunction: frame.homeFunction, location: { ...frame.locate(location), href: location }, onNavigate: navigate, onSignOut: signOut, favicon: favicon, panelFooter: panelFooter, ...(initialOpen === undefined ? {} : { initialOpen }), ...attributes, children: children }));
195
+ companyName: current?.name,
196
+ /* While the company is read, its place on the bar is kept. */
197
+ companyPending: !current && status === "loading" ? (companySwitch === "none" ? "plate" : true) : undefined, onSwitchCompany: switchable ? () => setMenuOpen((open) => !open) : undefined, companyMenu: companyMenu, companyMenuOpen: menuOpen, onCompanyMenuClose: () => setMenuOpen(false) }));
198
+ return (_jsx(WorkspaceFrame, { className: className, topBar: topBar, functions: frame.functions, sections: sections, footerItems: frame.footerItems, homeFunction: frame.homeFunction, location: { ...frame.locate(location), href: location }, onNavigate: navigate, onSignOut: signOut, favicon: favicon, panelFooter: panelFooter, ...(initialOpen === undefined ? {} : { initialOpen }), ...attributes, children: children }));
123
199
  }
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { coreUrl, corePublishableKey, coreProjectRef, companyMarkUrl, appLabelUrl, HUB_URL, PARENT_DOMAIN } from "./config.js";
2
2
  export { createOsClient, resetOsClient, type OsClient } from "./client.js";
3
- export { adoptSharedSession, publishSessionChanges, sharedSessionCookieName, joinChunks } from "./session.js";
4
- export { loadOsContext, invalidateOsContext, refreshOsContext, useOsContext, useTenant, useApps, groupApps, markFor, labelFor, withTenantHint, type OsContext, type OsTenant, type OsApp, } from "./context.js";
3
+ export { adoptSharedSession, followSharedSession, publishSessionChanges, sharedSessionCookieName, joinChunks } from "./session.js";
4
+ export { loadOsContext, invalidateOsContext, refreshOsContext, retryOsContext, watchOsAuth, useOsContext, useOsContextState, useTenant, useApps, groupApps, markFor, labelFor, withTenantHint, type OsContext, type OsContextStatus, type OsTenant, type OsApp, } from "./context.js";
5
5
  export { isEntitled, isActiveMember, appRole, appVariant, currentTenant, toolAllowed, myAdminScope, canManageCurrentCompany, type AdminScope, } from "./identity.js";
6
6
  export { OsAppSwitcher, OsAppSwitcherPlate, OsCompanySwitcher, OsBar, useCompanySwitch } from "./chrome.js";
7
7
  export { OsAuthGate, type OsAuthGateProps } from "./gate.js";
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export { coreUrl, corePublishableKey, coreProjectRef, companyMarkUrl, appLabelUrl, HUB_URL, PARENT_DOMAIN } from "./config.js";
2
2
  export { createOsClient, resetOsClient } from "./client.js";
3
- export { adoptSharedSession, publishSessionChanges, sharedSessionCookieName, joinChunks } from "./session.js";
4
- export { loadOsContext, invalidateOsContext, refreshOsContext, useOsContext, useTenant, useApps, groupApps, markFor, labelFor, withTenantHint, } from "./context.js";
3
+ export { adoptSharedSession, followSharedSession, publishSessionChanges, sharedSessionCookieName, joinChunks } from "./session.js";
4
+ export { loadOsContext, invalidateOsContext, refreshOsContext, retryOsContext, watchOsAuth, useOsContext, useOsContextState, useTenant, useApps, groupApps, markFor, labelFor, withTenantHint, } from "./context.js";
5
5
  export { isEntitled, isActiveMember, appRole, appVariant, currentTenant, toolAllowed, myAdminScope, canManageCurrentCompany, } from "./identity.js";
6
6
  export { OsAppSwitcher, OsAppSwitcherPlate, OsCompanySwitcher, OsBar, useCompanySwitch } from "./chrome.js";
7
7
  export { OsAuthGate } from "./gate.js";
package/dist/nav.d.ts CHANGED
@@ -78,11 +78,16 @@ export declare const HUB_PATHS: {
78
78
  readonly admin: "/admin";
79
79
  readonly settings: "/comms/settings";
80
80
  };
81
- /** Why a row is locked. A tool whose status is In progress or To build says so instead. */
81
+ /**
82
+ * Why a row is locked. A tool whose status is In progress or To build says so
83
+ * instead. `checking` is a Live tool whose app the catalogue decides, while
84
+ * os_context() has not answered yet (or failed, and is being asked again).
85
+ */
82
86
  export declare const HINTS: {
83
87
  readonly locked: "Ask your company admin to switch this on for you";
84
88
  readonly notBuilt: "Not built yet";
85
89
  readonly notLinked: "Live, not linked from the Hub yet";
90
+ readonly checking: "Checking your access…";
86
91
  };
87
92
  /** The rail footer: Admin (for someone who manages something), Settings, then Sign out, always last. */
88
93
  export declare function osFooter({ admin }?: {
@@ -109,11 +114,16 @@ export declare function staticLinks(): Record<string, string>;
109
114
  * A fixed `url` is never consulted here: it is no way round the catalogue.
110
115
  * Tools with no app keep osFrame's own rules. Links are final: osFrame adds
111
116
  * nothing to them.
117
+ *
118
+ * With `apps` null (the catalogue has not answered yet, or the read failed
119
+ * and is being asked again), nothing is linked, and a Live tool with an app
120
+ * reads "Checking your access…" rather than claiming it is not linked or not
121
+ * held; any other keeps the map's own status.
112
122
  */
113
123
  export declare function catalogueLinks(apps: ReadonlyArray<{
114
124
  key: string;
115
125
  url: string | null;
116
- }>, tenantSlug?: string | null): {
126
+ }> | null, tenantSlug?: string | null): {
117
127
  links: Record<string, string>;
118
128
  locked: Record<string, string>;
119
129
  };