autosolutions-os 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +57 -0
- package/README.md +127 -0
- package/dist/chrome.d.ts +18 -0
- package/dist/chrome.js +39 -15
- package/dist/client.js +2 -2
- package/dist/context.d.ts +7 -5
- package/dist/context.js +22 -17
- package/dist/frame.d.ts +82 -0
- package/dist/frame.js +104 -0
- package/dist/gate.js +2 -2
- package/dist/index.d.ts +7 -7
- package/dist/index.js +7 -7
- package/dist/nav.d.ts +234 -0
- package/dist/nav.js +433 -0
- package/dist/server.js +2 -2
- package/dist/session.js +1 -1
- package/dist/url.d.ts +9 -0
- package/dist/url.js +20 -0
- package/package.json +8 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0 - 2026-09-28
|
|
4
|
+
|
|
5
|
+
The OS menu and the workspace frame. Needs `autosolutions-design-system` 6.3
|
|
6
|
+
for `autosolutions-os/frame` (an optional peer: nothing else uses it).
|
|
7
|
+
|
|
8
|
+
New:
|
|
9
|
+
|
|
10
|
+
- `autosolutions-os/frame`: `OsWorkspaceFrame`, the design system's
|
|
11
|
+
`WorkspaceFrame` wired to the core. The same rail, menu and footer in every
|
|
12
|
+
app, this app's own tools live, the company's plate and switcher on the top
|
|
13
|
+
bar, Admin for people who manage something. It works with any router: it
|
|
14
|
+
reads `location` and calls `onNavigate(href)`. It follows the URL: to every
|
|
15
|
+
new place (Back included), and back from a click that took it elsewhere
|
|
16
|
+
when the URL moves on, so nothing clicked outlives the URL; a query the
|
|
17
|
+
page writes for itself leaves the person's own choices (a page-state tab, a
|
|
18
|
+
closed menu) alone.
|
|
19
|
+
- `companySwitch`: `"os"` (the default: `switch_company_for_app`, then a
|
|
20
|
+
reload), `"none"` (the plate with no chevron) or the app's own in-place
|
|
21
|
+
switch, after which `refreshOsContext(os)` brings the plate and the links
|
|
22
|
+
round to the new company.
|
|
23
|
+
- `actions`, `panelFooter`, `initialOpen` (the first location's menu, for a
|
|
24
|
+
narrow screen), and `data-*` / `aria-*` on the frame's root.
|
|
25
|
+
- Tools and tabs take `badge`; tabs may be titled groups.
|
|
26
|
+
- `autosolutions-os/nav`, plain data and functions: the rail
|
|
27
|
+
(`OS_FUNCTIONS`), the menu map (`OS_MENU`: the handoff's 49 tools plus Shelf
|
|
28
|
+
simulator, Key accounts, PM Copilot and Candidate hub, 53 in all, 21 Live),
|
|
29
|
+
`OS_TOOL_LINKS`, `HUB_URL`, `HUB_PATHS`, `HINTS`, `osFooter()`,
|
|
30
|
+
`staticLinks()`, `catalogueLinks()` and `osFrame()`, the routing rules the
|
|
31
|
+
frame runs on. An app off the core pairs it with `WorkspaceFrame`.
|
|
32
|
+
- `refreshOsContext(os)`: read `os_context()` again and hand the answer to
|
|
33
|
+
every mounted reader. `useCompanySwitch(os, appKey)`: the switch the
|
|
34
|
+
company menus share.
|
|
35
|
+
|
|
36
|
+
Where a tool goes:
|
|
37
|
+
|
|
38
|
+
- `OS_TOOL_LINKS` maps each tool to its catalogue app, so the menu reaches
|
|
39
|
+
every app the app switcher offers (all but the Hub, which is the rail's
|
|
40
|
+
Hub). In a frame backed by the catalogue, a tool whose app the person holds
|
|
41
|
+
links to it, with `?tenant=`, in the same tab, whatever status the map gives
|
|
42
|
+
the tool. A Live tool whose app is held but not deployed reads "Live, not
|
|
43
|
+
linked from the Hub yet", and one whose app is not held is locked ("Ask
|
|
44
|
+
your company admin to switch this on for you"); a tool the map does not mark
|
|
45
|
+
Live keeps its status in both cases.
|
|
46
|
+
- A tool's fixed `url` serves `staticLinks()` only, for frames off the core
|
|
47
|
+
with no catalogue to ask. It is never a way round the catalogue.
|
|
48
|
+
|
|
49
|
+
Fixed:
|
|
50
|
+
|
|
51
|
+
- The package loads in Node, not only in a bundler: every relative import
|
|
52
|
+
names its `.js` file. 0.1.0 did not, so `vite dev` SSR and test runners
|
|
53
|
+
failed with `ERR_MODULE_NOT_FOUND .../dist/config`.
|
|
54
|
+
`scripts/check-os-consumer.sh` installs the packed tarball and loads it in
|
|
55
|
+
Node, vitest, Vite SSR and a DOM.
|
|
56
|
+
- Under Vite SSR, list both packages in `ssr.noExternal`: the frame imports
|
|
57
|
+
the design system, whose components ship as JSX source.
|
package/README.md
CHANGED
|
@@ -29,8 +29,135 @@ 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.
|
|
66
|
+
|
|
67
|
+
- `tools` are this app's own rows, by menu-map id, with their routes. They are
|
|
68
|
+
live whatever the map says. A row the map does not have takes `fn`, `section`,
|
|
69
|
+
`label` and `icon`. A row can carry a `badge` (a count), and so can a tab.
|
|
70
|
+
- `tabs` is a flat list, or titled groups (`{ title, items }[]`) drawn with the
|
|
71
|
+
menu's own section headings. A tab with a `path` navigates; one without is
|
|
72
|
+
page state, read from the frame's state (`children` as a function).
|
|
73
|
+
- Every other tool opens its app in the same tab, and only if the person holds
|
|
74
|
+
that app: the menu reaches every app the app switcher offers (all but the
|
|
75
|
+
Hub itself, which is the rail's Hub). `OS_TOOL_LINKS` names each tool's app,
|
|
76
|
+
and `os_context()` decides:
|
|
77
|
+
- held, with an address: the tool goes there (plus its `path`) with
|
|
78
|
+
`?tenant=`, whatever status the map gives it (Influencer Manager is In
|
|
79
|
+
progress in the map, Marketing calendar and Paid media have none, yet a
|
|
80
|
+
company that holds their apps reaches them);
|
|
81
|
+
- held, not deployed yet: a Live tool reads "Live, not linked from the Hub
|
|
82
|
+
yet", any other keeps its status;
|
|
83
|
+
- not held: a Live tool is locked ("Ask your company admin to switch this on
|
|
84
|
+
for you"); any other keeps its status (Not built yet, In progress, To
|
|
85
|
+
build).
|
|
86
|
+
A tool's fixed `url` is never used here; it is for frames off the core
|
|
87
|
+
(`staticLinks()`). Tools with no app follow the map: Pricing researcher and
|
|
88
|
+
Brand voice copywriter read "Live, not linked from the Hub yet", anything
|
|
89
|
+
not Live shows its status.
|
|
90
|
+
- The company plate is `markFor(tenant, "plain")`. The chevron appears only for
|
|
91
|
+
someone with more than one company. `companySwitch` says what it does:
|
|
92
|
+
- `"os"` (the default) switches exactly as `OsCompanySwitcher` does, since
|
|
93
|
+
both use `useCompanySwitch(os, appKey)`: `switch_company_for_app`, then a
|
|
94
|
+
reload or that company's deployment of this app.
|
|
95
|
+
- `"none"` shows the acting company with no chevron, for an app whose
|
|
96
|
+
company is fixed some other way (PM Copilot's assignment).
|
|
97
|
+
- a function `(tenant) => Promise<void>` is the app's own in-place switch
|
|
98
|
+
(e-sales: `switch_tenant`, invalidate, toast). The frame calls it, closes
|
|
99
|
+
the menu and does not reload; when it resolves, `refreshOsContext(os)`
|
|
100
|
+
brings the plate and the menu's links round to the new company. The
|
|
101
|
+
function reports its own failures.
|
|
102
|
+
- `actions` go in the top bar before the plate (What's new, a notification
|
|
103
|
+
bell). `panelFooter` renders in the panel under the open tool's tabs, in the
|
|
104
|
+
panel's padding, scrolling with them (Create Studio's sessions).
|
|
105
|
+
- Settings goes to `settingsPath` when the app has a settings page, and to the
|
|
106
|
+
Hub's settings when it has none.
|
|
107
|
+
- `initialOpen={false}` starts the menu closed on the first location (a narrow
|
|
108
|
+
screen); after that the frame's own rule applies. `data-*` and `aria-*` props
|
|
109
|
+
land on the frame's root.
|
|
110
|
+
- Admin appears when `my_admin_scope()` says the person manages something; pass
|
|
111
|
+
`admin` to decide it yourself.
|
|
112
|
+
- The Hub passes `hubItems`, its own rows. In any other app the rail's Hub, Back
|
|
113
|
+
to hub and Admin go to the Hub.
|
|
114
|
+
|
|
115
|
+
### Off the core
|
|
116
|
+
|
|
117
|
+
`autosolutions-os/nav` is plain data and functions, with no React and no
|
|
118
|
+
Supabase: the rail (`OS_FUNCTIONS`), the menu map (`OS_MENU`), `OS_TOOL_LINKS`,
|
|
119
|
+
`HUB_URL`, `HUB_PATHS`, `HINTS`, `osFooter()`, `staticLinks()` and
|
|
120
|
+
`osFrame()`, the routing rules the frame runs on. An app on its own project
|
|
121
|
+
(Ops Hub: see "Linked, not federated" in `docs/CONTRACT.md`) pairs it with the
|
|
122
|
+
design system's `WorkspaceFrame`, a static plate and no switcher. `staticLinks()`
|
|
123
|
+
are the fixed addresses (Ops Hub's tools, Label Maker, CRM, Key accounts, PM
|
|
124
|
+
Copilot), with no tenant hint; with no catalogue to ask, they are all live, and
|
|
125
|
+
each app's own sign-in decides. If the app's CSS is a fork of the design
|
|
126
|
+
system, import `autosolutions-design-system/frame.css` instead of `styles.css`
|
|
127
|
+
(see the design system's README).
|
|
128
|
+
|
|
129
|
+
```tsx
|
|
130
|
+
import { WorkspaceFrame, TopBar, companyMarkUrl } from "autosolutions-design-system";
|
|
131
|
+
import { osFrame, staticLinks } from "autosolutions-os/nav";
|
|
132
|
+
|
|
133
|
+
const frame = osFrame({ appKey: "ops_hub", tools, links: staticLinks() });
|
|
134
|
+
const here = pathname + search;
|
|
135
|
+
|
|
136
|
+
<WorkspaceFrame
|
|
137
|
+
topBar={<TopBar searchPlaceholder="Search" companySrc={companyMarkUrl("frankbody", "plain")} />}
|
|
138
|
+
functions={frame.functions}
|
|
139
|
+
sections={frame.sections}
|
|
140
|
+
footerItems={frame.footerItems}
|
|
141
|
+
location={{ ...frame.locate(here), href: here }}
|
|
142
|
+
onNavigate={(state) => {
|
|
143
|
+
const target = frame.targetFor(state, here);
|
|
144
|
+
if (target?.external) window.location.assign(target.href);
|
|
145
|
+
else if (target) navigate(target.href);
|
|
146
|
+
}}
|
|
147
|
+
onSignOut={signOut}
|
|
148
|
+
>
|
|
149
|
+
{page}
|
|
150
|
+
</WorkspaceFrame>
|
|
151
|
+
```
|
|
152
|
+
|
|
32
153
|
## On the server
|
|
33
154
|
|
|
155
|
+
The package is plain ES modules, so Node, a test runner and a dev server's SSR
|
|
156
|
+
load it as it is (`scripts/check-os-consumer.sh` proves it from the packed
|
|
157
|
+
tarball). The frame is the exception: it imports the design system, whose
|
|
158
|
+
components ship as JSX source, so a Vite SSR app compiles both in dev:
|
|
159
|
+
`ssr: { noExternal: ["autosolutions-design-system", "autosolutions-os"] }`.
|
|
160
|
+
|
|
34
161
|
```ts
|
|
35
162
|
import { authenticate, tokenFromRequest } from "autosolutions-os/server";
|
|
36
163
|
|
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
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
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
|
|
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
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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";
|
package/dist/frame.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
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.
|
|
14
|
+
*/
|
|
15
|
+
import { type ReactNode } from "react";
|
|
16
|
+
import type { WorkspaceState } from "autosolutions-design-system";
|
|
17
|
+
import { type OsTenant } from "./context.js";
|
|
18
|
+
import { type OsAppTool, type OsHubSection } from "./nav.js";
|
|
19
|
+
/**
|
|
20
|
+
* How the plate's chevron switches company.
|
|
21
|
+
* - "os" (default): switch_company_for_app, then reload or land on that
|
|
22
|
+
* company's deployment of this app, like OsCompanySwitcher.
|
|
23
|
+
* - "none": the plate shows the acting company with no chevron, for an app
|
|
24
|
+
* whose company is fixed some other way (an assignment, say).
|
|
25
|
+
* - a function: the app's own in-place switch. The frame calls it with the
|
|
26
|
+
* chosen company, closes the menu and does not reload; when it resolves,
|
|
27
|
+
* the plate and the menu links follow the new company. The function reports
|
|
28
|
+
* its own failures (a toast); a rejection only leaves the plate as it was.
|
|
29
|
+
*/
|
|
30
|
+
export type OsCompanySwitch = "os" | "none" | ((tenant: OsTenant) => Promise<void>);
|
|
31
|
+
export type OsWorkspaceFrameProps = {
|
|
32
|
+
/** The client's `os` (public schema) connection. */
|
|
33
|
+
os: unknown;
|
|
34
|
+
/** Used for Sign out when `onSignOut` is not given: signs out, then reloads. */
|
|
35
|
+
auth?: {
|
|
36
|
+
signOut: () => Promise<unknown>;
|
|
37
|
+
};
|
|
38
|
+
/** This app's catalogue key; "hub" for the Hub. */
|
|
39
|
+
appKey: string;
|
|
40
|
+
/** This app's own tools, with their routes: these rows are live whatever the map says. */
|
|
41
|
+
tools?: OsAppTool[];
|
|
42
|
+
/** 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. */
|
|
43
|
+
hubItems?: OsHubSection[];
|
|
44
|
+
/** Where the app is: pathname plus query. */
|
|
45
|
+
location: string;
|
|
46
|
+
/** Push an in-app path. Links to other apps are opened by the frame. */
|
|
47
|
+
onNavigate: (href: string) => void;
|
|
48
|
+
search?: {
|
|
49
|
+
placeholder?: string;
|
|
50
|
+
value?: string;
|
|
51
|
+
onChange?: (value: string) => void;
|
|
52
|
+
};
|
|
53
|
+
/** Extra controls in the top bar, before the company plate (What's new, a notification bell). */
|
|
54
|
+
actions?: ReactNode;
|
|
55
|
+
/** How the plate switches company. Default "os". */
|
|
56
|
+
companySwitch?: OsCompanySwitch;
|
|
57
|
+
/** Rendered in the panel under the open tool's tabs, in the panel's padding (a session list, say). */
|
|
58
|
+
panelFooter?: ReactNode;
|
|
59
|
+
/** Sign out, in whatever order the app needs (clear caches first, and so on). */
|
|
60
|
+
onSignOut?: () => void;
|
|
61
|
+
/** This app's settings route. Default: the Hub's settings. */
|
|
62
|
+
settingsPath?: string;
|
|
63
|
+
/** This app's landing. In the Hub it is where Back to hub lands. */
|
|
64
|
+
homePath?: string;
|
|
65
|
+
/** Show Admin in the footer. Default: asked of the core with my_admin_scope(). */
|
|
66
|
+
admin?: boolean;
|
|
67
|
+
/** Set the browser-tab icon from the current menu glyph. Default true. */
|
|
68
|
+
favicon?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Whether the menu starts open, for the first location only (false on a
|
|
71
|
+
* narrow screen, say). After that the frame's own rule applies: open on a
|
|
72
|
+
* function with a menu. Default: that rule from the start.
|
|
73
|
+
*/
|
|
74
|
+
initialOpen?: boolean;
|
|
75
|
+
className?: string;
|
|
76
|
+
children?: ReactNode | ((state: WorkspaceState) => ReactNode);
|
|
77
|
+
} & {
|
|
78
|
+
[key: `data-${string}`]: string | number | boolean | undefined;
|
|
79
|
+
} & {
|
|
80
|
+
[key: `aria-${string}`]: string | number | boolean | undefined;
|
|
81
|
+
};
|
|
82
|
+
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,104 @@
|
|
|
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.
|
|
15
|
+
*/
|
|
16
|
+
import { useEffect, useMemo, useState } from "react";
|
|
17
|
+
import { ActionList, TopBar, WorkspaceFrame } from "autosolutions-design-system";
|
|
18
|
+
import { useCompanySwitch } from "./chrome.js";
|
|
19
|
+
import { markFor, refreshOsContext } from "./context.js";
|
|
20
|
+
import { myAdminScope } from "./identity.js";
|
|
21
|
+
import { catalogueLinks, osFrame } from "./nav.js";
|
|
22
|
+
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 }) {
|
|
23
|
+
/* Only data-* and aria-* reach the frame's root. */
|
|
24
|
+
const attributes = Object.fromEntries(Object.entries(rest).filter(([key]) => /^(data|aria)-/.test(key)));
|
|
25
|
+
const { context, current, tenants, busy: switching, error, choose } = useCompanySwitch(os, appKey);
|
|
26
|
+
const [menuOpen, setMenuOpen] = useState(false);
|
|
27
|
+
const [ownBusy, setOwnBusy] = useState(false);
|
|
28
|
+
const busy = switching || ownBusy;
|
|
29
|
+
/* The core decides who manages something; the footer only reflects it. */
|
|
30
|
+
const [manages, setManages] = useState(false);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (admin !== undefined)
|
|
33
|
+
return undefined;
|
|
34
|
+
let live = true;
|
|
35
|
+
myAdminScope(os)
|
|
36
|
+
.then((scope) => {
|
|
37
|
+
if (live)
|
|
38
|
+
setManages(scope.isPlatformAdmin || scope.managesTenants.length > 0);
|
|
39
|
+
})
|
|
40
|
+
.catch(() => {
|
|
41
|
+
/* No Admin row is the safe failure; the admin console checks again anyway. */
|
|
42
|
+
});
|
|
43
|
+
return () => {
|
|
44
|
+
live = false;
|
|
45
|
+
};
|
|
46
|
+
}, [os, admin]);
|
|
47
|
+
const apps = context?.apps;
|
|
48
|
+
const slug = current?.slug ?? null;
|
|
49
|
+
const frame = useMemo(() => {
|
|
50
|
+
/* Only the catalogue says what this person holds. Until it arrives
|
|
51
|
+
nothing is linked and nothing is "not held": other apps' tools read as
|
|
52
|
+
not linked, never as a fixed address the person may not hold. */
|
|
53
|
+
const { links, locked } = apps ? catalogueLinks(apps, slug) : { links: {}, locked: {} };
|
|
54
|
+
return osFrame({
|
|
55
|
+
appKey, links, locked, admin: admin ?? manages, tenantSlug: slug,
|
|
56
|
+
...(tools ? { tools } : {}),
|
|
57
|
+
...(hubItems ? { hubItems } : {}),
|
|
58
|
+
...(settingsPath ? { settingsPath } : {}),
|
|
59
|
+
...(homePath ? { homePath } : {}),
|
|
60
|
+
});
|
|
61
|
+
}, [appKey, apps, admin, manages, slug, tools, hubItems, settingsPath, homePath]);
|
|
62
|
+
const navigate = (state) => {
|
|
63
|
+
const target = frame.targetFor(state, location);
|
|
64
|
+
if (!target)
|
|
65
|
+
return;
|
|
66
|
+
if (target.external)
|
|
67
|
+
window.location.assign(target.href);
|
|
68
|
+
else
|
|
69
|
+
onNavigate(target.href);
|
|
70
|
+
};
|
|
71
|
+
const signOut = onSignOut ?? (() => {
|
|
72
|
+
void auth?.signOut().then(() => window.location.reload());
|
|
73
|
+
});
|
|
74
|
+
/* The company menu, offered only when there is somewhere to switch to. */
|
|
75
|
+
const pick = (tenant) => {
|
|
76
|
+
if (typeof companySwitch !== "function") {
|
|
77
|
+
void choose(tenant.id, () => setMenuOpen(false));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
setMenuOpen(false);
|
|
81
|
+
if (!current || busy || tenant.id === current.id)
|
|
82
|
+
return;
|
|
83
|
+
setOwnBusy(true);
|
|
84
|
+
companySwitch(tenant)
|
|
85
|
+
.then(() => refreshOsContext(os))
|
|
86
|
+
.catch(() => {
|
|
87
|
+
/* The app's switch says what went wrong; the plate stays as it was. */
|
|
88
|
+
})
|
|
89
|
+
.finally(() => setOwnBusy(false));
|
|
90
|
+
};
|
|
91
|
+
const switchable = companySwitch !== "none" && Boolean(current) && tenants.length > 1;
|
|
92
|
+
const companyMenu = switchable && current ? (_jsxs(_Fragment, { children: [_jsx(ActionList, { sections: [{
|
|
93
|
+
title: "Your companies",
|
|
94
|
+
items: tenants.map((tenant) => ({
|
|
95
|
+
content: tenant.name,
|
|
96
|
+
active: tenant.id === current.id,
|
|
97
|
+
disabled: busy,
|
|
98
|
+
prefix: _jsx("img", { className: "as-ws__company-mark", src: markFor(tenant, "plain"), alt: "" }),
|
|
99
|
+
onAction: () => pick(tenant),
|
|
100
|
+
})),
|
|
101
|
+
}] }), 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;
|
|
102
|
+
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) }));
|
|
103
|
+
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 }));
|
|
104
|
+
}
|
package/dist/gate.js
CHANGED
|
@@ -13,8 +13,8 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
|
|
|
13
13
|
* lists, reads to the user as "the product is broken".
|
|
14
14
|
*/
|
|
15
15
|
import { useCallback, useEffect, useState } from "react";
|
|
16
|
-
import { isActiveMember, isEntitled } from "./identity";
|
|
17
|
-
import { invalidateOsContext, loadOsContext } from "./context";
|
|
16
|
+
import { isActiveMember, isEntitled } from "./identity.js";
|
|
17
|
+
import { invalidateOsContext, loadOsContext } from "./context.js";
|
|
18
18
|
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
19
19
|
/** The session is restored from storage asynchronously; give it one beat. */
|
|
20
20
|
const RESTORE_GRACE_MS = 1500;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { coreUrl, corePublishableKey, coreProjectRef, companyMarkUrl, appLabelUrl, HUB_URL, PARENT_DOMAIN } from "./config";
|
|
2
|
-
export { createOsClient, resetOsClient, type OsClient } from "./client";
|
|
3
|
-
export { adoptSharedSession, publishSessionChanges, sharedSessionCookieName, joinChunks } from "./session";
|
|
4
|
-
export { loadOsContext, invalidateOsContext, useOsContext, useTenant, useApps, groupApps, markFor, labelFor, withTenantHint, type OsContext, type OsTenant, type OsApp, } from "./context";
|
|
5
|
-
export { isEntitled, isActiveMember, appRole, appVariant, currentTenant, toolAllowed, myAdminScope, canManageCurrentCompany, type AdminScope, } from "./identity";
|
|
6
|
-
export { OsAppSwitcher, OsAppSwitcherPlate, OsCompanySwitcher, OsBar } from "./chrome";
|
|
7
|
-
export { OsAuthGate, type OsAuthGateProps } from "./gate";
|
|
1
|
+
export { coreUrl, corePublishableKey, coreProjectRef, companyMarkUrl, appLabelUrl, HUB_URL, PARENT_DOMAIN } from "./config.js";
|
|
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";
|
|
5
|
+
export { isEntitled, isActiveMember, appRole, appVariant, currentTenant, toolAllowed, myAdminScope, canManageCurrentCompany, type AdminScope, } from "./identity.js";
|
|
6
|
+
export { OsAppSwitcher, OsAppSwitcherPlate, OsCompanySwitcher, OsBar, useCompanySwitch } from "./chrome.js";
|
|
7
|
+
export { OsAuthGate, type OsAuthGateProps } from "./gate.js";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { coreUrl, corePublishableKey, coreProjectRef, companyMarkUrl, appLabelUrl, HUB_URL, PARENT_DOMAIN } from "./config";
|
|
2
|
-
export { createOsClient, resetOsClient } from "./client";
|
|
3
|
-
export { adoptSharedSession, publishSessionChanges, sharedSessionCookieName, joinChunks } from "./session";
|
|
4
|
-
export { loadOsContext, invalidateOsContext, useOsContext, useTenant, useApps, groupApps, markFor, labelFor, withTenantHint, } from "./context";
|
|
5
|
-
export { isEntitled, isActiveMember, appRole, appVariant, currentTenant, toolAllowed, myAdminScope, canManageCurrentCompany, } from "./identity";
|
|
6
|
-
export { OsAppSwitcher, OsAppSwitcherPlate, OsCompanySwitcher, OsBar } from "./chrome";
|
|
7
|
-
export { OsAuthGate } from "./gate";
|
|
1
|
+
export { coreUrl, corePublishableKey, coreProjectRef, companyMarkUrl, appLabelUrl, HUB_URL, PARENT_DOMAIN } from "./config.js";
|
|
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";
|
|
5
|
+
export { isEntitled, isActiveMember, appRole, appVariant, currentTenant, toolAllowed, myAdminScope, canManageCurrentCompany, } from "./identity.js";
|
|
6
|
+
export { OsAppSwitcher, OsAppSwitcherPlate, OsCompanySwitcher, OsBar, useCompanySwitch } from "./chrome.js";
|
|
7
|
+
export { OsAuthGate } from "./gate.js";
|