autosolutions-os 0.2.2 → 0.2.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,156 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.4 - 2026-10-14
4
+
5
+ Released with `autosolutions-design-system` 6.4.0: the workspace frame in the
6
+ final design, with 6.3.5's fixes (wide pages scroll sideways again, a phone's
7
+ menu closes on every pick, no search box without a search) and the fixes of
8
+ the full review. The design-system peer range is now `>=6.4.0 <7`: the frame
9
+ passes the bar 6.4.0's `companyPending`, which an older design system would
10
+ put on the bar's element, and it relies on 6.4.0 for links on tabs, refused
11
+ navigations and the rest below.
12
+
13
+ - **A company switch to a company that does not hold this app goes to the
14
+ Hub again.** When `switch_company_for_app` answers with no `appUrl` (the
15
+ new company does not have the app), `useCompanySwitch`, and so
16
+ `OsCompanySwitcher` and `OsWorkspaceFrame`'s plate with `companySwitch`
17
+ `"os"`, reloaded the page in place, where the app showed its "not
18
+ entitled" state. It now goes to the Hub (`HUB_URL`) in the same tab, as
19
+ the apps' own company switchers did before they took this package, and as
20
+ this package's own doc comments already said. The Hub still reloads in
21
+ place, and a returned `appUrl` still reloads when it is this origin and
22
+ navigates otherwise. The decision is `companySwitchLanding` in
23
+ `src/url.ts` (internal), tested in `test/switch.test.ts`.
24
+ - **This app's own rows and tabs are links.** The frame's tabs and this
25
+ app's own rows were buttons, so a Cmd, Ctrl, Shift or middle click did
26
+ nothing useful and there was no link to copy, where the apps' own menus
27
+ were links. They now carry their path as `href` (`hrefFor`, default the
28
+ path itself): a plain click still goes through `onNavigate`, the rest is
29
+ the browser's. A hash router passes `hrefFor={(path) => "#" + path}`; an
30
+ app whose places never reach the address bar (Label Maker's views)
31
+ passes `hrefFor={null}` and keeps buttons.
32
+ - **A navigation the app does not make leaves the frame where the URL is.**
33
+ The frame shows a click at once; when the app's router then refused the
34
+ navigation (an unsaved-changes prompt the person stays on), the frame
35
+ stayed on what was clicked. When `onNavigate` returns a promise (TanStack
36
+ Router's `navigate`), the frame now waits for it and, if the address bar
37
+ did not move, goes back to where the URL is.
38
+ - **os_context() is the signed-in person's, and a failure is asked again.**
39
+ The cached answer was the page's, whoever was signed in: another person
40
+ signing in on the same browser without a reload (in this tab or another)
41
+ saw the last person's company and companies. It is now keyed on the person
42
+ in the stored session, dropped when another person's session arrives from
43
+ another tab, and followed through the app's auth client when the frame is
44
+ given one (`auth`, or `watchOsAuth(auth)`). A failed read was never asked
45
+ again in a mounted frame: the plate, the company switch and every link to
46
+ another app stayed missing until a reload. It is asked again 1, 3, 10, 30
47
+ and 60 seconds on, when the window comes back (focus, online, visible),
48
+ and when the app's location changes (`retryOsContext`); every mounted
49
+ reader gets the answer. `useOsContextState` says whether the answer is
50
+ still being read, read, or failed.
51
+ - **Until the catalogue answers, no tool claims it is not linked.** Other
52
+ apps' Live tools read "Live, not linked from the Hub yet" while
53
+ os_context() was pending or failing. `catalogueLinks(null)` now marks them
54
+ `HINTS.checking` ("Checking your access…").
55
+ - **An in-place switch moves the plate at once.** With `companySwitch` as a
56
+ function, the plate stayed on the old company when the read after the
57
+ switch failed, and a pick of that old company was then ignored, though the
58
+ session acted as the new one. The chosen company is now the acting one on
59
+ the plate, the menu's check and the links as soon as the switch resolves,
60
+ until the core is read again (asked up to three times).
61
+ - **The plate's place is kept while the company is read**
62
+ (`companyPending`), so an app's own bar controls do not jump when it
63
+ arrives; a company's name on the plate has the whole name as its tooltip;
64
+ and in the company menu a mark that does not load keeps its slot, so the
65
+ names stay lined up.
66
+ - **Where a location is.** A tool's tab now claims a location before the
67
+ tool's own row (Key Accounts: the list at `/` and a draft under Requests
68
+ are one place, so a menu the person closed stays closed between them); a
69
+ tab at `/` claims `/` only, not every page of the app (a member without
70
+ Trends on /trends is on no tab, not on the Dashboard); and paths compare
71
+ without regard to case, as the apps' routers serve them (/ops/Boards is the
72
+ Boards page).
73
+ - **`search` and `initialOpen`, as 6.4.0 draws them.** The bar draws a search
74
+ box only when `search.onChange` is given (a placeholder alone draws none).
75
+ A phone's screen needs no `initialOpen={false}`: at 767px and below the
76
+ menu is closed on every location and after every row or tab picked, once
77
+ the page is live; a server-rendered page shows it open until it hydrates.
78
+ The README's look-only frame example now passes a search handler.
79
+
80
+ ### Upgrading
81
+
82
+ - Take 0.2.4 and `autosolutions-design-system` 6.4.0 together, in one
83
+ commit: bump both in `package.json` and the lockfile. Nothing else is
84
+ required.
85
+ - An app whose router reads hashes passes `hrefFor={(path) => "#" + path}`;
86
+ one whose places are not addresses passes `hrefFor={null}`.
87
+ - An app whose navigations can be refused returns its router's promise from
88
+ `onNavigate` (TanStack Router: `onNavigate={(href) => navigate({ to: href })}`).
89
+ - An app that passes `auth={supabase.auth}` gets sign-in changes followed
90
+ live; others are covered through the stored session.
91
+ - An app whose top bar should keep a search box passes `search.onChange`.
92
+ One that passes no handler (or only a placeholder) loses the box, which
93
+ did nothing.
94
+ - `initialOpen={false}` passed for a narrow screen can go; kept, it does no
95
+ harm. Rows marked `menu: false` only so that a pick closes the menu on a
96
+ narrow screen (the Hub's) can drop that flag there: see the design
97
+ system's 6.4.0 notes.
98
+
99
+ ## 0.2.3 - 2026-10-01
100
+
101
+ With `autosolutions-design-system` 6.3.4, whose frame fixes this release
102
+ wires up. The design-system peer range is now `>=6.3.4 <7`: the Hub's rail
103
+ rule below tells Back to hub from the rail's Hub by 6.3.4's `back` flag,
104
+ and an older design system does not send it.
105
+
106
+ - **The rail's Hub, in the Hub, reopens its menu where the person is.**
107
+ After browsing another function's menu, the rail's Hub left any Hub page
108
+ that was not Smart Comms (an Agent thread, Brand Voice, the Signature
109
+ Generator) for `/comms/overview`: the thread or the form was gone, a
110
+ history entry was added, the Hub menu stayed closed, and from the
111
+ launcher focus fell to the page as the shell changed, all from a control
112
+ announced as "Hub, collapsed". `osFrame().targetFor` now answers the hub
113
+ function with no row with nothing (no navigation) when the URL is already
114
+ in that function and it has a menu, so the frame reopens the Hub menu on
115
+ the current page, expanded, focus kept, as it already did on the
116
+ Overview. From another place (Admin, or an app's own Settings) it still
117
+ lands on the Hub's landing, and Back to hub (`back: true`, design system
118
+ 6.3.4) lands there from anywhere, as before. Other apps are unchanged:
119
+ their rail Hub goes to the Hub.
120
+ - **A company with no artwork has its name on the plate.** With 6.3.4 the
121
+ plate shows the acting company's name when `markFor(tenant, "plain")`
122
+ does not load (a company outside the brand bucket's eight with no stored
123
+ logo, such as one created in Admin), where it showed a broken image.
124
+ `OsWorkspaceFrame` passes the name it always passed. In the company menu,
125
+ a company whose mark does not load keeps its name and drops the image.
126
+ - **Tab order** and **the bar on a phone** come with 6.3.4 and need nothing
127
+ here: an open menu is next in Tab order after its function, and at 767px
128
+ and below the bar fits the screen with the plate whole.
129
+ - **A direct caller of `targetFor` that means Back to hub passes
130
+ `back: true`.** In the Hub (`appKey: "hub"`), `targetFor` with the hub
131
+ function and no row, and no flag, now means the rail's Hub: from a Hub
132
+ page outside the landing (an Agent thread, Brand Voice, the Signature
133
+ Generator) it answers `null`, where 0.2.2 answered the landing. Back to
134
+ hub is `{ fn: { id: "hub" }, item: null, tab: null, back: true }`, which
135
+ still lands on the landing from anywhere. `OsWorkspaceFrame` passes the
136
+ frame's state whole, so an app that renders it changes nothing but the
137
+ two versions; so does an app that wires the design system's
138
+ `WorkspaceFrame` to `osFrame` itself and passes the state to `targetFor`
139
+ whole, `back` included. Outside the Hub nothing changes: the hub function
140
+ with no row goes to the Hub either way.
141
+ - **The Hub's adoption commit also updates one test.** Its
142
+ `src/launcher/nav.test.ts` models Back to hub ("lands Back to hub on the
143
+ Overview from anywhere off it") as the hub function with no row and no
144
+ flag, which fails on 0.2.3 for `/comms/agent/abc` and
145
+ `/launcher?section=brandvoice`. It builds the state with `back: true`
146
+ instead:
147
+
148
+ ```ts
149
+ const back: OsFrameState = { fn: { id: "hub" }, item: null, tab: null, back: true };
150
+ expect(frame(everyone, { location: from }).targetFor(back, from), from)
151
+ .toEqual({ href: "/comms/overview", external: false });
152
+ ```
153
+
3
154
  ## 0.2.2 - 2026-09-30
4
155
 
5
156
  With `autosolutions-design-system` 6.3.3, whose frame fixes this release
package/README.md CHANGED
@@ -35,9 +35,20 @@ export function App() {
35
35
  the top bar with the company's mark and switcher, the rail, the OS menu (the 53
36
36
  tools of the menu map: the handoff's 49 plus Shelf simulator, Key accounts, PM
37
37
  Copilot and Candidate hub), the footer with Admin for people who manage something, and the
38
- browser-tab icon. It needs `autosolutions-design-system` 6.3.3 or later
39
- (an optional peer: only this entry point uses it). Take this package's 0.2.2
40
- and the design system's 6.3.3 together, in one commit.
38
+ browser-tab icon. It needs `autosolutions-design-system` 6.4.0 or later
39
+ (an optional peer: only this entry point uses it). Take this package's 0.2.4
40
+ and the design system's 6.4.0 together, in one commit: 0.2.4 sends a company
41
+ switch the app's new company does not hold to the Hub, reads os_context()
42
+ for the person signed in and asks again after a failure, and makes this
43
+ app's own rows and tabs links; 6.4.0 brings the final design and the frame's
44
+ own fixes (wide pages scroll sideways again, a phone's menu closes on every
45
+ pick, no search box without a search, and the rest in its CHANGELOG). An
46
+ app that renders `OsWorkspaceFrame` changes nothing else, but for the
47
+ options below (`hrefFor`, a navigation promise, `auth`). Code that calls `osFrame().targetFor`
48
+ itself in the Hub (a test of the Hub's rows, say) and means Back to hub passes
49
+ `back: true`: since 0.2.3 the hub function with no row and no flag is the
50
+ rail's Hub (see below). The Hub's adoption of 0.2.3 updates its one test that
51
+ does this (the CHANGELOG has the change).
41
52
 
42
53
  ```tsx
43
54
  import { OsWorkspaceFrame } from "autosolutions-os/frame";
@@ -62,8 +73,14 @@ import { OsWorkspaceFrame } from "autosolutions-os/frame";
62
73
 
63
74
  It works with any router: it reads `location` and calls `onNavigate(href)` for
64
75
  paths inside the app, and opens other apps itself, in the same tab. The rows
65
- for other apps are links (`<a href>` with `?tenant=`), so a middle-click, a
66
- Cmd or Ctrl click and Copy link work as the browser does them. Browser Back
76
+ for other apps are links (`<a href>` with `?tenant=`), and so are this app's
77
+ own rows and tabs (`href` is the path; `hrefFor` writes it another way, as
78
+ `(path) => "#" + path` for a hash router, or `null` keeps buttons for an app
79
+ whose places never reach the address bar), so a middle-click, a Cmd or Ctrl
80
+ click and Copy link work as the browser does them. Return the router's
81
+ navigation promise from `onNavigate` (as above) and a navigation the app
82
+ refuses (an unsaved-changes prompt the person stays on, which leaves the
83
+ address bar where it was) puts the frame back where the URL is. Browser Back
67
84
  moves the menus because the frame follows `location`, and it calls
68
85
  `onNavigate` only when someone clicks, so there is no loop. Back from another
69
86
  app out of the browser's back/forward cache puts the frame where the URL is,
@@ -101,33 +118,59 @@ why).
101
118
  (`staticLinks()`). Tools with no app follow the map: Pricing researcher and
102
119
  Brand voice copywriter read "Live, not linked from the Hub yet", anything
103
120
  not Live shows its status.
104
- - The company plate is `markFor(tenant, "plain")`. The chevron appears only for
121
+ - os_context() is read once per page and person: another person signing in
122
+ on the same browser, without a reload, reads their own (pass `auth`, the
123
+ app's `supabase.auth`, to have sign-ins followed live in this tab too). A
124
+ read that fails is asked again (1, 3, 10, 30 and 60 seconds on, when the
125
+ window comes back, and when the location changes), and until it answers
126
+ other apps' tools read "Checking your access…" and the plate's place is
127
+ kept, drawn as nothing.
128
+ - The company plate is `markFor(tenant, "plain")`. A company with no artwork
129
+ there (one outside the brand bucket's eight, with no stored logo), or whose
130
+ artwork fails to load, has its name on the plate instead (its whole name
131
+ in a tooltip), and its row in the company menu keeps the mark's slot,
132
+ empty. The chevron appears only for
105
133
  someone with more than one company, and then the plate and the chevron are
106
134
  one button that opens the company menu: a menu of the companies, the acting
107
135
  one checked, with arrow keys, and focus back on the button when it closes.
108
136
  `companySwitch` says what it does:
109
137
  - `"os"` (the default) switches exactly as `OsCompanySwitcher` does, since
110
138
  both use `useCompanySwitch(os, appKey)`: `switch_company_for_app`, then a
111
- reload or that company's deployment of this app.
139
+ reload or that company's deployment of this app, or the Hub when that
140
+ company does not hold the app (the core returns no `appUrl`).
112
141
  - `"none"` shows the acting company with no chevron, for an app whose
113
142
  company is fixed some other way (PM Copilot's assignment).
114
143
  - a function `(tenant) => Promise<void>` is the app's own in-place switch
115
144
  (e-sales: `switch_tenant`, invalidate, toast). The frame calls it, closes
116
- the menu and does not reload; when it resolves, `refreshOsContext(os)`
117
- brings the plate and the menu's links round to the new company. The
118
- function reports its own failures.
145
+ the menu and does not reload; when it resolves, the plate, the menu's
146
+ check and its links follow the new company at once, and
147
+ `refreshOsContext(os)` reads the core again (asking again if that fails).
148
+ The function reports its own failures.
119
149
  - `actions` go in the top bar before the plate (What's new, a notification
120
150
  bell). `panelFooter` renders in the panel under the open tool's tabs, in the
121
151
  panel's padding, scrolling with them (Create Studio's sessions).
122
152
  - Settings goes to `settingsPath` when the app has a settings page, and to the
123
153
  Hub's settings when it has none.
124
- - `initialOpen={false}` starts the menu closed on the first location (a narrow
125
- screen); after that the frame's own rule applies. `data-*` and `aria-*` props
126
- land on the frame's root.
154
+ - `search` is the top bar's field. It is drawn only when `search.onChange`
155
+ is given: an app with no search passes none and the bar has no box (a
156
+ placeholder alone draws none either).
157
+ - On a phone's screen (767px and below) the design system closes the menu on
158
+ every location and on every row or tab picked, so the page picked gets the
159
+ width, once the page is live (a server-rendered page shows it open until it
160
+ hydrates); a reselect still goes back to its own page. No prop is needed
161
+ for it. `initialOpen={false}` starts the menu closed on the first location,
162
+ which a phone no longer needs it for; after that the frame's own rule
163
+ applies. `data-*` and `aria-*` props land on the frame's root.
127
164
  - Admin appears when `my_admin_scope()` says the person manages something; pass
128
165
  `admin` to decide it yourself.
129
166
  - The Hub passes `hubItems`, its own rows. In any other app the rail's Hub, Back
130
- to hub and Admin go to the Hub.
167
+ to hub and Admin go to the Hub. In the Hub, the rail's Hub is its menu's
168
+ control: pressed after browsing another function's menu, it reopens the Hub
169
+ menu on the page the person is on (a thread, a tool, the Overview), with no
170
+ navigation. From another place (Admin, an app's Settings) it lands on the
171
+ Hub's landing, as Back to hub does from anywhere. `targetFor` tells the two
172
+ apart by the design system's `back` flag (6.3.4): the hub function with no
173
+ row is the rail's Hub, and with `back: true` it is Back to hub.
131
174
 
132
175
  ### Off the core
133
176
 
@@ -151,12 +194,13 @@ const frame = osFrame({ appKey: "ops_hub", tools, links: staticLinks() });
151
194
  const here = pathname + search;
152
195
 
153
196
  <WorkspaceFrame
154
- topBar={<TopBar searchPlaceholder="Search" companySrc={companyMarkUrl("frankbody", "plain")} />}
197
+ topBar={<TopBar searchPlaceholder="Search" searchValue={query} onSearchChange={setQuery} companySrc={companyMarkUrl("frankbody", "plain")} />}
155
198
  functions={frame.functions}
156
199
  sections={frame.sections}
157
200
  footerItems={frame.footerItems}
158
201
  location={{ ...frame.locate(here), href: here }}
159
202
  onNavigate={(state) => {
203
+ // The state whole: `reselect` and `back` (Back to hub) change where it goes.
160
204
  const target = frame.targetFor(state, here);
161
205
  if (!target) return false; // goes nowhere: the frame stays where `here` is
162
206
  if (target.external) window.location.assign(target.href);
package/dist/chrome.d.ts CHANGED
@@ -26,9 +26,12 @@ export declare function OsAppSwitcher({ os, appKey, variant, onOpen }: {
26
26
  *
27
27
  * `choose` runs `close` synchronously, and does nothing else, when there is
28
28
  * nothing to do: the company is already current or a switch is in flight.
29
+ * `status` says whether the context is still being read, read, or failed
30
+ * (and is being asked again).
29
31
  */
30
32
  export declare function useCompanySwitch(os: unknown, appKey: string): {
31
- context: import("./context.js").OsContext | null;
33
+ context: import("./contextCache.js").OsContext | null;
34
+ status: import("./contextCache.js").OsContextStatus;
32
35
  current: OsTenant | null;
33
36
  tenants: OsTenant[];
34
37
  busy: boolean;
package/dist/chrome.js CHANGED
@@ -12,7 +12,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
12
  */
13
13
  import { useEffect, useRef, useState } from "react";
14
14
  import { HUB_URL } from "./config.js";
15
- import { groupApps, invalidateOsContext, labelFor, markFor, useOsContext, withTenantHint, } from "./context.js";
15
+ import { companySwitchLanding } from "./url.js";
16
+ import { groupApps, invalidateOsContext, labelFor, markFor, useOsContext, useOsContextState, withTenantHint, } from "./context.js";
16
17
  function useDismiss(open, close, ref) {
17
18
  useEffect(() => {
18
19
  if (!open)
@@ -69,9 +70,11 @@ export function OsAppSwitcher({ os, appKey, variant = "menu", onOpen }) {
69
70
  *
70
71
  * `choose` runs `close` synchronously, and does nothing else, when there is
71
72
  * nothing to do: the company is already current or a switch is in flight.
73
+ * `status` says whether the context is still being read, read, or failed
74
+ * (and is being asked again).
72
75
  */
73
76
  export function useCompanySwitch(os, appKey) {
74
- const context = useOsContext(os);
77
+ const { context, status } = useOsContextState(os);
75
78
  const [busy, setBusy] = useState(false);
76
79
  const [error, setError] = useState(null);
77
80
  const current = context?.tenant ?? null;
@@ -97,24 +100,15 @@ export function useCompanySwitch(os, appKey) {
97
100
  }
98
101
  invalidateOsContext();
99
102
  const result = (data ?? {});
100
- if (appKey === "hub" || !result.appUrl) {
103
+ const destination = companySwitchLanding(appKey, result, window.location.origin);
104
+ if (destination === null)
101
105
  window.location.reload();
102
- return;
103
- }
104
- const destination = withTenantHint(result.appUrl, result.tenantSlug ?? null);
105
- try {
106
- if (new URL(destination).origin === window.location.origin) {
107
- window.location.reload();
108
- return;
109
- }
110
- }
111
- catch {
112
- /* malformed destination: fall through and let the browser report it */
113
- }
114
- window.location.assign(destination);
106
+ else
107
+ window.location.assign(destination);
115
108
  };
116
109
  return {
117
110
  context,
111
+ status,
118
112
  current,
119
113
  tenants: context?.tenants ?? [],
120
114
  busy,
package/dist/context.d.ts CHANGED
@@ -1,37 +1,10 @@
1
- export type OsTenant = {
2
- id: string;
3
- slug: string;
4
- name: string;
5
- logoUrl: string | null;
6
- logoPlainUrl: string | null;
7
- osRole?: string;
1
+ import { type OsApp, type OsContext, type OsContextStatus, type OsTenant } from "./contextCache.js";
2
+ export { loadOsContext, invalidateOsContext, refreshOsContext, retryOsContext, watchOsAuth, type OsApp, type OsContext, type OsContextStatus, type OsTenant, } from "./contextCache.js";
3
+ /** The context and where it stands, for a component that shows the difference. */
4
+ export declare function useOsContextState(os: unknown): {
5
+ context: OsContext | null;
6
+ status: OsContextStatus;
8
7
  };
9
- export type OsApp = {
10
- key: string;
11
- name: string;
12
- iconUrl: string | null;
13
- url: string | null;
14
- sortOrder: number;
15
- /** Switcher column, e.g. Marketing. Comes from the catalogue, not from code. */
16
- groupKey: string | null;
17
- /** Sub-heading inside the column; null means the untitled first block. */
18
- sectionKey: string | null;
19
- designKey: string | null;
20
- labelUrl: string | null;
21
- };
22
- export type OsContext = {
23
- tenant: OsTenant | null;
24
- tenants: OsTenant[];
25
- apps: OsApp[];
26
- };
27
- export declare function loadOsContext(os: unknown): Promise<OsContext | null>;
28
- /** Forget the cached answer, so the next read reflects a company switch. */
29
- export declare function invalidateOsContext(): void;
30
- /**
31
- * Ask again and hand the answer to every mounted reader: after a company
32
- * switch that does not reload the page. A failed call changes nothing.
33
- */
34
- export declare function refreshOsContext(os: unknown): Promise<OsContext | null>;
35
8
  export declare function useOsContext(os: unknown): OsContext | null;
36
9
  export declare function useTenant(os: unknown): OsTenant | null;
37
10
  export declare function useApps(os: unknown): OsApp[];
package/dist/context.js CHANGED
@@ -1,68 +1,41 @@
1
1
  /**
2
2
  * `os_context()` is the one call every app's chrome makes: who you are acting
3
3
  * as, which companies you can act as, and which apps you hold. One round trip,
4
- * cached for the page.
4
+ * cached for the page and for the person signed in (contextCache.ts).
5
5
  */
6
6
  import { useEffect, useState } from "react";
7
7
  import { appLabelUrl, companyMarkUrl } from "./config.js";
8
- /**
9
- * One fetch per page, but a FAILURE is never cached. A call that races a token
10
- * refresh would otherwise blank both switchers until a full reload.
11
- */
12
- let pending = null;
13
- export function loadOsContext(os) {
14
- if (!pending) {
15
- pending = Promise.resolve(os.rpc("os_context"))
16
- .then(({ data, error }) => {
17
- if (error || !data) {
18
- pending = null;
19
- return null;
20
- }
21
- return data;
22
- })
23
- .catch(() => {
24
- pending = null;
25
- return null;
26
- });
27
- }
28
- return pending;
29
- }
30
- /** Forget the cached answer, so the next read reflects a company switch. */
31
- export function invalidateOsContext() {
32
- pending = null;
33
- }
34
- /* Every mounted useOsContext, so an in-place switch reaches them all. */
35
- const readers = new Set();
36
- /**
37
- * Ask again and hand the answer to every mounted reader: after a company
38
- * switch that does not reload the page. A failed call changes nothing.
39
- */
40
- export async function refreshOsContext(os) {
41
- pending = null;
42
- const value = await loadOsContext(os);
43
- if (value)
44
- readers.forEach((read) => read(value));
45
- return value;
46
- }
47
- export function useOsContext(os) {
48
- const [context, setContext] = useState(null);
8
+ import { loadOsContext, scheduleOsContextRetry, subscribeOsContext, } from "./contextCache.js";
9
+ export { loadOsContext, invalidateOsContext, refreshOsContext, retryOsContext, watchOsAuth, } from "./contextCache.js";
10
+ /** The context and where it stands, for a component that shows the difference. */
11
+ export function useOsContextState(os) {
12
+ const [state, setState] = useState({ context: null, status: "loading" });
49
13
  useEffect(() => {
50
14
  let live = true;
51
- const read = (value) => {
15
+ const read = (context, status) => {
52
16
  if (live)
53
- setContext(value);
17
+ setState((was) => (was.context === context && was.status === status ? was : { context, status }));
54
18
  };
55
- readers.add(read);
19
+ const unsubscribe = subscribeOsContext(read);
56
20
  void loadOsContext(os).then((value) => {
57
- if (live)
58
- setContext(value);
21
+ if (!live)
22
+ return;
23
+ if (value) {
24
+ read(value, "ready");
25
+ return;
26
+ }
27
+ read(null, "failed");
28
+ scheduleOsContextRetry(os);
59
29
  });
60
30
  return () => {
61
31
  live = false;
62
- readers.delete(read);
32
+ unsubscribe();
63
33
  };
64
34
  }, [os]);
65
- return context;
35
+ return state;
36
+ }
37
+ export function useOsContext(os) {
38
+ return useOsContextState(os).context;
66
39
  }
67
40
  export function useTenant(os) {
68
41
  return useOsContext(os)?.tenant ?? null;
@@ -0,0 +1,50 @@
1
+ export type OsTenant = {
2
+ id: string;
3
+ slug: string;
4
+ name: string;
5
+ logoUrl: string | null;
6
+ logoPlainUrl: string | null;
7
+ osRole?: string;
8
+ };
9
+ export type OsApp = {
10
+ key: string;
11
+ name: string;
12
+ iconUrl: string | null;
13
+ url: string | null;
14
+ sortOrder: number;
15
+ /** Switcher column, e.g. Marketing. Comes from the catalogue, not from code. */
16
+ groupKey: string | null;
17
+ /** Sub-heading inside the column; null means the untitled first block. */
18
+ sectionKey: string | null;
19
+ designKey: string | null;
20
+ labelUrl: string | null;
21
+ };
22
+ export type OsContext = {
23
+ tenant: OsTenant | null;
24
+ tenants: OsTenant[];
25
+ apps: OsApp[];
26
+ };
27
+ /**
28
+ * Where a reader's context stands: still being read, read, or failed (and
29
+ * being asked again).
30
+ */
31
+ export type OsContextStatus = "loading" | "ready" | "failed";
32
+ export declare function loadOsContext(os: unknown): Promise<OsContext | null>;
33
+ /** Forget the cached answer, so the next read reflects a company switch. */
34
+ export declare function invalidateOsContext(): void;
35
+ /** Hear every new answer (and a change of person) until the returned function is called. */
36
+ export declare function subscribeOsContext(read: (context: OsContext | null, status: OsContextStatus) => void): () => void;
37
+ /**
38
+ * Ask again and hand the answer to every mounted reader: after a company
39
+ * switch that does not reload the page. A failed call changes nothing.
40
+ */
41
+ export declare function refreshOsContext(os: unknown): Promise<OsContext | null>;
42
+ /** After a failed read: ask again on a timer (1, 3, 10, 30, 60 seconds). */
43
+ export declare function scheduleOsContextRetry(os: unknown): void;
44
+ /**
45
+ * Ask again now if the last read failed (the frame calls it when the app's
46
+ * location changes); otherwise the cached answer. Every mounted reader gets a
47
+ * new answer.
48
+ */
49
+ export declare function retryOsContext(os: unknown): Promise<OsContext | null>;
50
+ export declare function watchOsAuth(auth: unknown): void;