autosolutions-os 0.3.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,72 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.5 - 2026-10-18
4
+
5
+ The live check of every app found two menu rows still sending people to old
6
+ lovable.app addresses: Commercial > Key accounts and Operations > Candidate
7
+ hub, in every frame off the core (Asset Portal and Ops Hub without a Hub
8
+ session) and in the fixed links. Those addresses only redirect to the apps'
9
+ autosolutions.app addresses, and some internet providers block lovable.app.
10
+
11
+ ### autosolutions-os/nav
12
+
13
+ - `OS_TOOL_LINKS["key-accounts"]` is https://key-accounts.autosolutions.app and
14
+ `OS_TOOL_LINKS["candidate-hub"]` is https://candidate-hub.autosolutions.app,
15
+ as the core catalogue's `launch_url` now is. `staticLinks()` follows. No
16
+ fixed link names a lovable.app address any more (tested).
17
+ - Nothing else changes. Apps take this release with a lockfile bump.
18
+
19
+ ## 0.3.4 - 2026-10-18
20
+
21
+ The Hub's frame in the two apps that keep their own Supabase project (Asset
22
+ Portal and Ops Hub), for a person signed in at the Hub. The final visual review
23
+ found them drawing the frame from fixed addresses, so, unlike the Hub, they
24
+ showed no Admin row for company admins, opened the five held apps with no
25
+ address (Paid media, Marketing calendar, Influencer Manager, NPD validator,
26
+ Shelf simulator) as Hub sample pages instead of the Hub's locked rows, left
27
+ rows for apps the company does not hold open, and drew a static plate with no
28
+ switcher. Apps on the core take this release with a lockfile bump: nothing
29
+ changes for them.
30
+
31
+ ### autosolutions-os/core-view
32
+
33
+ - `useCoreFrame({ appKey, email, fallback, companySwitch? })` returns
34
+ `{ source, frameOptions, plate }`: spread `frameOptions` into `osFrame` and
35
+ `plate` into the workspace `TopBar`. With a Hub session for the app's person
36
+ on an autosolutions.app address, they are what OsWorkspaceFrame draws for
37
+ that app: the catalogue's links (with the acting company as `?tenant=`) and
38
+ locks, the Admin row from `my_admin_scope()`, and the acting company's plate
39
+ with its switcher for someone with more than one company. Without one, they
40
+ are the frame from 0.3.3: `staticLinks(fallback.tenantSlug)`, no Admin row,
41
+ the fallback's static plate. `source` is `"core"`, `"checking"` (asking the
42
+ core, as the Hub does while it loads) or `"static"`.
43
+ - The reader under it, `createCoreViewClient({ email })`, borrows the Hub's
44
+ access token from the core's shared cookie at every call, while it is good,
45
+ only for the app's own person (by email), and only for `os_context`,
46
+ `my_admin_scope` and `switch_company_for_app` (`CORE_VIEW_FUNCTIONS`), posted
47
+ to the core's REST endpoint with no cookies. It never signs in, refreshes,
48
+ writes a cookie or storage, or publishes a session, and the token never
49
+ reaches the app. `hubSession(email)` says what it sees: the core user id,
50
+ the email, the expiry and whether the token can be used; never the token.
51
+ - The company switch is the package's own: the core switches, then the app
52
+ reloads when the new company holds it here, goes to its deployment
53
+ elsewhere, or goes to the Hub when the company does not hold the app.
54
+
55
+ ### Shared with OsWorkspaceFrame
56
+
57
+ - The company plate and its menu moved from frame.tsx to plate.tsx
58
+ (`useOsPlate`), unchanged, so OsWorkspaceFrame and `useCoreFrame` draw them
59
+ from one copy.
60
+ - The `os_context()` cache follows the Hub's person for `useCoreFrame`
61
+ (`followOsPerson`): a cached answer for someone else is never handed out.
62
+
63
+ ### What each app does after taking 0.3.4
64
+
65
+ - Apps on the core: bump `autosolutions-os` to `^0.3.4`. Nothing else.
66
+ - Asset Portal (staff face) and Ops Hub: bump, then build the frame's links,
67
+ Admin row and plate from `useCoreFrame` (README, "On its own project, with
68
+ the Hub's session").
69
+
3
70
  ## 0.3.3 - 2026-10-18
4
71
 
5
72
  The owner's three calls of 18 October. Every app takes them with a lockfile
package/README.md CHANGED
@@ -290,7 +290,8 @@ Supabase: the rail (`OS_FUNCTIONS`), the menu map (`OS_MENU`), the Hub panel
290
290
  and `searchOsMenu()` (the menu search's data and matching), and `osFrame()`,
291
291
  the routing rules the frame runs on. An app on its own
292
292
  project (Ops Hub: see "Linked, not federated" in `docs/CONTRACT.md`) pairs it
293
- with the design system's `WorkspaceFrame`, a static plate and no switcher.
293
+ with the design system's `WorkspaceFrame`, a static plate and no switcher; for
294
+ a person signed in at the Hub it draws the Hub's frame instead (0.3.4, below).
294
295
  `staticLinks(slug)` are the fixed addresses, the ones the Hub's catalogue
295
296
  gives (0.3.2: every app with a live address, Ops Hub's tools on
296
297
  ops-hub.autosolutions.app, PM Copilot's console at `/ops`; 0.3.3: Operations'
@@ -344,6 +345,68 @@ const menuSearch = useOsMenuSearch({ frame, location: here, onNavigate: (href) =
344
345
  {menuSearch.results}
345
346
  ```
346
347
 
348
+ ### On its own project, with the Hub's session (0.3.4)
349
+
350
+ An app on its own Supabase project (Asset Portal, Ops Hub) cannot ask the core
351
+ with its own client. On an autosolutions.app address it can still draw the
352
+ Hub's frame for a person who is signed in at the Hub: `useCoreFrame` from
353
+ `autosolutions-os/core-view` reads the core's own view of that person through
354
+ the Hub's session in the core's shared cookie, and gives the frame what
355
+ OsWorkspaceFrame gives an app on the core: the catalogue's links and locks
356
+ (`catalogueLinks`), the Admin row (`my_admin_scope()`), and the company plate
357
+ with its switcher (`os_context()`, the same plate code as OsWorkspaceFrame's).
358
+ The app keeps its own `osFrame`, `WorkspaceFrame` and `TopBar`, and spreads
359
+ two objects into them:
360
+
361
+ ```tsx
362
+ import { TopBar, WorkspaceFrame, companyMarkUrl } from "autosolutions-design-system";
363
+ import { useCoreFrame } from "autosolutions-os/core-view";
364
+ import { osFrame } from "autosolutions-os/nav";
365
+
366
+ const core = useCoreFrame({
367
+ appKey: "asset_portal",
368
+ email: user?.email, // the person signed in to the app
369
+ fallback: { tenantSlug: "frank-body", companyName: "frank body", companySrc: companyMarkUrl("frankbody", "plain") },
370
+ });
371
+ const frame = useMemo(() => osFrame({ appKey: "asset_portal", tools, ...core.frameOptions }), [tools, core.frameOptions]);
372
+
373
+ <WorkspaceFrame topBar={<TopBar variant="workspace" {...menuSearch.topBar} {...core.plate} />} /* the rest as before */ />
374
+ ```
375
+
376
+ `core.source` says which frame it is: `"core"` (the core's view), `"checking"`
377
+ (the Hub's session is there and the core is being asked: other apps' rows read
378
+ "Checking your access…" and the plate keeps its place, as in the Hub while it
379
+ loads) or `"static"` (the fallback). The fallback is the frame from before
380
+ 0.3.4: `staticLinks(tenantSlug)`, no Admin row, and a static plate. It is drawn
381
+ whenever there is no Hub session for the app's person: off autosolutions.app,
382
+ signed out at the Hub, someone else signed in there (the Hub session counts
383
+ only when its email is `email`), nobody signed in to the app yet, blocked
384
+ cookies, or a core that does not answer. The hook looks at the cookie again
385
+ when the window comes back, when the page is shown again and once a minute.
386
+
387
+ The reader behind it (`createCoreViewClient`; `hubSession(email)` says what it
388
+ sees, without the token) is read-only:
389
+
390
+ - it borrows the Hub's access token from the shared cookie at every call, and
391
+ only while that token is good (more than 30 seconds left). It never signs in,
392
+ never refreshes the token, never writes a cookie or storage, and never
393
+ publishes a session: a refresh would rotate the Hub's refresh token behind
394
+ the Hub's back. A token that has expired since the frame was read keeps the
395
+ frame; on a fresh page it is the fallback until the Hub (or any app on the
396
+ core) refreshes it, and the frame follows when the window comes back;
397
+ - it sends the token to the core's REST endpoint and nowhere else, for
398
+ `os_context`, `my_admin_scope` and `switch_company_for_app` only
399
+ (`CORE_VIEW_FUNCTIONS`); any other name is refused before anything is sent;
400
+ - the company switch is the Hub's (`companySwitch`, default `"os"`): the core
401
+ switches the acting company, then the app reloads when the new company holds
402
+ it at this address, goes to its deployment elsewhere, or goes to the Hub when
403
+ the company does not hold the app. The app's own sign-in, data and access
404
+ rules do not change.
405
+
406
+ On the server there is no cookie to read, so the hook gives the fallback:
407
+ render the frame in the browser only (Asset Portal's staff face does), or
408
+ accept a first paint of the fallback.
409
+
347
410
  ## On the server
348
411
 
349
412
  The package is plain ES modules, so Node, a test runner and a dev server's SSR
@@ -47,4 +47,15 @@ export declare function scheduleOsContextRetry(os: unknown): void;
47
47
  * new answer.
48
48
  */
49
49
  export declare function retryOsContext(os: unknown): Promise<OsContext | null>;
50
+ /** Test seam: forget the person followed and the answer, as on a fresh page. */
51
+ export declare function resetOsContextPerson(): void;
52
+ /**
53
+ * Follow the person whose context this is, by their core user id, for a
54
+ * frame that reads the core through a session it does not hold itself
55
+ * (`useCoreFrame`, autosolutions-os/core-view, 0.3.4: the Hub's session, read
56
+ * from the shared cookie). The first call names the person, so a cached
57
+ * answer for anyone else is not handed out; after that a change of person
58
+ * reads again, and null (no Hub session for this person) forgets the answer.
59
+ */
60
+ export declare function followOsPerson(person: string | null): void;
50
61
  export declare function watchOsAuth(auth: unknown): void;
@@ -193,6 +193,30 @@ function personChanged(person) {
193
193
  if (lastOs)
194
194
  void again(lastOs);
195
195
  }
196
+ /** Test seam: forget the person followed and the answer, as on a fresh page. */
197
+ export function resetOsContextPerson() {
198
+ authUser = undefined;
199
+ pendingFor = undefined;
200
+ invalidateOsContext();
201
+ }
202
+ /**
203
+ * Follow the person whose context this is, by their core user id, for a
204
+ * frame that reads the core through a session it does not hold itself
205
+ * (`useCoreFrame`, autosolutions-os/core-view, 0.3.4: the Hub's session, read
206
+ * from the shared cookie). The first call names the person, so a cached
207
+ * answer for anyone else is not handed out; after that a change of person
208
+ * reads again, and null (no Hub session for this person) forgets the answer.
209
+ */
210
+ export function followOsPerson(person) {
211
+ if (authUser === undefined) {
212
+ authUser = person;
213
+ return;
214
+ }
215
+ if (person === authUser)
216
+ return;
217
+ authUser = person;
218
+ personChanged(person);
219
+ }
196
220
  /**
197
221
  * Follow sign-ins and sign-outs through the app's Supabase auth client
198
222
  * (`supabase.auth`), live, in this tab too, and for an app whose session is
@@ -0,0 +1,51 @@
1
+ /** The only core functions the reader calls: the frame's two questions, and the company switch. */
2
+ export declare const CORE_VIEW_FUNCTIONS: readonly ["os_context", "my_admin_scope", "switch_company_for_app"];
3
+ export type CoreViewFunction = (typeof CORE_VIEW_FUNCTIONS)[number];
4
+ /** The Hub's session as the reader sees it. Never the token. */
5
+ export type HubSession = {
6
+ /** The person's core user id. */
7
+ userId: string;
8
+ /** Their email at the core, lower case. */
9
+ email: string;
10
+ /** When the access token in the cookie expires, in seconds since the epoch, as Supabase writes it. */
11
+ expiresAt: number;
12
+ /**
13
+ * The token can be used now (it expires more than 30 seconds from now).
14
+ * When it has expired the person is still signed in at the Hub, and the
15
+ * Hub (or any app on the core) refreshes it the next time it is open.
16
+ */
17
+ usable: boolean;
18
+ };
19
+ /**
20
+ * The person signed in at the Hub, when it is the person with this email
21
+ * (the one signed in to the app), as the core's shared cookie on
22
+ * .autosolutions.app says; or null: no email, off autosolutions.app, no
23
+ * shared session, signed out at the Hub, someone else, or cookies blocked.
24
+ */
25
+ export declare function hubSession(email: string | null | undefined): HubSession | null;
26
+ /** What a call answers: the shape supabase-js's `rpc` resolves to, as the package's frame code reads it. */
27
+ export type CoreViewResult = {
28
+ data: unknown;
29
+ error: {
30
+ message: string;
31
+ } | null;
32
+ };
33
+ /** The read-only core client: `rpc` for the three functions in CORE_VIEW_FUNCTIONS. */
34
+ export type CoreViewClient = {
35
+ rpc: (fn: string, args?: Record<string, unknown>) => Promise<CoreViewResult>;
36
+ };
37
+ export type CoreViewClientOptions = {
38
+ /** The email of the person signed in to the app, read at every call. */
39
+ email: () => string | null | undefined;
40
+ /** For tests: the fetch to use. Default the global one. */
41
+ fetch?: typeof fetch;
42
+ };
43
+ /**
44
+ * A client for the core that borrows the Hub's session from the shared
45
+ * cookie, read at every call: `rpc(fn, args)` for os_context,
46
+ * my_admin_scope and switch_company_for_app, posted to the core's REST
47
+ * endpoint with the session's access token, as supabase-js would. With no
48
+ * usable Hub session for the app's person, or for any other function, it
49
+ * answers with an error and sends nothing.
50
+ */
51
+ export declare function createCoreViewClient(options: CoreViewClientOptions): CoreViewClient;
@@ -0,0 +1,153 @@
1
+ /**
2
+ * The core's view of a person, for an app on its own Supabase project (0.3.4).
3
+ *
4
+ * Asset Portal and Ops Hub keep their own projects, their own sign-in and
5
+ * their own data (docs/CONTRACT.md, "Federated: own project, one sign-in").
6
+ * On an autosolutions.app address they can still read the core's shared
7
+ * cookie, which holds the Hub's session, and so ask the core the questions
8
+ * the Hub's frame asks: os_context() (the acting company, the person's
9
+ * companies and the apps they hold) and my_admin_scope() (whether they manage
10
+ * anything), and switch the acting company, as the Hub's plate does.
11
+ *
12
+ * This file is that reader, and nothing more:
13
+ *
14
+ * - It never signs in, never refreshes a token, never writes a cookie or
15
+ * storage, and never publishes a session anywhere. It reads the shared
16
+ * cookie on every call and uses the access token in it while that token is
17
+ * good. A refresh would rotate the Hub's refresh token behind the Hub's
18
+ * back; only the Hub and the apps on the core refresh it.
19
+ * - The token goes to the core's REST endpoint and nowhere else, for three
20
+ * functions only (CORE_VIEW_FUNCTIONS). Any other name is refused before
21
+ * anything is sent. The token is never handed to the app.
22
+ * - It answers only for the app's own person: the Hub's session counts only
23
+ * when its email is the email of the person signed in to the app.
24
+ *
25
+ * Off autosolutions.app, with no shared session, after a sign-out at the
26
+ * Hub, or for someone else, there is no Hub session and the reader answers
27
+ * every call with an error, sending nothing. No React, no supabase-js.
28
+ */
29
+ import { coreProjectRef, corePublishableKey, coreUrl, PARENT_DOMAIN } from "./config.js";
30
+ import { joinChunks, parseCopy, parseSignedOutNote, sharedSessionCookieName, signedOutCookieName, signedOutCopy, } from "./session.js";
31
+ /** The only core functions the reader calls: the frame's two questions, and the company switch. */
32
+ export const CORE_VIEW_FUNCTIONS = ["os_context", "my_admin_scope", "switch_company_for_app"];
33
+ /**
34
+ * A token this close to expiring is not used: supabase-js treats a session as
35
+ * expired 30 seconds early too, and the Hub refreshes well before that.
36
+ */
37
+ const EXPIRY_MARGIN_MS = 30_000;
38
+ const normalise = (email) => {
39
+ const value = typeof email === "string" ? email.trim().toLowerCase() : "";
40
+ return value.length > 0 ? value : null;
41
+ };
42
+ function onParentDomain() {
43
+ if (typeof window === "undefined" || typeof document === "undefined")
44
+ return false;
45
+ const host = window.location.hostname;
46
+ return host === PARENT_DOMAIN || host.endsWith(`.${PARENT_DOMAIN}`);
47
+ }
48
+ /** The shared session in the cookie, with its token, when it is this person's and not signed out. */
49
+ function readShared(email) {
50
+ const wanted = normalise(email);
51
+ if (wanted === null || !onParentDomain())
52
+ return null;
53
+ try {
54
+ const ref = coreProjectRef();
55
+ const jar = new Map();
56
+ for (const entry of document.cookie ? document.cookie.split("; ") : []) {
57
+ const index = entry.indexOf("=");
58
+ if (index > 0)
59
+ jar.set(entry.slice(0, index), entry.slice(index + 1));
60
+ }
61
+ const raw = joinChunks(sharedSessionCookieName(ref), (name) => jar.get(name));
62
+ const copy = parseCopy(raw);
63
+ if (!raw || !copy || copy.userId === null)
64
+ return null;
65
+ // Signed out at the Hub: the note covers this copy.
66
+ if (signedOutCopy(copy, parseSignedOutNote(jar.get(signedOutCookieName(ref)))))
67
+ return null;
68
+ const value = JSON.parse(raw);
69
+ const token = typeof value.access_token === "string" ? value.access_token : "";
70
+ const theirs = normalise(typeof value.user?.email === "string" ? value.user.email : null);
71
+ if (!token || theirs === null || theirs !== wanted)
72
+ return null;
73
+ return {
74
+ session: {
75
+ userId: copy.userId,
76
+ email: theirs,
77
+ expiresAt: copy.expiresAt,
78
+ usable: copy.expiresAt * 1000 - Date.now() > EXPIRY_MARGIN_MS,
79
+ },
80
+ token,
81
+ };
82
+ }
83
+ catch {
84
+ // Cookies blocked or unreadable: no Hub session.
85
+ return null;
86
+ }
87
+ }
88
+ /**
89
+ * The person signed in at the Hub, when it is the person with this email
90
+ * (the one signed in to the app), as the core's shared cookie on
91
+ * .autosolutions.app says; or null: no email, off autosolutions.app, no
92
+ * shared session, signed out at the Hub, someone else, or cookies blocked.
93
+ */
94
+ export function hubSession(email) {
95
+ return readShared(email)?.session ?? null;
96
+ }
97
+ const refused = (message) => ({ data: null, error: { message } });
98
+ /**
99
+ * A client for the core that borrows the Hub's session from the shared
100
+ * cookie, read at every call: `rpc(fn, args)` for os_context,
101
+ * my_admin_scope and switch_company_for_app, posted to the core's REST
102
+ * endpoint with the session's access token, as supabase-js would. With no
103
+ * usable Hub session for the app's person, or for any other function, it
104
+ * answers with an error and sends nothing.
105
+ */
106
+ export function createCoreViewClient(options) {
107
+ const allowed = new Set(CORE_VIEW_FUNCTIONS);
108
+ return {
109
+ async rpc(fn, args = {}) {
110
+ if (!allowed.has(fn))
111
+ return refused(`${fn}: not one of the core functions a frame reads`);
112
+ const shared = readShared(options.email());
113
+ if (!shared)
114
+ return refused("No Hub session for this person");
115
+ if (!shared.session.usable)
116
+ return refused("The Hub session needs a refresh at the Hub");
117
+ const send = options.fetch ?? (typeof fetch === "function" ? fetch : undefined);
118
+ if (!send)
119
+ return refused("No fetch");
120
+ try {
121
+ const response = await send(`${coreUrl()}/rest/v1/rpc/${fn}`, {
122
+ method: "POST",
123
+ headers: {
124
+ apikey: corePublishableKey(),
125
+ Authorization: `Bearer ${shared.token}`,
126
+ "Content-Type": "application/json",
127
+ Accept: "application/json",
128
+ },
129
+ body: JSON.stringify(args),
130
+ // The token is the only credential: no cookies of any origin go with it.
131
+ credentials: "omit",
132
+ cache: "no-store",
133
+ });
134
+ const text = await response.text();
135
+ let body = null;
136
+ try {
137
+ body = text ? JSON.parse(text) : null;
138
+ }
139
+ catch {
140
+ body = null;
141
+ }
142
+ if (!response.ok) {
143
+ const message = body?.message;
144
+ return refused(typeof message === "string" && message ? message : `HTTP ${response.status}`);
145
+ }
146
+ return { data: body, error: null };
147
+ }
148
+ catch {
149
+ return refused("The core did not answer");
150
+ }
151
+ },
152
+ };
153
+ }
@@ -0,0 +1,56 @@
1
+ import { type OsCompanySwitch, type OsPlateProps } from "./plate.js";
2
+ export { CORE_VIEW_FUNCTIONS, createCoreViewClient, hubSession, type CoreViewClient, type CoreViewClientOptions, type CoreViewFunction, type CoreViewResult, type HubSession, } from "./coreReader.js";
3
+ export type { OsCompanySwitch, OsPlateProps } from "./plate.js";
4
+ export type CoreFrameOptions = {
5
+ /** This app's catalogue key: "asset_portal", "ops_hub". */
6
+ appKey: string;
7
+ /**
8
+ * The email of the person signed in to the app. The Hub's session counts
9
+ * only when it is the same person; null or undefined (nobody signed in
10
+ * yet) is the fallback frame.
11
+ */
12
+ email: string | null | undefined;
13
+ /** Today's frame, for when there is no Hub session: the app's own company. */
14
+ fallback: {
15
+ /** The company's slug in the core, for `staticLinks` and the rows into the Hub: "frank-body". */
16
+ tenantSlug: string;
17
+ /** The plate's name, and what it shows when the artwork does not load. */
18
+ companyName?: string;
19
+ /** The plate's artwork. */
20
+ companySrc?: string;
21
+ };
22
+ /** How the plate switches company with a Hub session. Default "os", as in the Hub. */
23
+ companySwitch?: OsCompanySwitch;
24
+ };
25
+ /**
26
+ * Where the frame comes from:
27
+ * - "core": the core's view of the person, through the Hub's session;
28
+ * - "checking": the Hub's session is there and the core is being asked, so
29
+ * other apps' rows read "Checking your access…" and the plate keeps its
30
+ * place, as in the Hub while it loads;
31
+ * - "static": no Hub session for this person, or the core could not be
32
+ * read: the fixed addresses and the app's own company.
33
+ */
34
+ export type CoreFrameSource = "core" | "checking" | "static";
35
+ /** What `osFrame` takes from the core: spread `frameOptions` into it. */
36
+ export type CoreFrameOptionsForOsFrame = {
37
+ links: Record<string, string>;
38
+ locked: Record<string, string>;
39
+ admin: boolean;
40
+ tenantSlug: string | null;
41
+ };
42
+ /** The design system's TopBar props for the company plate: spread `plate` into `<TopBar>`. */
43
+ export type CorePlateProps = Partial<OsPlateProps>;
44
+ export type CoreFrame = {
45
+ source: CoreFrameSource;
46
+ /** For `osFrame({ appKey, tools, ...frameOptions })`. The same object until something changes. */
47
+ frameOptions: CoreFrameOptionsForOsFrame;
48
+ /** For `<TopBar variant="workspace" {...plate} />`. */
49
+ plate: CorePlateProps;
50
+ };
51
+ /**
52
+ * The frame's links, Admin row and company plate from the core's own view of
53
+ * the person signed in to the app, when they are signed in at the Hub;
54
+ * otherwise the app's fallback frame. See the top of this file.
55
+ */
56
+ export declare function useCoreFrame({ appKey, email, fallback, companySwitch }: CoreFrameOptions): CoreFrame;
@@ -0,0 +1,132 @@
1
+ /**
2
+ * autosolutions-os/core-view (0.3.4): the Hub's frame in an app that keeps its
3
+ * own Supabase project, for a person who is signed in at the Hub.
4
+ *
5
+ * Asset Portal and Ops Hub build their frame from `osFrame` and the design
6
+ * system's WorkspaceFrame, because their own client cannot read the core. On
7
+ * an autosolutions.app address the core's shared cookie holds the Hub's
8
+ * session, so `useCoreFrame` reads the core's own view of the person through
9
+ * it (coreReader.ts: os_context(), my_admin_scope() and the company switch,
10
+ * nothing else, never signing in, refreshing or writing anything) and hands
11
+ * back exactly what OsWorkspaceFrame gives an app on the core:
12
+ *
13
+ * - the menu links from the catalogue (`catalogueLinks`): a tool whose app
14
+ * the person holds opens it, with the acting company as ?tenant=; a tool
15
+ * whose app they do not hold is locked; a held app with no address yet
16
+ * opens its page in the Hub;
17
+ * - the Admin row, for someone who manages something;
18
+ * - the company plate from the acting company, and with more than one company
19
+ * its switcher (plate.tsx, the same code as OsWorkspaceFrame's), which
20
+ * switches as the Hub does: a reload here when the new company holds this
21
+ * app at this address, its deployment elsewhere, or the Hub when it does
22
+ * not hold the app.
23
+ *
24
+ * Without a Hub session for the app's person (signed out at the Hub, someone
25
+ * else at the Hub, a partner, cookies blocked, or off autosolutions.app) it
26
+ * hands back today's frame instead: the fixed addresses (`staticLinks`) with
27
+ * the app's own company, no Admin row, and a static plate. The app's own
28
+ * sign-in, data and rules are untouched either way.
29
+ */
30
+ import { useEffect, useMemo, useRef, useState } from "react";
31
+ import { retryOsContext } from "./context.js";
32
+ import { followOsPerson } from "./contextCache.js";
33
+ import { createCoreViewClient, hubSession } from "./coreReader.js";
34
+ import { myAdminScope } from "./identity.js";
35
+ import { catalogueLinks, staticLinks } from "./nav.js";
36
+ import { useOsPlate } from "./plate.js";
37
+ export { CORE_VIEW_FUNCTIONS, createCoreViewClient, hubSession, } from "./coreReader.js";
38
+ /** How often a page that stays open looks at the shared cookie again, besides focus and coming back into view. */
39
+ const LOOK_EVERY = 60_000;
40
+ const sameHub = (a, b) => (a === b || (a !== null && b !== null && a.userId === b.userId && a.email === b.email && a.usable === b.usable));
41
+ /**
42
+ * The frame's links, Admin row and company plate from the core's own view of
43
+ * the person signed in to the app, when they are signed in at the Hub;
44
+ * otherwise the app's fallback frame. See the top of this file.
45
+ */
46
+ export function useCoreFrame({ appKey, email, fallback, companySwitch = "os" }) {
47
+ /* One reader per mounted frame, asking with the app's person as they are now. */
48
+ const emailNow = useRef(email);
49
+ emailNow.current = email;
50
+ const [client] = useState(() => createCoreViewClient({ email: () => emailNow.current }));
51
+ /* The Hub's session for this person: read now, and again when the window
52
+ comes back, the page is shown again, once a minute, and when the app's
53
+ person changes. A refreshed token for the same person changes nothing. */
54
+ const [hub, setHub] = useState(() => hubSession(email));
55
+ useEffect(() => {
56
+ const look = () => {
57
+ const next = hubSession(emailNow.current);
58
+ setHub((was) => (sameHub(was, next) ? was : next));
59
+ };
60
+ look();
61
+ if (typeof window === "undefined" || typeof document === "undefined")
62
+ return undefined;
63
+ const wake = () => {
64
+ if (document.visibilityState !== "hidden")
65
+ look();
66
+ };
67
+ document.addEventListener("visibilitychange", wake);
68
+ window.addEventListener("focus", wake);
69
+ window.addEventListener("pageshow", wake);
70
+ const timer = setInterval(look, LOOK_EVERY);
71
+ return () => {
72
+ document.removeEventListener("visibilitychange", wake);
73
+ window.removeEventListener("focus", wake);
74
+ window.removeEventListener("pageshow", wake);
75
+ clearInterval(timer);
76
+ };
77
+ }, [email]);
78
+ /* The answer is this person's: the cache reads again for another person,
79
+ and forgets the answer when there is no Hub session. Declared before the
80
+ plate's own read, so it runs first. */
81
+ const person = hub?.userId ?? null;
82
+ useEffect(() => {
83
+ followOsPerson(person);
84
+ }, [person]);
85
+ /* A token that has become usable (the Hub refreshed it, or the person signed
86
+ in there): ask now rather than on the next timer. */
87
+ const usable = hub?.usable === true;
88
+ useEffect(() => {
89
+ if (usable)
90
+ void retryOsContext(client);
91
+ }, [usable, client]);
92
+ const { context, status, current, plate } = useOsPlate(client, appKey, companySwitch);
93
+ /* The Admin row, as OsWorkspaceFrame decides it: the core's my_admin_scope().
94
+ Asked for each person whose token can be used; a failed answer keeps the
95
+ last one for that person, and nobody's carries over to someone else. */
96
+ const [admin, setAdmin] = useState(null);
97
+ useEffect(() => {
98
+ if (!usable || person === null)
99
+ return undefined;
100
+ let alive = true;
101
+ myAdminScope(client)
102
+ .then((scope) => {
103
+ if (alive)
104
+ setAdmin({ person, manages: scope.isPlatformAdmin || scope.managesTenants.length > 0 });
105
+ })
106
+ .catch(() => {
107
+ /* No Admin row is the safe failure; the admin console checks again anyway. */
108
+ });
109
+ return () => {
110
+ alive = false;
111
+ };
112
+ }, [usable, person, client]);
113
+ const manages = admin !== null && admin.person === person && admin.manages;
114
+ const source = hub !== null && status === "ready" && context !== null
115
+ ? "core"
116
+ : usable && status === "loading" ? "checking" : "static";
117
+ const apps = context?.apps;
118
+ const slug = current?.slug ?? null;
119
+ const frameOptions = useMemo(() => {
120
+ if (source === "static") {
121
+ return { links: staticLinks(fallback.tenantSlug), locked: {}, admin: false, tenantSlug: fallback.tenantSlug };
122
+ }
123
+ /* "checking": apps is null, so nothing is linked and other apps' rows read as being checked. */
124
+ const { links, locked } = catalogueLinks(source === "core" ? apps ?? null : null, source === "core" ? slug : null);
125
+ return { links, locked, admin: source === "core" && manages, tenantSlug: source === "core" ? slug : null };
126
+ }, [source, apps, slug, manages, fallback.tenantSlug]);
127
+ const staticPlate = useMemo(() => ({
128
+ ...(fallback.companySrc ? { companySrc: fallback.companySrc } : {}),
129
+ ...(fallback.companyName ? { companyName: fallback.companyName } : {}),
130
+ }), [fallback.companySrc, fallback.companyName]);
131
+ return { source, frameOptions, plate: source === "static" ? staticPlate : plate };
132
+ }
package/dist/frame.d.ts CHANGED
@@ -27,22 +27,9 @@
27
27
  */
28
28
  import { type ReactNode } from "react";
29
29
  import type { WorkspaceState } from "autosolutions-design-system";
30
- import { type OsTenant } from "./context.js";
31
30
  import { type OsAppTool, type OsHubSection } from "./nav.js";
32
- /**
33
- * How the plate's chevron switches company.
34
- * - "os" (default): switch_company_for_app, then reload or land on that
35
- * company's deployment of this app, like OsCompanySwitcher.
36
- * - "none": the plate shows the acting company with no chevron, for an app
37
- * whose company is fixed some other way (an assignment, say).
38
- * - a function: the app's own in-place switch. The frame calls it with the
39
- * chosen company, closes the menu and does not reload; when it resolves,
40
- * the plate and the menu links follow the new company at once, and the
41
- * frame reads the core again (asking again if that read fails). The function
42
- * reports its own failures (a toast); a rejection only leaves the plate as
43
- * it was.
44
- */
45
- export type OsCompanySwitch = "os" | "none" | ((tenant: OsTenant) => Promise<void>);
31
+ import { type OsCompanySwitch } from "./plate.js";
32
+ export type { OsCompanySwitch } from "./plate.js";
46
33
  export type OsWorkspaceFrameProps = {
47
34
  /** The client's `os` (public schema) connection. */
48
35
  os: unknown;
package/dist/frame.js CHANGED
@@ -26,23 +26,13 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
26
26
  * the OS menu search (`autosolutions-os/search`), which jumps to any app or
27
27
  * page the menu reaches.
28
28
  */
29
- import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
30
- import { ActionList, TopBar, WorkspaceFrame } from "autosolutions-design-system";
31
- import { useCompanySwitch } from "./chrome.js";
32
- import { markFor, refreshOsContext, retryOsContext, watchOsAuth } from "./context.js";
29
+ import { useCallback, useEffect, useId, useMemo, useState } from "react";
30
+ import { TopBar, WorkspaceFrame } from "autosolutions-design-system";
31
+ import { retryOsContext, watchOsAuth } from "./context.js";
33
32
  import { myAdminScope } from "./identity.js";
34
33
  import { catalogueLinks, osFrame } from "./nav.js";
34
+ import { useOsPlate } from "./plate.js";
35
35
  import { useMenuSearch } from "./search.js";
36
- /* A company's mark in the company menu. When its artwork does not load, the
37
- slot stays, empty (the row already says the company's name), so the names
38
- stay lined up; never a broken image. */
39
- function CompanyMenuMark({ src }) {
40
- const [failed, setFailed] = useState(null);
41
- if (failed === src)
42
- return _jsx("span", { className: "as-ws__company-mark", "aria-hidden": "true" });
43
- return _jsx("img", { className: "as-ws__company-mark", src: src, alt: "", onError: () => { if (failed !== src)
44
- setFailed(src); } });
45
- }
46
36
  /* This app's own rows and tabs as links to their paths. Rows for other apps
47
37
  already carry their address; a locked row is never a link. */
48
38
  function linked(sections, hrefFor) {
@@ -70,21 +60,8 @@ const here = () => (typeof window === "undefined" ? "" : window.location.pathnam
70
60
  export function OsWorkspaceFrame({ os, auth, appKey, tools, hubItems, location, onNavigate, hrefFor, search, actions, companySwitch = "os", panelFooter, onSignOut, homePath, admin, favicon = true, initialOpen, className, children, ...rest }) {
71
61
  /* Only data-* and aria-* reach the frame's root. */
72
62
  const attributes = Object.fromEntries(Object.entries(rest).filter(([key]) => /^(data|aria)-/.test(key)));
73
- const { context, status, current: read, tenants, busy: switching, error, choose } = useCompanySwitch(os, appKey);
74
- const [menuOpen, setMenuOpen] = useState(false);
75
- const [ownBusy, setOwnBusy] = useState(false);
76
- const busy = switching || ownBusy;
77
- /* An in-place switch (companySwitch as a function) makes the chosen company
78
- the acting one at once: the plate, the menu's check and the links follow
79
- it until the core is read again, whether or not that read succeeds, so a
80
- read that fails never leaves the plate on the company the session has
81
- left (and a pick of that company is a real switch back). */
82
- const [acting, setActing] = useState(null);
83
- const current = acting && acting.over === context ? acting.tenant : read;
84
- const contextNow = useRef(context);
85
- contextNow.current = context;
86
- const live = useRef(true);
87
- useEffect(() => () => { live.current = false; }, []);
63
+ /* The company plate and its menu (plate.tsx, shared with useCoreFrame). */
64
+ const { context, status, current, plate } = useOsPlate(os, appKey, companySwitch);
88
65
  /* The core decides who manages something; the footer only reflects it. */
89
66
  const [manages, setManages] = useState(false);
90
67
  useEffect(() => {
@@ -164,59 +141,9 @@ export function OsWorkspaceFrame({ os, auth, appKey, tools, hubItems, location,
164
141
  const signOut = onSignOut ?? (() => {
165
142
  void auth?.signOut().then(() => window.location.reload());
166
143
  });
167
- /* After an in-place switch: read the core again, and again if that fails,
168
- a few times, while the frame is mounted. */
169
- const readAgain = (tries) => {
170
- void refreshOsContext(os).then((value) => {
171
- if (value || tries <= 1 || !live.current)
172
- return;
173
- setTimeout(() => { if (live.current)
174
- readAgain(tries - 1); }, 1500);
175
- });
176
- };
177
- /* The company menu, offered only when there is somewhere to switch to: a
178
- menu of radio items, the acting company checked. */
179
- const pick = (tenant) => {
180
- if (typeof companySwitch !== "function") {
181
- void choose(tenant.id, () => setMenuOpen(false));
182
- return;
183
- }
184
- setMenuOpen(false);
185
- if (!current || busy || tenant.id === current.id)
186
- return;
187
- setOwnBusy(true);
188
- companySwitch(tenant)
189
- .then(() => {
190
- if (!live.current)
191
- return;
192
- setActing({ tenant, over: contextNow.current });
193
- readAgain(3);
194
- })
195
- .catch(() => {
196
- /* The app's switch says what went wrong; the plate stays as it was. */
197
- })
198
- .finally(() => { if (live.current)
199
- setOwnBusy(false); });
200
- };
201
- const switchable = companySwitch !== "none" && Boolean(current) && tenants.length > 1;
202
- const companyMenu = switchable && current ? (_jsxs(_Fragment, { children: [_jsx(ActionList, { role: "menu", "aria-label": "Switch company", sections: [{
203
- title: "Your companies",
204
- items: tenants.map((tenant) => ({
205
- content: tenant.name,
206
- active: tenant.id === current.id,
207
- checked: tenant.id === current.id,
208
- disabled: busy,
209
- prefix: _jsx(CompanyMenuMark, { src: markFor(tenant, "plain") }),
210
- onAction: () => pick(tenant),
211
- })),
212
- }] }), 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;
213
144
  const topBar = (_jsx(TopBar, { variant: "workspace", "data-os-bar": barId, ...(own
214
145
  ? { searchPlaceholder: search?.placeholder ?? "Search", searchValue: search?.value, onSearchChange: search?.onChange }
215
- : menuSearch.topBar), actions: actions, company: current?.slug ?? null, companySrc: current ? markFor(current, "plain") : undefined,
216
- /* Also what the plate shows when the company has no artwork, or it fails to load. */
217
- companyName: current?.name,
218
- /* While the company is read, its place on the bar is kept. */
219
- companyPending: !current && status === "loading" ? (companySwitch === "none" ? "plate" : true) : undefined, onSwitchCompany: switchable ? () => setMenuOpen((open) => !open) : undefined, companyMenu: companyMenu, companyMenuOpen: menuOpen, onCompanyMenuClose: () => setMenuOpen(false) }));
146
+ : menuSearch.topBar), actions: actions, ...plate }));
220
147
  /* The menu search's matches hang under the bar's field, drawn after the
221
148
  frame; nothing while they are closed. */
222
149
  return (_jsxs(_Fragment, { children: [_jsx(WorkspaceFrame, { className: className, topBar: topBar, functions: frame.functions, sections: sections, footerItems: frame.footerItems, homeFunction: frame.homeFunction, location: { ...frame.locate(location), href: location }, onNavigate: navigate, onSignOut: signOut, favicon: favicon, panelFooter: panelFooter, ...(initialOpen === undefined ? {} : { initialOpen }), ...attributes, children: children }), menuSearch.results] }));
package/dist/nav.d.ts CHANGED
@@ -136,6 +136,11 @@ export type OsToolLink = {
136
136
  * locked for someone who does not, like Ops Hub's tools; and Asset Manager's
137
137
  * fixed address is asset-portal.autosolutions.app, which shares the Hub's
138
138
  * sign-in (self-asset-manager.lovable.app cannot read it).
139
+ *
140
+ * Since 0.3.5: Key Accounts and Candidate Hub have their autosolutions.app
141
+ * addresses (key-accounts, candidate-hub), as the core catalogue does. The
142
+ * lovable.app ones only redirect there, and some internet providers block
143
+ * lovable.app.
139
144
  */
140
145
  export declare const OS_TOOL_LINKS: Record<string, OsToolLink>;
141
146
  /** The Hub's own pages, for the rail's Hub, Admin and Settings rows in other apps. */
package/dist/nav.js CHANGED
@@ -207,6 +207,11 @@ const opsHub = (path) => ({ app: "ops_hub", url: OPS_HUB, path });
207
207
  * locked for someone who does not, like Ops Hub's tools; and Asset Manager's
208
208
  * fixed address is asset-portal.autosolutions.app, which shares the Hub's
209
209
  * sign-in (self-asset-manager.lovable.app cannot read it).
210
+ *
211
+ * Since 0.3.5: Key Accounts and Candidate Hub have their autosolutions.app
212
+ * addresses (key-accounts, candidate-hub), as the core catalogue does. The
213
+ * lovable.app ones only redirect there, and some internet providers block
214
+ * lovable.app.
210
215
  */
211
216
  export const OS_TOOL_LINKS = {
212
217
  "live-ecomm-sales": { app: "alive_reporting", url: "https://e-sales.autosolutions.app" },
@@ -222,7 +227,7 @@ export const OS_TOOL_LINKS = {
222
227
  "sales": opsHub("/sales-dashboard"),
223
228
  "open-orders": opsHub("/customer-orders"),
224
229
  "crm": { app: "enxgy_crm", url: "https://e-crm.autosolutions.app" },
225
- "key-accounts": { app: "key_accounts", url: "https://key-accounts.lovable.app" },
230
+ "key-accounts": { app: "key_accounts", url: "https://key-accounts.autosolutions.app" },
226
231
  /* Operations' Overview is Ops Hub's home dashboard (owner, 0.3.3). */
227
232
  "operations-home": opsHub("/"),
228
233
  "inventory-health": opsHub("/inventory-health"),
@@ -234,7 +239,7 @@ export const OS_TOOL_LINKS = {
234
239
  "ordering-tool": opsHub("/ordering"),
235
240
  "carton-label-generator": { app: "label_maker", url: "https://label-maker.autosolutions.app" },
236
241
  "pm-copilot": { app: "pm_copilot", url: "https://pm-copilot.autosolutions.app", path: "/ops" },
237
- "candidate-hub": { app: "candidate_hub", url: "https://hire-spark-center.lovable.app" },
242
+ "candidate-hub": { app: "candidate_hub", url: "https://candidate-hub.autosolutions.app" },
238
243
  };
239
244
  /** The Hub's own pages, for the rail's Hub, Admin and Settings rows in other apps. */
240
245
  export const HUB_PATHS = {
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The top bar's company plate and its menu, as every frame on the core draws
3
+ * them: OsWorkspaceFrame, and since 0.3.4 `useCoreFrame`
4
+ * (`autosolutions-os/core-view`), for an app on its own project that reads the
5
+ * core through the Hub's session. One copy, so the two cannot drift: moved
6
+ * here from frame.tsx in 0.3.4, unchanged.
7
+ *
8
+ * The plate shows the acting company's mark (its name, when it has no artwork
9
+ * or the artwork fails to load). With somewhere to switch to, the plate and
10
+ * its chevron are one button that opens a menu of the person's companies, the
11
+ * acting one checked.
12
+ */
13
+ import { type ReactNode } from "react";
14
+ import { type OsContext, type OsContextStatus, type OsTenant } from "./context.js";
15
+ /**
16
+ * How the plate's chevron switches company.
17
+ * - "os" (default): switch_company_for_app, then reload or land on that
18
+ * company's deployment of this app, like OsCompanySwitcher.
19
+ * - "none": the plate shows the acting company with no chevron, for an app
20
+ * whose company is fixed some other way (an assignment, say).
21
+ * - a function: the app's own in-place switch. The frame calls it with the
22
+ * chosen company, closes the menu and does not reload; when it resolves,
23
+ * the plate and the menu links follow the new company at once, and the
24
+ * frame reads the core again (asking again if that read fails). The function
25
+ * reports its own failures (a toast); a rejection only leaves the plate as
26
+ * it was.
27
+ */
28
+ export type OsCompanySwitch = "os" | "none" | ((tenant: OsTenant) => Promise<void>);
29
+ /** The design system's TopBar props for the company plate: spread them into `<TopBar>`. */
30
+ export type OsPlateProps = {
31
+ company: string | null;
32
+ companySrc: string | undefined;
33
+ companyName: string | undefined;
34
+ companyPending: true | "plate" | undefined;
35
+ onSwitchCompany: (() => void) | undefined;
36
+ companyMenu: ReactNode;
37
+ companyMenuOpen: boolean;
38
+ onCompanyMenuClose: () => void;
39
+ };
40
+ /**
41
+ * The acting company (the core's, or the one an in-place switch just made
42
+ * acting), the context it came from, and the plate's TopBar props.
43
+ */
44
+ export declare function useOsPlate(os: unknown, appKey: string, companySwitch: OsCompanySwitch): {
45
+ context: OsContext | null;
46
+ status: OsContextStatus;
47
+ current: OsTenant | null;
48
+ plate: OsPlateProps;
49
+ };
package/dist/plate.js ADDED
@@ -0,0 +1,107 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * The top bar's company plate and its menu, as every frame on the core draws
4
+ * them: OsWorkspaceFrame, and since 0.3.4 `useCoreFrame`
5
+ * (`autosolutions-os/core-view`), for an app on its own project that reads the
6
+ * core through the Hub's session. One copy, so the two cannot drift: moved
7
+ * here from frame.tsx in 0.3.4, unchanged.
8
+ *
9
+ * The plate shows the acting company's mark (its name, when it has no artwork
10
+ * or the artwork fails to load). With somewhere to switch to, the plate and
11
+ * its chevron are one button that opens a menu of the person's companies, the
12
+ * acting one checked.
13
+ */
14
+ import { useEffect, useRef, useState } from "react";
15
+ import { ActionList } from "autosolutions-design-system";
16
+ import { useCompanySwitch } from "./chrome.js";
17
+ import { markFor, refreshOsContext } from "./context.js";
18
+ /* A company's mark in the company menu. When its artwork does not load, the
19
+ slot stays, empty (the row already says the company's name), so the names
20
+ stay lined up; never a broken image. */
21
+ function CompanyMenuMark({ src }) {
22
+ const [failed, setFailed] = useState(null);
23
+ if (failed === src)
24
+ return _jsx("span", { className: "as-ws__company-mark", "aria-hidden": "true" });
25
+ return _jsx("img", { className: "as-ws__company-mark", src: src, alt: "", onError: () => { if (failed !== src)
26
+ setFailed(src); } });
27
+ }
28
+ /**
29
+ * The acting company (the core's, or the one an in-place switch just made
30
+ * acting), the context it came from, and the plate's TopBar props.
31
+ */
32
+ export function useOsPlate(os, appKey, companySwitch) {
33
+ const { context, status, current: read, tenants, busy: switching, error, choose } = useCompanySwitch(os, appKey);
34
+ const [menuOpen, setMenuOpen] = useState(false);
35
+ const [ownBusy, setOwnBusy] = useState(false);
36
+ const busy = switching || ownBusy;
37
+ /* An in-place switch (companySwitch as a function) makes the chosen company
38
+ the acting one at once: the plate, the menu's check and the links follow
39
+ it until the core is read again, whether or not that read succeeds, so a
40
+ read that fails never leaves the plate on the company the session has
41
+ left (and a pick of that company is a real switch back). */
42
+ const [acting, setActing] = useState(null);
43
+ const current = acting && acting.over === context ? acting.tenant : read;
44
+ const contextNow = useRef(context);
45
+ contextNow.current = context;
46
+ const live = useRef(true);
47
+ useEffect(() => () => { live.current = false; }, []);
48
+ /* After an in-place switch: read the core again, and again if that fails,
49
+ a few times, while the frame is mounted. */
50
+ const readAgain = (tries) => {
51
+ void refreshOsContext(os).then((value) => {
52
+ if (value || tries <= 1 || !live.current)
53
+ return;
54
+ setTimeout(() => { if (live.current)
55
+ readAgain(tries - 1); }, 1500);
56
+ });
57
+ };
58
+ /* The company menu, offered only when there is somewhere to switch to: a
59
+ menu of radio items, the acting company checked. */
60
+ const pick = (tenant) => {
61
+ if (typeof companySwitch !== "function") {
62
+ void choose(tenant.id, () => setMenuOpen(false));
63
+ return;
64
+ }
65
+ setMenuOpen(false);
66
+ if (!current || busy || tenant.id === current.id)
67
+ return;
68
+ setOwnBusy(true);
69
+ companySwitch(tenant)
70
+ .then(() => {
71
+ if (!live.current)
72
+ return;
73
+ setActing({ tenant, over: contextNow.current });
74
+ readAgain(3);
75
+ })
76
+ .catch(() => {
77
+ /* The app's switch says what went wrong; the plate stays as it was. */
78
+ })
79
+ .finally(() => { if (live.current)
80
+ setOwnBusy(false); });
81
+ };
82
+ const switchable = companySwitch !== "none" && Boolean(current) && tenants.length > 1;
83
+ const companyMenu = switchable && current ? (_jsxs(_Fragment, { children: [_jsx(ActionList, { role: "menu", "aria-label": "Switch company", sections: [{
84
+ title: "Your companies",
85
+ items: tenants.map((tenant) => ({
86
+ content: tenant.name,
87
+ active: tenant.id === current.id,
88
+ checked: tenant.id === current.id,
89
+ disabled: busy,
90
+ prefix: _jsx(CompanyMenuMark, { src: markFor(tenant, "plain") }),
91
+ onAction: () => pick(tenant),
92
+ })),
93
+ }] }), 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;
94
+ const plate = {
95
+ company: current?.slug ?? null,
96
+ companySrc: current ? markFor(current, "plain") : undefined,
97
+ /* Also what the plate shows when the company has no artwork, or it fails to load. */
98
+ companyName: current?.name,
99
+ /* While the company is read, its place on the bar is kept. */
100
+ companyPending: !current && status === "loading" ? (companySwitch === "none" ? "plate" : true) : undefined,
101
+ onSwitchCompany: switchable ? () => setMenuOpen((open) => !open) : undefined,
102
+ companyMenu,
103
+ companyMenuOpen: menuOpen,
104
+ onCompanyMenuClose: () => setMenuOpen(false),
105
+ };
106
+ return { context, status, current, plate };
107
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autosolutions-os",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "One sign-in, one company switcher, one app grid. What every AutoSolutions app imports instead of copying.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -13,6 +13,7 @@
13
13
  "./frame": { "types": "./dist/frame.d.ts", "import": "./dist/frame.js" },
14
14
  "./federation": { "types": "./dist/federation.d.ts", "import": "./dist/federation.js" },
15
15
  "./search": { "types": "./dist/search.d.ts", "import": "./dist/search.js" },
16
+ "./core-view": { "types": "./dist/coreView.d.ts", "import": "./dist/coreView.js" },
16
17
  "./chrome.css": "./dist/chrome.css"
17
18
  },
18
19
  "files": ["dist", "CHANGELOG.md"],