autosolutions-os 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/nav.js CHANGED
@@ -160,11 +160,16 @@ export const HUB_PATHS = {
160
160
  admin: "/admin",
161
161
  settings: "/comms/settings",
162
162
  };
163
- /** Why a row is locked. A tool whose status is In progress or To build says so instead. */
163
+ /**
164
+ * Why a row is locked. A tool whose status is In progress or To build says so
165
+ * instead. `checking` is a Live tool whose app the catalogue decides, while
166
+ * os_context() has not answered yet (or failed, and is being asked again).
167
+ */
164
168
  export const HINTS = {
165
169
  locked: "Ask your company admin to switch this on for you",
166
170
  notBuilt: "Not built yet",
167
171
  notLinked: "Live, not linked from the Hub yet",
172
+ checking: "Checking your access…",
168
173
  };
169
174
  /** The rail footer: Admin (for someone who manages something), Settings, then Sign out, always last. */
170
175
  export function osFooter({ admin = false } = {}) {
@@ -201,6 +206,11 @@ export function staticLinks() {
201
206
  * A fixed `url` is never consulted here: it is no way round the catalogue.
202
207
  * Tools with no app keep osFrame's own rules. Links are final: osFrame adds
203
208
  * nothing to them.
209
+ *
210
+ * With `apps` null (the catalogue has not answered yet, or the read failed
211
+ * and is being asked again), nothing is linked, and a Live tool with an app
212
+ * reads "Checking your access…" rather than claiming it is not linked or not
213
+ * held; any other keeps the map's own status.
204
214
  */
205
215
  export function catalogueLinks(apps, tenantSlug = null) {
206
216
  const links = {};
@@ -208,6 +218,11 @@ export function catalogueLinks(apps, tenantSlug = null) {
208
218
  for (const [tool, link] of Object.entries(OS_TOOL_LINKS)) {
209
219
  if (!link.app)
210
220
  continue;
221
+ if (apps === null) {
222
+ if (STATUS.get(tool) === "Live")
223
+ locked[tool] = HINTS.checking;
224
+ continue;
225
+ }
211
226
  const app = apps.find((candidate) => candidate.key === link.app);
212
227
  if (app?.url)
213
228
  links[tool] = withTenantHint(joinPath(app.url, link.path), tenantSlug);
@@ -234,12 +249,18 @@ function joinPath(base, path) {
234
249
  function trimmed(pathname) {
235
250
  return pathname.replace(/\/+$/, "") || "/";
236
251
  }
237
- /** How specifically `route` claims `location`: [path length, query params], or null when it does not. */
238
- function claim(route, location) {
252
+ /**
253
+ * How specifically `route` claims `location`: [path length, query params], or
254
+ * null when it does not. Paths compare without regard to case, as the routers
255
+ * the apps use match them (TanStack Router, React Router): /ops/Boards is the
256
+ * Boards page. `/` claims every location, as a tool's catch-all, unless
257
+ * `exact`: a tab at `/` is one page, `/` itself.
258
+ */
259
+ function claim(route, location, exact = false) {
239
260
  const wanted = new URL(route, ORIGIN);
240
- const path = trimmed(wanted.pathname);
241
- const here = trimmed(location.pathname);
242
- if (path !== "/" && here !== path && !here.startsWith(`${path}/`))
261
+ const path = trimmed(wanted.pathname).toLowerCase();
262
+ const here = trimmed(location.pathname).toLowerCase();
263
+ if (path === "/" ? exact && here !== "/" : here !== path && !here.startsWith(`${path}/`))
243
264
  return null;
244
265
  let params = 0;
245
266
  for (const [key, value] of wanted.searchParams) {
@@ -256,12 +277,12 @@ function better(a, b) {
256
277
  return true;
257
278
  return a[0] > b[0] || (a[0] === b[0] && a[1] > b[1]);
258
279
  }
259
- function best(routes, location) {
280
+ function best(routes, location, exact = false) {
260
281
  let top = null;
261
282
  for (const route of routes) {
262
283
  if (!route)
263
284
  continue;
264
- const score = claim(route, location);
285
+ const score = claim(route, location, exact);
265
286
  if (better(score, top))
266
287
  top = score;
267
288
  }
@@ -317,7 +338,11 @@ export function osFrame(options) {
317
338
  section.items.push(rowFor({ id: tool.id, label: tool.label ?? tool.id, ...(tool.icon ? { icon: tool.icon } : {}) }, tool));
318
339
  }
319
340
  const footerItems = osFooter({ admin });
320
- /* Every place a location can land, most specific claim wins. */
341
+ /* Every place a location can land, most specific claim wins; on a tie, the
342
+ first. A tool's tabs come before the tool's own row, so where a tab and
343
+ its row claim a location alike (Key Accounts' Requests tab and the tool
344
+ both at /), it is on the tab: the list and a draft under it are one
345
+ place. */
321
346
  const claims = [];
322
347
  if (settingsPath)
323
348
  claims.push({ routes: [settingsPath], spot: { fn: "settings", item: null, tab: null } });
@@ -328,10 +353,10 @@ export function osFrame(options) {
328
353
  for (const row of section.items) {
329
354
  if (row.disabled)
330
355
  continue;
331
- claims.push({ routes: [row.path, ...(row.match ?? [])], spot: { fn, item: row.id, tab: null } });
332
356
  for (const tab of flatTabs(row.tabs)) {
333
- claims.push({ routes: [tab.path, ...(tab.match ?? [])], spot: { fn, item: row.id, tab: tab.id } });
357
+ claims.push({ routes: [tab.path, ...(tab.match ?? [])], spot: { fn, item: row.id, tab: tab.id }, exact: true });
334
358
  }
359
+ claims.push({ routes: [row.path, ...(row.match ?? [])], spot: { fn, item: row.id, tab: null } });
335
360
  }
336
361
  }
337
362
  }
@@ -347,7 +372,7 @@ export function osFrame(options) {
347
372
  let top = null;
348
373
  let found;
349
374
  for (const candidate of claims) {
350
- const score = best(candidate.routes, url);
375
+ const score = best(candidate.routes, url, candidate.exact);
351
376
  if (better(score, top)) {
352
377
  top = score;
353
378
  found = candidate.spot;
@@ -395,6 +420,12 @@ export function osFrame(options) {
395
420
  return null; // opening a function's menu is not a navigation
396
421
  if (!isHub)
397
422
  return toHub(HUB_PATHS.home);
423
+ /* The rail's Hub where the person is already in the Hub (a thread, a
424
+ tool, the landing) reopens its menu on that page: it is the menu's
425
+ control, never a navigation. Back to hub, and the rail's Hub from
426
+ another place (Admin, an app's Settings), land on the landing. */
427
+ if (!state.back && here.fn === fn && (sections[fn]?.length ?? 0) > 0)
428
+ return null;
398
429
  /* The Hub: stay anywhere on the landing's own ground, else land on it. */
399
430
  const landing = locate(homePath);
400
431
  return here.fn === landing.fn && here.item === landing.item ? null : { href: homePath, external: false };
package/dist/url.d.ts CHANGED
@@ -1,9 +1,21 @@
1
- /**
2
- * URL helpers with no dependencies, so `autosolutions-os/nav` can use them
3
- * without pulling React or Supabase into an app's bundle.
4
- */
5
1
  /**
6
2
  * Apps show the acting company's branding, so a link carries it as a hint.
7
3
  * Access is still decided by the core; this only saves a round trip.
8
4
  */
9
5
  export declare function withTenantHint(url: string, slug: string | null): string;
6
+ /**
7
+ * Where a company switch lands once the core has made it: `null` reloads the
8
+ * page in place, a URL is a same-tab navigation.
9
+ *
10
+ * - The hub reloads where the person is. `switch_company_for_app` never
11
+ * returns a per-company hub URL, so there is nowhere else it would go.
12
+ * - An app goes to the deployment the core returns (`appUrl`), by a reload
13
+ * when that is this origin.
14
+ * - An app the new company does not hold (no `appUrl`) goes to the hub, as the
15
+ * apps' own company switchers did: a reload would land on the app's
16
+ * "not entitled" state.
17
+ */
18
+ export declare function companySwitchLanding(appKey: string, result: {
19
+ appUrl?: string | null;
20
+ tenantSlug?: string | null;
21
+ }, origin: string): string | null;
package/dist/url.js CHANGED
@@ -1,7 +1,9 @@
1
1
  /**
2
- * URL helpers with no dependencies, so `autosolutions-os/nav` can use them
3
- * without pulling React or Supabase into an app's bundle.
2
+ * URL helpers with no dependencies outside this package, so
3
+ * `autosolutions-os/nav` can use them without pulling React or Supabase into
4
+ * an app's bundle.
4
5
  */
6
+ import { HUB_URL } from "./config.js";
5
7
  /**
6
8
  * Apps show the acting company's branding, so a link carries it as a hint.
7
9
  * Access is still decided by the core; this only saves a round trip.
@@ -18,3 +20,28 @@ export function withTenantHint(url, slug) {
18
20
  return url;
19
21
  }
20
22
  }
23
+ /**
24
+ * Where a company switch lands once the core has made it: `null` reloads the
25
+ * page in place, a URL is a same-tab navigation.
26
+ *
27
+ * - The hub reloads where the person is. `switch_company_for_app` never
28
+ * returns a per-company hub URL, so there is nowhere else it would go.
29
+ * - An app goes to the deployment the core returns (`appUrl`), by a reload
30
+ * when that is this origin.
31
+ * - An app the new company does not hold (no `appUrl`) goes to the hub, as the
32
+ * apps' own company switchers did: a reload would land on the app's
33
+ * "not entitled" state.
34
+ */
35
+ export function companySwitchLanding(appKey, result, origin) {
36
+ if (appKey === "hub")
37
+ return null;
38
+ const destination = result.appUrl ? withTenantHint(result.appUrl, result.tenantSlug ?? null) : HUB_URL;
39
+ try {
40
+ if (new URL(destination).origin === origin)
41
+ return null;
42
+ }
43
+ catch {
44
+ /* malformed destination: navigate anyway and let the browser report it */
45
+ }
46
+ return destination;
47
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autosolutions-os",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
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",
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "peerDependencies": {
23
23
  "@supabase/supabase-js": ">=2.40.0",
24
- "autosolutions-design-system": ">=6.3.3 <7",
24
+ "autosolutions-design-system": ">=6.4.0 <7",
25
25
  "react": ">=18"
26
26
  },
27
27
  "peerDependenciesMeta": {