autosolutions-os 0.1.0 → 0.2.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/CHANGELOG.md ADDED
@@ -0,0 +1,104 @@
1
+ # Changelog
2
+
3
+ ## 0.2.1 - 2026-09-29
4
+
5
+ A fix, with `autosolutions-design-system` 6.3.2. A click on the tab or row
6
+ the frame already shows goes to that tab's or row's own page from a page
7
+ filed under it. In Key Accounts a draft (`/drafts/$id`) files under the
8
+ Requests tab (`match: ["/drafts"]`); on a draft, clicking Requests (or
9
+ stepping out to Commercial and clicking Key accounts again) now goes to `/`,
10
+ as the old sidebar link did, where 0.2.0 stayed on the draft. In the Hub,
11
+ Unmarked Agent on an Agent thread goes to `/comms/agent`.
12
+
13
+ - `osFrame().targetFor` reads the design system's `reselect` flag
14
+ (`OsFrameState.reselect`). A reselected tab or row goes to its own `path`
15
+ unless the URL is exactly that path (the same pathname and the same
16
+ query), and nowhere when it is, so a click on the page you are on adds no
17
+ history entry. Settings, and Admin in the Hub, go back to their page from
18
+ a page under them.
19
+ - A reselect goes to the tab's own path and drops the page's query. Exactly
20
+ includes the query, so on `/analytics?range=90` Analytics goes to
21
+ `/analytics`, as the old sidebar links did. Tell app owners: a page that
22
+ keeps its filters or sort in the query starts again from its defaults
23
+ after that click.
24
+ - As before: a tab with no `path` (page state) goes nowhere; a row that
25
+ carries its own tab row in the page (`menu: false`, the Hub's Smart Comms)
26
+ stays on any view of its own; links to other apps open as they did;
27
+ opening a function's menu is not a navigation.
28
+ - A locked row goes nowhere from `targetFor`, whatever state it is handed.
29
+ The frame never reports a click on one, but a locked Hub row keeps its
30
+ `path` for its hint, and `targetFor` used to return it.
31
+ - `OsWorkspaceFrame` passes the flag through, and so does an app off the
32
+ core that hands `targetFor` the frame's state whole (Key Accounts does).
33
+ Apps change nothing but the two versions.
34
+ - The design-system peer range stays `>=6.3.0 <7`. With 6.3.0 or 6.3.1 the
35
+ flag never comes and this release behaves exactly as 0.2.0: the consumer
36
+ check on design system 6.3.1 passes every test but the new reselect ones.
37
+ Raising it to `>=6.3.2` would not stop the pairing that goes wrong, which
38
+ is design system 6.3.2 with os 0.2.0 (0.2.0's own range allows it).
39
+
40
+ **Take both together.** Design system 6.3.2 with os 0.2.0 is the one pairing
41
+ that misbehaves: 6.3.2 reports the click on the selected tab and 0.2.0's
42
+ `targetFor` does not know the flag, so where a tab's path is also its tool's
43
+ (Key Accounts' Requests at `/`), that click on the page you are on pushes a
44
+ second history entry for it. 0.2.0's peer range and the apps' caret ranges
45
+ allow that pairing, so the release order has to prevent it: publish os
46
+ 0.2.1 no later than design system 6.3.2, and have each app bump both
47
+ packages in one commit (Key Accounts, e-sales and the Hub pin `^6.3.1` and
48
+ `^0.2.0` with lockfiles).
49
+
50
+ ## 0.2.0 - 2026-09-28
51
+
52
+ The OS menu and the workspace frame. Needs `autosolutions-design-system` 6.3
53
+ for `autosolutions-os/frame` (an optional peer: nothing else uses it).
54
+
55
+ New:
56
+
57
+ - `autosolutions-os/frame`: `OsWorkspaceFrame`, the design system's
58
+ `WorkspaceFrame` wired to the core. The same rail, menu and footer in every
59
+ app, this app's own tools live, the company's plate and switcher on the top
60
+ bar, Admin for people who manage something. It works with any router: it
61
+ reads `location` and calls `onNavigate(href)`. It follows the URL: to every
62
+ new place (Back included), and back from a click that took it elsewhere
63
+ when the URL moves on, so nothing clicked outlives the URL; a query the
64
+ page writes for itself leaves the person's own choices (a page-state tab, a
65
+ closed menu) alone.
66
+ - `companySwitch`: `"os"` (the default: `switch_company_for_app`, then a
67
+ reload), `"none"` (the plate with no chevron) or the app's own in-place
68
+ switch, after which `refreshOsContext(os)` brings the plate and the links
69
+ round to the new company.
70
+ - `actions`, `panelFooter`, `initialOpen` (the first location's menu, for a
71
+ narrow screen), and `data-*` / `aria-*` on the frame's root.
72
+ - Tools and tabs take `badge`; tabs may be titled groups.
73
+ - `autosolutions-os/nav`, plain data and functions: the rail
74
+ (`OS_FUNCTIONS`), the menu map (`OS_MENU`: the handoff's 49 tools plus Shelf
75
+ simulator, Key accounts, PM Copilot and Candidate hub, 53 in all, 21 Live),
76
+ `OS_TOOL_LINKS`, `HUB_URL`, `HUB_PATHS`, `HINTS`, `osFooter()`,
77
+ `staticLinks()`, `catalogueLinks()` and `osFrame()`, the routing rules the
78
+ frame runs on. An app off the core pairs it with `WorkspaceFrame`.
79
+ - `refreshOsContext(os)`: read `os_context()` again and hand the answer to
80
+ every mounted reader. `useCompanySwitch(os, appKey)`: the switch the
81
+ company menus share.
82
+
83
+ Where a tool goes:
84
+
85
+ - `OS_TOOL_LINKS` maps each tool to its catalogue app, so the menu reaches
86
+ every app the app switcher offers (all but the Hub, which is the rail's
87
+ Hub). In a frame backed by the catalogue, a tool whose app the person holds
88
+ links to it, with `?tenant=`, in the same tab, whatever status the map gives
89
+ the tool. A Live tool whose app is held but not deployed reads "Live, not
90
+ linked from the Hub yet", and one whose app is not held is locked ("Ask
91
+ your company admin to switch this on for you"); a tool the map does not mark
92
+ Live keeps its status in both cases.
93
+ - A tool's fixed `url` serves `staticLinks()` only, for frames off the core
94
+ with no catalogue to ask. It is never a way round the catalogue.
95
+
96
+ Fixed:
97
+
98
+ - The package loads in Node, not only in a bundler: every relative import
99
+ names its `.js` file. 0.1.0 did not, so `vite dev` SSR and test runners
100
+ failed with `ERR_MODULE_NOT_FOUND .../dist/config`.
101
+ `scripts/check-os-consumer.sh` installs the packed tarball and loads it in
102
+ Node, vitest, Vite SSR and a DOM.
103
+ - Under Vite SSR, list both packages in `ssr.noExternal`: the frame imports
104
+ the design system, whose components ship as JSX source.
package/README.md CHANGED
@@ -29,8 +29,143 @@ export function App() {
29
29
  `supabase` is bound to your schema, so `.from("your_table")` works unchanged.
30
30
  `os` is the same connection bound to `public`, for the platform's own functions.
31
31
 
32
+ ## The workspace frame
33
+
34
+ `OsWorkspaceFrame` is the frame every app on the core renders around its pages:
35
+ the top bar with the company's mark and switcher, the rail, the OS menu (the 53
36
+ tools of the menu map: the handoff's 49 plus Shelf simulator, Key accounts, PM
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 or later
39
+ (an optional peer: only this entry point uses it).
40
+
41
+ ```tsx
42
+ import { OsWorkspaceFrame } from "autosolutions-os/frame";
43
+
44
+ <OsWorkspaceFrame
45
+ os={os}
46
+ appKey="ops_hub"
47
+ tools={[
48
+ { id: "inventory-health", path: "/inventory", tabs: [
49
+ { id: "summary", label: "Summary", icon: "ops-inventory-health", path: "/inventory/summary" },
50
+ ] },
51
+ { id: "out-of-stocks", path: "/oos" },
52
+ ]}
53
+ location={pathname + search}
54
+ onNavigate={(href) => navigate({ to: href })}
55
+ search={{ placeholder: "Search", value: query, onChange: setQuery }}
56
+ onSignOut={signOut}
57
+ >
58
+ <Outlet />
59
+ </OsWorkspaceFrame>
60
+ ```
61
+
62
+ It works with any router: it reads `location` and calls `onNavigate(href)` for
63
+ paths inside the app, and opens other apps itself, in the same tab. Browser
64
+ Back moves the menus because the frame follows `location`, and it calls
65
+ `onNavigate` only when someone clicks, so there is no loop. A click on the tab
66
+ or row the frame already shows goes to that tab's or row's own path from a
67
+ page under it (a draft filed under Requests goes back to Requests), and
68
+ nowhere when the URL is exactly that path. It goes to the tab's own path and
69
+ drops the page's query: on `/analytics?range=90`, Analytics goes to
70
+ `/analytics`, as the old sidebar links did, so a page that keeps its filters in
71
+ the query starts again from its defaults. Design system 6.3.2 is what reports
72
+ that click: take it together with this package's 0.2.1 (the CHANGELOG says
73
+ why).
74
+
75
+ - `tools` are this app's own rows, by menu-map id, with their routes. They are
76
+ live whatever the map says. A row the map does not have takes `fn`, `section`,
77
+ `label` and `icon`. A row can carry a `badge` (a count), and so can a tab.
78
+ - `tabs` is a flat list, or titled groups (`{ title, items }[]`) drawn with the
79
+ menu's own section headings. A tab with a `path` navigates; one without is
80
+ page state, read from the frame's state (`children` as a function).
81
+ - Every other tool opens its app in the same tab, and only if the person holds
82
+ that app: the menu reaches every app the app switcher offers (all but the
83
+ Hub itself, which is the rail's Hub). `OS_TOOL_LINKS` names each tool's app,
84
+ and `os_context()` decides:
85
+ - held, with an address: the tool goes there (plus its `path`) with
86
+ `?tenant=`, whatever status the map gives it (Influencer Manager is In
87
+ progress in the map, Marketing calendar and Paid media have none, yet a
88
+ company that holds their apps reaches them);
89
+ - held, not deployed yet: a Live tool reads "Live, not linked from the Hub
90
+ yet", any other keeps its status;
91
+ - not held: a Live tool is locked ("Ask your company admin to switch this on
92
+ for you"); any other keeps its status (Not built yet, In progress, To
93
+ build).
94
+ A tool's fixed `url` is never used here; it is for frames off the core
95
+ (`staticLinks()`). Tools with no app follow the map: Pricing researcher and
96
+ Brand voice copywriter read "Live, not linked from the Hub yet", anything
97
+ not Live shows its status.
98
+ - The company plate is `markFor(tenant, "plain")`. The chevron appears only for
99
+ someone with more than one company. `companySwitch` says what it does:
100
+ - `"os"` (the default) switches exactly as `OsCompanySwitcher` does, since
101
+ both use `useCompanySwitch(os, appKey)`: `switch_company_for_app`, then a
102
+ reload or that company's deployment of this app.
103
+ - `"none"` shows the acting company with no chevron, for an app whose
104
+ company is fixed some other way (PM Copilot's assignment).
105
+ - a function `(tenant) => Promise<void>` is the app's own in-place switch
106
+ (e-sales: `switch_tenant`, invalidate, toast). The frame calls it, closes
107
+ the menu and does not reload; when it resolves, `refreshOsContext(os)`
108
+ brings the plate and the menu's links round to the new company. The
109
+ function reports its own failures.
110
+ - `actions` go in the top bar before the plate (What's new, a notification
111
+ bell). `panelFooter` renders in the panel under the open tool's tabs, in the
112
+ panel's padding, scrolling with them (Create Studio's sessions).
113
+ - Settings goes to `settingsPath` when the app has a settings page, and to the
114
+ Hub's settings when it has none.
115
+ - `initialOpen={false}` starts the menu closed on the first location (a narrow
116
+ screen); after that the frame's own rule applies. `data-*` and `aria-*` props
117
+ land on the frame's root.
118
+ - Admin appears when `my_admin_scope()` says the person manages something; pass
119
+ `admin` to decide it yourself.
120
+ - The Hub passes `hubItems`, its own rows. In any other app the rail's Hub, Back
121
+ to hub and Admin go to the Hub.
122
+
123
+ ### Off the core
124
+
125
+ `autosolutions-os/nav` is plain data and functions, with no React and no
126
+ Supabase: the rail (`OS_FUNCTIONS`), the menu map (`OS_MENU`), `OS_TOOL_LINKS`,
127
+ `HUB_URL`, `HUB_PATHS`, `HINTS`, `osFooter()`, `staticLinks()` and
128
+ `osFrame()`, the routing rules the frame runs on. An app on its own project
129
+ (Ops Hub: see "Linked, not federated" in `docs/CONTRACT.md`) pairs it with the
130
+ design system's `WorkspaceFrame`, a static plate and no switcher. `staticLinks()`
131
+ are the fixed addresses (Ops Hub's tools, Label Maker, CRM, Key accounts, PM
132
+ Copilot), with no tenant hint; with no catalogue to ask, they are all live, and
133
+ each app's own sign-in decides. If the app's CSS is a fork of the design
134
+ system, import `autosolutions-design-system/frame.css` instead of `styles.css`
135
+ (see the design system's README).
136
+
137
+ ```tsx
138
+ import { WorkspaceFrame, TopBar, companyMarkUrl } from "autosolutions-design-system";
139
+ import { osFrame, staticLinks } from "autosolutions-os/nav";
140
+
141
+ const frame = osFrame({ appKey: "ops_hub", tools, links: staticLinks() });
142
+ const here = pathname + search;
143
+
144
+ <WorkspaceFrame
145
+ topBar={<TopBar searchPlaceholder="Search" companySrc={companyMarkUrl("frankbody", "plain")} />}
146
+ functions={frame.functions}
147
+ sections={frame.sections}
148
+ footerItems={frame.footerItems}
149
+ location={{ ...frame.locate(here), href: here }}
150
+ onNavigate={(state) => {
151
+ const target = frame.targetFor(state, here);
152
+ if (target?.external) window.location.assign(target.href);
153
+ else if (target) navigate(target.href);
154
+ }}
155
+ onSignOut={signOut}
156
+ >
157
+ {page}
158
+ </WorkspaceFrame>
159
+ ```
160
+
32
161
  ## On the server
33
162
 
163
+ The package is plain ES modules, so Node, a test runner and a dev server's SSR
164
+ load it as it is (`scripts/check-os-consumer.sh` proves it from the packed
165
+ tarball). The frame is the exception: it imports the design system, whose
166
+ components ship as JSX source, so a Vite SSR app compiles both in dev:
167
+ `ssr: { noExternal: ["autosolutions-design-system", "autosolutions-os"] }`.
168
+
34
169
  ```ts
35
170
  import { authenticate, tokenFromRequest } from "autosolutions-os/server";
36
171
 
package/dist/chrome.d.ts CHANGED
@@ -10,6 +10,7 @@
10
10
  * disclosure chevron, transparent at rest, never a plate behind it.
11
11
  */
12
12
  import { type ReactNode } from "react";
13
+ import { type OsTenant } from "./context.js";
13
14
  /** The app grid. `variant="menu"` is one column for a popover; `grid` is wide. */
14
15
  export declare function OsAppSwitcher({ os, appKey, variant, onOpen }: {
15
16
  os: unknown;
@@ -17,6 +18,23 @@ export declare function OsAppSwitcher({ os, appKey, variant, onOpen }: {
17
18
  variant?: "grid" | "menu";
18
19
  onOpen?: () => void;
19
20
  }): import("react").JSX.Element;
21
+ /**
22
+ * Switching company, shared by every company menu (OsCompanySwitcher, and the
23
+ * workspace frame's plate). It changes the acting company server-side and then
24
+ * lands on that company's deployment of this app, a different front end when
25
+ * the company runs its own, or the hub when it does not hold this app.
26
+ *
27
+ * `choose` runs `close` synchronously, and does nothing else, when there is
28
+ * nothing to do: the company is already current or a switch is in flight.
29
+ */
30
+ export declare function useCompanySwitch(os: unknown, appKey: string): {
31
+ context: import("./context.js").OsContext | null;
32
+ current: OsTenant | null;
33
+ tenants: OsTenant[];
34
+ busy: boolean;
35
+ error: string | null;
36
+ choose: (tenantId: string, close?: () => void) => Promise<void>;
37
+ };
20
38
  /**
21
39
  * The company switcher. Switching changes the acting company server-side and
22
40
  * then lands on that company's deployment of this app, a different front end
package/dist/chrome.js CHANGED
@@ -11,8 +11,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
11
  * disclosure chevron, transparent at rest, never a plate behind it.
12
12
  */
13
13
  import { useEffect, useRef, useState } from "react";
14
- import { HUB_URL } from "./config";
15
- import { groupApps, invalidateOsContext, labelFor, markFor, useOsContext, withTenantHint, } from "./context";
14
+ import { HUB_URL } from "./config.js";
15
+ import { groupApps, invalidateOsContext, labelFor, markFor, useOsContext, withTenantHint, } from "./context.js";
16
16
  function useDismiss(open, close, ref) {
17
17
  useEffect(() => {
18
18
  if (!open)
@@ -62,24 +62,24 @@ export function OsAppSwitcher({ os, appKey, variant = "menu", onOpen }) {
62
62
  }, tenantSlug: tenantSlug, current: appKey === "hub", onOpen: onOpen })] })] }));
63
63
  }
64
64
  /**
65
- * The company switcher. Switching changes the acting company server-side and
66
- * then lands on that company's deployment of this app, a different front end
67
- * when the company runs its own, or the hub when it does not hold this app.
65
+ * Switching company, shared by every company menu (OsCompanySwitcher, and the
66
+ * workspace frame's plate). It changes the acting company server-side and then
67
+ * lands on that company's deployment of this app, a different front end when
68
+ * the company runs its own, or the hub when it does not hold this app.
69
+ *
70
+ * `choose` runs `close` synchronously, and does nothing else, when there is
71
+ * nothing to do: the company is already current or a switch is in flight.
68
72
  */
69
- export function OsCompanySwitcher({ os, appKey }) {
73
+ export function useCompanySwitch(os, appKey) {
70
74
  const context = useOsContext(os);
71
- const [open, setOpen] = useState(false);
72
75
  const [busy, setBusy] = useState(false);
73
76
  const [error, setError] = useState(null);
74
- const root = useRef(null);
75
- useDismiss(open, () => setOpen(false), root);
76
- if (!context?.tenant)
77
- return null;
78
- const current = context.tenant;
79
- const single = context.tenants.length <= 1;
80
- const choose = async (tenantId) => {
77
+ const current = context?.tenant ?? null;
78
+ const choose = async (tenantId, close) => {
79
+ if (!current)
80
+ return;
81
81
  if (busy || tenantId === current.id) {
82
- setOpen(false);
82
+ close?.();
83
83
  return;
84
84
  }
85
85
  setBusy(true);
@@ -113,6 +113,30 @@ export function OsCompanySwitcher({ os, appKey }) {
113
113
  }
114
114
  window.location.assign(destination);
115
115
  };
116
+ return {
117
+ context,
118
+ current,
119
+ tenants: context?.tenants ?? [],
120
+ busy,
121
+ error,
122
+ choose,
123
+ };
124
+ }
125
+ /**
126
+ * The company switcher. Switching changes the acting company server-side and
127
+ * then lands on that company's deployment of this app, a different front end
128
+ * when the company runs its own, or the hub when it does not hold this app.
129
+ */
130
+ export function OsCompanySwitcher({ os, appKey }) {
131
+ const { context, busy, error, choose: switchTo } = useCompanySwitch(os, appKey);
132
+ const [open, setOpen] = useState(false);
133
+ const root = useRef(null);
134
+ useDismiss(open, () => setOpen(false), root);
135
+ if (!context?.tenant)
136
+ return null;
137
+ const current = context.tenant;
138
+ const single = context.tenants.length <= 1;
139
+ const choose = (tenantId) => switchTo(tenantId, () => setOpen(false));
116
140
  return (_jsxs("div", { className: "os-root", ref: root, children: [_jsxs("button", { type: "button", className: "os-company" + (single ? " is-static" : ""), onClick: () => !single && setOpen(!open), "aria-haspopup": !single, "aria-expanded": open, "aria-label": `Company: ${current.name}${single ? "" : ". Switch company"}`, children: [_jsx("img", { className: "os-company__mark", src: markFor(current), alt: current.name, title: current.name, onError: (event) => {
117
141
  event.target.outerHTML =
118
142
  `<span class="os-company__name">${current.name}</span>`;
package/dist/client.js CHANGED
@@ -6,8 +6,8 @@
6
6
  * `public`, for the platform's own tables and functions.
7
7
  */
8
8
  import { createClient } from "@supabase/supabase-js";
9
- import { coreProjectRef, corePublishableKey, coreUrl } from "./config";
10
- import { adoptSharedSession, publishSessionChanges } from "./session";
9
+ import { coreProjectRef, corePublishableKey, coreUrl } from "./config.js";
10
+ import { adoptSharedSession, publishSessionChanges } from "./session.js";
11
11
  let cached;
12
12
  export function createOsClient(options) {
13
13
  // One client per page. A second would keep its own session state and the two
package/dist/context.d.ts CHANGED
@@ -27,6 +27,11 @@ export type OsContext = {
27
27
  export declare function loadOsContext(os: unknown): Promise<OsContext | null>;
28
28
  /** Forget the cached answer, so the next read reflects a company switch. */
29
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>;
30
35
  export declare function useOsContext(os: unknown): OsContext | null;
31
36
  export declare function useTenant(os: unknown): OsTenant | null;
32
37
  export declare function useApps(os: unknown): OsApp[];
@@ -42,8 +47,5 @@ export declare function groupApps(apps: OsApp[]): Array<{
42
47
  apps: OsApp[];
43
48
  }>;
44
49
  }>;
45
- /**
46
- * Apps show the acting company's branding, so a link carries it as a hint.
47
- * Access is still decided by the core; this only saves a round trip.
48
- */
49
- export declare function withTenantHint(url: string, slug: string | null): string;
50
+ /** Re-exported from ./url, where `autosolutions-os/nav` can reach it without React. */
51
+ export { withTenantHint } from "./url.js";
package/dist/context.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * cached for the page.
5
5
  */
6
6
  import { useEffect, useState } from "react";
7
- import { appLabelUrl, companyMarkUrl } from "./config";
7
+ import { appLabelUrl, companyMarkUrl } from "./config.js";
8
8
  /**
9
9
  * One fetch per page, but a FAILURE is never cached. A call that races a token
10
10
  * refresh would otherwise blank both switchers until a full reload.
@@ -31,16 +31,35 @@ export function loadOsContext(os) {
31
31
  export function invalidateOsContext() {
32
32
  pending = null;
33
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
+ }
34
47
  export function useOsContext(os) {
35
48
  const [context, setContext] = useState(null);
36
49
  useEffect(() => {
37
50
  let live = true;
51
+ const read = (value) => {
52
+ if (live)
53
+ setContext(value);
54
+ };
55
+ readers.add(read);
38
56
  void loadOsContext(os).then((value) => {
39
57
  if (live)
40
58
  setContext(value);
41
59
  });
42
60
  return () => {
43
61
  live = false;
62
+ readers.delete(read);
44
63
  };
45
64
  }, [os]);
46
65
  return context;
@@ -80,19 +99,5 @@ export function groupApps(apps) {
80
99
  sections: [...sections.entries()].map(([title, list]) => ({ title: title || null, apps: list })),
81
100
  }));
82
101
  }
83
- /**
84
- * Apps show the acting company's branding, so a link carries it as a hint.
85
- * Access is still decided by the core; this only saves a round trip.
86
- */
87
- export function withTenantHint(url, slug) {
88
- if (!slug)
89
- return url;
90
- try {
91
- const parsed = new URL(url);
92
- parsed.searchParams.set("tenant", slug);
93
- return parsed.toString();
94
- }
95
- catch {
96
- return url;
97
- }
98
- }
102
+ /** Re-exported from ./url, where `autosolutions-os/nav` can reach it without React. */
103
+ export { withTenantHint } from "./url.js";
@@ -0,0 +1,83 @@
1
+ /**
2
+ * OsWorkspaceFrame: the design system's WorkspaceFrame, wired to the core.
3
+ *
4
+ * Every app on the core renders this around its pages. It draws the same rail,
5
+ * the same 53-tool menu and the same footer in every app, marks this app's own
6
+ * tools live, links the others through the catalogue, and puts the acting
7
+ * company's mark on the top bar's plate with the switcher behind its chevron.
8
+ *
9
+ * It knows nothing about routers. Hand it the current location (pathname plus
10
+ * query) and an `onNavigate(href)` that pushes an in-app path; links to other
11
+ * apps it opens itself, in the same tab. Browser Back and Forward move the
12
+ * menus because the frame follows `location`, and it only calls `onNavigate`
13
+ * when someone clicks. A click on the tab or row it already shows, from a page
14
+ * filed under it (a draft under Requests), goes to that tab's own page.
15
+ */
16
+ import { type ReactNode } from "react";
17
+ import type { WorkspaceState } from "autosolutions-design-system";
18
+ import { type OsTenant } from "./context.js";
19
+ import { type OsAppTool, type OsHubSection } from "./nav.js";
20
+ /**
21
+ * How the plate's chevron switches company.
22
+ * - "os" (default): switch_company_for_app, then reload or land on that
23
+ * company's deployment of this app, like OsCompanySwitcher.
24
+ * - "none": the plate shows the acting company with no chevron, for an app
25
+ * whose company is fixed some other way (an assignment, say).
26
+ * - a function: the app's own in-place switch. The frame calls it with the
27
+ * chosen company, closes the menu and does not reload; when it resolves,
28
+ * the plate and the menu links follow the new company. The function reports
29
+ * its own failures (a toast); a rejection only leaves the plate as it was.
30
+ */
31
+ export type OsCompanySwitch = "os" | "none" | ((tenant: OsTenant) => Promise<void>);
32
+ export type OsWorkspaceFrameProps = {
33
+ /** The client's `os` (public schema) connection. */
34
+ os: unknown;
35
+ /** Used for Sign out when `onSignOut` is not given: signs out, then reloads. */
36
+ auth?: {
37
+ signOut: () => Promise<unknown>;
38
+ };
39
+ /** This app's catalogue key; "hub" for the Hub. */
40
+ appKey: string;
41
+ /** This app's own tools, with their routes: these rows are live whatever the map says. */
42
+ tools?: OsAppTool[];
43
+ /** The Hub function's menu. The Hub passes its own rows; other apps leave it out and the rail's Hub goes to the Hub. */
44
+ hubItems?: OsHubSection[];
45
+ /** Where the app is: pathname plus query. */
46
+ location: string;
47
+ /** Push an in-app path. Links to other apps are opened by the frame. */
48
+ onNavigate: (href: string) => void;
49
+ search?: {
50
+ placeholder?: string;
51
+ value?: string;
52
+ onChange?: (value: string) => void;
53
+ };
54
+ /** Extra controls in the top bar, before the company plate (What's new, a notification bell). */
55
+ actions?: ReactNode;
56
+ /** How the plate switches company. Default "os". */
57
+ companySwitch?: OsCompanySwitch;
58
+ /** Rendered in the panel under the open tool's tabs, in the panel's padding (a session list, say). */
59
+ panelFooter?: ReactNode;
60
+ /** Sign out, in whatever order the app needs (clear caches first, and so on). */
61
+ onSignOut?: () => void;
62
+ /** This app's settings route. Default: the Hub's settings. */
63
+ settingsPath?: string;
64
+ /** This app's landing. In the Hub it is where Back to hub lands. */
65
+ homePath?: string;
66
+ /** Show Admin in the footer. Default: asked of the core with my_admin_scope(). */
67
+ admin?: boolean;
68
+ /** Set the browser-tab icon from the current menu glyph. Default true. */
69
+ favicon?: boolean;
70
+ /**
71
+ * Whether the menu starts open, for the first location only (false on a
72
+ * narrow screen, say). After that the frame's own rule applies: open on a
73
+ * function with a menu. Default: that rule from the start.
74
+ */
75
+ initialOpen?: boolean;
76
+ className?: string;
77
+ children?: ReactNode | ((state: WorkspaceState) => ReactNode);
78
+ } & {
79
+ [key: `data-${string}`]: string | number | boolean | undefined;
80
+ } & {
81
+ [key: `aria-${string}`]: string | number | boolean | undefined;
82
+ };
83
+ 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;
package/dist/frame.js ADDED
@@ -0,0 +1,105 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * OsWorkspaceFrame: the design system's WorkspaceFrame, wired to the core.
4
+ *
5
+ * Every app on the core renders this around its pages. It draws the same rail,
6
+ * the same 53-tool menu and the same footer in every app, marks this app's own
7
+ * tools live, links the others through the catalogue, and puts the acting
8
+ * company's mark on the top bar's plate with the switcher behind its chevron.
9
+ *
10
+ * It knows nothing about routers. Hand it the current location (pathname plus
11
+ * query) and an `onNavigate(href)` that pushes an in-app path; links to other
12
+ * apps it opens itself, in the same tab. Browser Back and Forward move the
13
+ * menus because the frame follows `location`, and it only calls `onNavigate`
14
+ * when someone clicks. A click on the tab or row it already shows, from a page
15
+ * filed under it (a draft under Requests), goes to that tab's own page.
16
+ */
17
+ import { useEffect, useMemo, useState } from "react";
18
+ import { ActionList, TopBar, WorkspaceFrame } from "autosolutions-design-system";
19
+ import { useCompanySwitch } from "./chrome.js";
20
+ import { markFor, refreshOsContext } from "./context.js";
21
+ import { myAdminScope } from "./identity.js";
22
+ import { catalogueLinks, osFrame } from "./nav.js";
23
+ 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 }) {
24
+ /* Only data-* and aria-* reach the frame's root. */
25
+ const attributes = Object.fromEntries(Object.entries(rest).filter(([key]) => /^(data|aria)-/.test(key)));
26
+ const { context, current, tenants, busy: switching, error, choose } = useCompanySwitch(os, appKey);
27
+ const [menuOpen, setMenuOpen] = useState(false);
28
+ const [ownBusy, setOwnBusy] = useState(false);
29
+ const busy = switching || ownBusy;
30
+ /* The core decides who manages something; the footer only reflects it. */
31
+ const [manages, setManages] = useState(false);
32
+ useEffect(() => {
33
+ if (admin !== undefined)
34
+ return undefined;
35
+ let live = true;
36
+ myAdminScope(os)
37
+ .then((scope) => {
38
+ if (live)
39
+ setManages(scope.isPlatformAdmin || scope.managesTenants.length > 0);
40
+ })
41
+ .catch(() => {
42
+ /* No Admin row is the safe failure; the admin console checks again anyway. */
43
+ });
44
+ return () => {
45
+ live = false;
46
+ };
47
+ }, [os, admin]);
48
+ const apps = context?.apps;
49
+ const slug = current?.slug ?? null;
50
+ const frame = useMemo(() => {
51
+ /* Only the catalogue says what this person holds. Until it arrives
52
+ nothing is linked and nothing is "not held": other apps' tools read as
53
+ not linked, never as a fixed address the person may not hold. */
54
+ const { links, locked } = apps ? catalogueLinks(apps, slug) : { links: {}, locked: {} };
55
+ return osFrame({
56
+ appKey, links, locked, admin: admin ?? manages, tenantSlug: slug,
57
+ ...(tools ? { tools } : {}),
58
+ ...(hubItems ? { hubItems } : {}),
59
+ ...(settingsPath ? { settingsPath } : {}),
60
+ ...(homePath ? { homePath } : {}),
61
+ });
62
+ }, [appKey, apps, admin, manages, slug, tools, hubItems, settingsPath, homePath]);
63
+ const navigate = (state) => {
64
+ const target = frame.targetFor(state, location);
65
+ if (!target)
66
+ return;
67
+ if (target.external)
68
+ window.location.assign(target.href);
69
+ else
70
+ onNavigate(target.href);
71
+ };
72
+ const signOut = onSignOut ?? (() => {
73
+ void auth?.signOut().then(() => window.location.reload());
74
+ });
75
+ /* The company menu, offered only when there is somewhere to switch to. */
76
+ const pick = (tenant) => {
77
+ if (typeof companySwitch !== "function") {
78
+ void choose(tenant.id, () => setMenuOpen(false));
79
+ return;
80
+ }
81
+ setMenuOpen(false);
82
+ if (!current || busy || tenant.id === current.id)
83
+ return;
84
+ setOwnBusy(true);
85
+ companySwitch(tenant)
86
+ .then(() => refreshOsContext(os))
87
+ .catch(() => {
88
+ /* The app's switch says what went wrong; the plate stays as it was. */
89
+ })
90
+ .finally(() => setOwnBusy(false));
91
+ };
92
+ const switchable = companySwitch !== "none" && Boolean(current) && tenants.length > 1;
93
+ const companyMenu = switchable && current ? (_jsxs(_Fragment, { children: [_jsx(ActionList, { sections: [{
94
+ title: "Your companies",
95
+ items: tenants.map((tenant) => ({
96
+ content: tenant.name,
97
+ active: tenant.id === current.id,
98
+ disabled: busy,
99
+ prefix: _jsx("img", { className: "as-ws__company-mark", src: markFor(tenant, "plain"), alt: "" }),
100
+ onAction: () => pick(tenant),
101
+ })),
102
+ }] }), 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;
103
+ 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, companyName: current?.name, onSwitchCompany: switchable ? () => setMenuOpen((open) => !open) : undefined, companyMenu: companyMenu, companyMenuOpen: menuOpen, onCompanyMenuClose: () => setMenuOpen(false) }));
104
+ 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 }));
105
+ }