autosolutions-os 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +104 -0
- package/README.md +135 -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 +83 -0
- package/dist/frame.js +105 -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 +244 -0
- package/dist/nav.js +453 -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/dist/nav.js
ADDED
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The OS menu: the rail every app shows, the 53 tools of the menu map by
|
|
3
|
+
* function, and the one set of routing rules that turns a location into a
|
|
4
|
+
* place in the workspace frame and a click into a destination.
|
|
5
|
+
*
|
|
6
|
+
* Three levels, the same in every AutoSolutions webapp:
|
|
7
|
+
* 1 the rail Hub, Finance, Marketing, Commercial, Operations
|
|
8
|
+
* 2 the menu that function's tools, grouped Reporting / Planning
|
|
9
|
+
* 3 the tab menu the open tool's views, with Back to hub
|
|
10
|
+
*
|
|
11
|
+
* Pure data and pure functions: no React, no Supabase. An app that is not on
|
|
12
|
+
* the core imports this beside the design system's WorkspaceFrame; an app on
|
|
13
|
+
* the core gets it through OsWorkspaceFrame (`autosolutions-os/frame`).
|
|
14
|
+
*/
|
|
15
|
+
import { HUB_URL } from "./config.js";
|
|
16
|
+
import { withTenantHint } from "./url.js";
|
|
17
|
+
export { HUB_URL };
|
|
18
|
+
/** The rail: the Hub, then the four business functions. */
|
|
19
|
+
export const OS_FUNCTIONS = [
|
|
20
|
+
{ id: "hub", label: "Hub", icon: "hub" },
|
|
21
|
+
{ id: "finance", label: "Finance", icon: "finance" },
|
|
22
|
+
{ id: "marketing", label: "Marketing", icon: "marketing" },
|
|
23
|
+
{ id: "commercial", label: "Commercial", icon: "commercial" },
|
|
24
|
+
{ id: "operations", label: "Operations", icon: "operations" },
|
|
25
|
+
];
|
|
26
|
+
/**
|
|
27
|
+
* "Menu map - all 49 items by function", as the design handoff carries it,
|
|
28
|
+
* plus four Live apps the sheet did not have: Shelf simulator (Marketing >
|
|
29
|
+
* Planning), Key accounts (Commercial > Planning), PM Copilot and Candidate
|
|
30
|
+
* hub (Operations > Planning). Owner, source and cadence stay in the sheet.
|
|
31
|
+
* Icons are glyph ids from the design system's NAV_ICONS, which draws them
|
|
32
|
+
* inline; the four new rows borrow ops-inventory-value (a stocked shelf),
|
|
33
|
+
* com-customer-scorecard, hub-tasks and hub-accounts.
|
|
34
|
+
*/
|
|
35
|
+
export const OS_MENU = {
|
|
36
|
+
finance: [
|
|
37
|
+
{ title: "Reporting", items: [
|
|
38
|
+
{ id: "cash-forecast", label: "Cash & forecast", icon: "fin-cash", status: "No status" },
|
|
39
|
+
{ id: "pl-vs-budget", label: "P&L vs budget", icon: "fin-pl", status: "No status" },
|
|
40
|
+
{ id: "balance-sheet", label: "Balance sheet", icon: "fin-balance", status: "No status" },
|
|
41
|
+
{ id: "margin-by-channel", label: "Margin by channel", icon: "fin-margin", status: "No status" },
|
|
42
|
+
{ id: "debtors-creditors", label: "Debtors & creditors", icon: "fin-debtors", status: "No status" },
|
|
43
|
+
{ id: "board-pack", label: "Board pack", icon: "fin-ratios", status: "No status" },
|
|
44
|
+
] },
|
|
45
|
+
{ title: "Planning", items: [
|
|
46
|
+
{ id: "month-end-close", label: "Month-end close", icon: "fin-compliance", status: "No status" },
|
|
47
|
+
{ id: "budget-reforecast", label: "Budget & reforecast", icon: "fin-capital", status: "No status" },
|
|
48
|
+
{ id: "cost-sheets", label: "Cost sheets", icon: "fin-margin", status: "No status" },
|
|
49
|
+
{ id: "approvals-authority", label: "Approvals & authority", icon: "fin-approvals", status: "No status" },
|
|
50
|
+
{ id: "compliance-calendar", label: "Compliance calendar", icon: "fin-compliance", status: "No status" },
|
|
51
|
+
] },
|
|
52
|
+
],
|
|
53
|
+
marketing: [
|
|
54
|
+
{ title: "Performance", items: [
|
|
55
|
+
{ id: "live-ecomm-sales", label: "Live eComm sales by store", icon: "mkt-live-ecomm-sales-by-store", status: "Live" },
|
|
56
|
+
{ id: "paid-media", label: "Paid media", icon: "mkt-paid-media", status: "No status" },
|
|
57
|
+
{ id: "email-sms", label: "Email & SMS", icon: "mkt-email-sms", status: "No status" },
|
|
58
|
+
{ id: "retention-ltv", label: "Retention & LTV", icon: "mkt-retention-ltv", status: "No status" },
|
|
59
|
+
{ id: "social-influencer", label: "Social & influencer", icon: "mkt-social-influencer", status: "No status" },
|
|
60
|
+
{ id: "spend-vs-budget", label: "Spend vs budget", icon: "mkt-spend-vs-budget", status: "No status" },
|
|
61
|
+
] },
|
|
62
|
+
{ title: "Planning", items: [
|
|
63
|
+
{ id: "marketing-calendar", label: "Marketing calendar", icon: "mkt-marketing-calendar", status: "No status" },
|
|
64
|
+
{ id: "social-content-planner", label: "Social media content planner", icon: "mkt-media-content-planner", status: "No status" },
|
|
65
|
+
{ id: "influencer-crm", label: "Influencer CRM", icon: "mkt-influencer-crm", status: "No status" },
|
|
66
|
+
{ id: "franks-kitchen", label: "Influencer Manager", icon: "mkt-frank-s-kitchen", status: "In progress" },
|
|
67
|
+
{ id: "brand-guidelines", label: "Brand guidelines", icon: "mkt-brand-guidelines", status: "In progress" },
|
|
68
|
+
{ id: "npd-validator", label: "NPD validator", icon: "mkt-npd-validator", status: "Live" },
|
|
69
|
+
{ id: "pricing-researcher", label: "Pricing researcher", icon: "mkt-pricing-researcher", status: "Live" },
|
|
70
|
+
{ id: "shelf-simulator", label: "Shelf simulator", icon: "ops-inventory-value", status: "Live" },
|
|
71
|
+
] },
|
|
72
|
+
{ title: "Creative", items: [
|
|
73
|
+
{ id: "image-generator", label: "Artificial Design Studio", icon: "mkt-image-generator", status: "Live" },
|
|
74
|
+
{ id: "retail-image-library", label: "Asset Manager", icon: "mkt-retail-ecom-image-library", status: "Live" },
|
|
75
|
+
{ id: "brand-voice-copywriter", label: "Brand voice copywriter", icon: "mkt-brand-voice-copywriter", status: "Live" },
|
|
76
|
+
] },
|
|
77
|
+
],
|
|
78
|
+
commercial: [
|
|
79
|
+
{ title: "Reporting", items: [
|
|
80
|
+
{ id: "live-sales-by-channel", label: "Live sales by channel", icon: "com-sales-by-channel", status: "Live" },
|
|
81
|
+
{ id: "open-orders", label: "Open orders", icon: "com-open-so-s", status: "Live" },
|
|
82
|
+
{ id: "retailer-sell-out", label: "Retailer sell out (POS)", icon: "com-retailer-sell-out-pos", status: "In progress" },
|
|
83
|
+
{ id: "new-customer-acquisition", label: "New customer acquisition", icon: "com-customer-funnel", status: "To build" },
|
|
84
|
+
{ id: "at-risk-customers", label: "At risk / lapsed customers", icon: "com-at-risk-lapsed-customers", status: "To build" },
|
|
85
|
+
] },
|
|
86
|
+
{ title: "Planning", items: [
|
|
87
|
+
{ id: "customer-scorecard", label: "Customer scorecard", icon: "com-customer-scorecard", status: "To build" },
|
|
88
|
+
{ id: "pricelist-generator", label: "Pricelist generator", icon: "com-pricelist-generator", status: "To build" },
|
|
89
|
+
{ id: "margin-calculator", label: "Margin calculator", icon: "com-margin-calculator", status: "In progress" },
|
|
90
|
+
{ id: "trade-marketing-calendar", label: "Trade marketing calendar", icon: "com-trade-marketing-calendar", status: "To build" },
|
|
91
|
+
{ id: "line-form-populator", label: "New line form populator", icon: "com-line-form-populator", status: "In progress" },
|
|
92
|
+
{ id: "crm", label: "CRM", icon: "com-crm", status: "Live" },
|
|
93
|
+
{ id: "key-accounts", label: "Key accounts", icon: "com-customer-scorecard", status: "Live" },
|
|
94
|
+
] },
|
|
95
|
+
],
|
|
96
|
+
operations: [
|
|
97
|
+
{ title: "Reporting", items: [
|
|
98
|
+
{ id: "inventory-health", label: "Inventory health", icon: "ops-inventory-health", status: "Live" },
|
|
99
|
+
{ id: "out-of-stocks", label: "Out of stocks", icon: "ops-oos", status: "Live" },
|
|
100
|
+
{ id: "forecast-accuracy", label: "Forecast accuracy", icon: "ops-forecast-accuracy", status: "In progress" },
|
|
101
|
+
{ id: "open-purchase-orders", label: "Open purchase orders", icon: "ops-open-po-s", status: "Live" },
|
|
102
|
+
{ id: "shipment-tracker", label: "Shipment tracker", icon: "ops-shipment-tracker", status: "Live" },
|
|
103
|
+
{ id: "customer-otif", label: "Customer OTIF", icon: "ops-customer-otif", status: "To build" },
|
|
104
|
+
{ id: "inventory-value", label: "Inventory value by item", icon: "ops-inventory-value", status: "Live" },
|
|
105
|
+
] },
|
|
106
|
+
{ title: "Planning", items: [
|
|
107
|
+
{ id: "action-queue", label: "Action queue", icon: "ops-action-queue", status: "Live" },
|
|
108
|
+
{ id: "demand-planning", label: "Demand planning", icon: "ops-demand-plan", status: "In progress" },
|
|
109
|
+
{ id: "ordering-tool", label: "Ordering tool", icon: "ops-order-planing", status: "Live" },
|
|
110
|
+
{ id: "carton-label-generator", label: "Carton label generator", icon: "ops-carton-label-generator", status: "Live" },
|
|
111
|
+
{ id: "pm-copilot", label: "PM Copilot", icon: "hub-tasks", status: "Live" },
|
|
112
|
+
{ id: "candidate-hub", label: "Candidate hub", icon: "hub-accounts", status: "Live" },
|
|
113
|
+
] },
|
|
114
|
+
],
|
|
115
|
+
};
|
|
116
|
+
/* Ops Hub is linked, not federated (CONTRACT.md): its catalogue row decides
|
|
117
|
+
who sees its tools live; the fixed address serves frames off the core. */
|
|
118
|
+
const OPS_HUB = "https://frankhub.lovable.app";
|
|
119
|
+
const opsHub = (path) => ({ app: "ops_hub", url: OPS_HUB, path });
|
|
120
|
+
/**
|
|
121
|
+
* Where the tools go: every Live tool, and the tools whose app is already in
|
|
122
|
+
* the catalogue whatever the map says of them (Influencer Manager, Marketing
|
|
123
|
+
* calendar, Paid media), so every app the app switcher offers is reachable
|
|
124
|
+
* from the menu too. Every link opens in the same tab. Pricing researcher and
|
|
125
|
+
* Brand voice copywriter have no app to open yet, so they stay unlinked
|
|
126
|
+
* ("Live, not linked from the Hub yet"). The Hub itself (smart_comms_hub) is
|
|
127
|
+
* the rail's Hub, not a row.
|
|
128
|
+
*/
|
|
129
|
+
export const OS_TOOL_LINKS = {
|
|
130
|
+
"live-ecomm-sales": { app: "alive_reporting" },
|
|
131
|
+
"paid-media": { app: "ad_management" },
|
|
132
|
+
"marketing-calendar": { app: "content_calendar" },
|
|
133
|
+
"franks-kitchen": { app: "frank_kitchen" },
|
|
134
|
+
"npd-validator": { app: "product_idea_validator" },
|
|
135
|
+
"pricing-researcher": {},
|
|
136
|
+
"shelf-simulator": { app: "shelf_simulator" },
|
|
137
|
+
"image-generator": { app: "frank_create" },
|
|
138
|
+
"retail-image-library": { app: "asset_portal" },
|
|
139
|
+
"brand-voice-copywriter": {},
|
|
140
|
+
"live-sales-by-channel": opsHub("/sales-dashboard"),
|
|
141
|
+
"open-orders": opsHub("/customer-orders"),
|
|
142
|
+
"crm": { app: "enxgy_crm", url: "https://e-crm.autosolutions.app" },
|
|
143
|
+
"key-accounts": { app: "key_accounts", url: "https://key-accounts.lovable.app" },
|
|
144
|
+
"inventory-health": opsHub("/inventory-health"),
|
|
145
|
+
"out-of-stocks": opsHub("/inventory-health?view=oos"),
|
|
146
|
+
"open-purchase-orders": opsHub("/po-pipeline"),
|
|
147
|
+
"shipment-tracker": opsHub("/shipment-tracker"),
|
|
148
|
+
"inventory-value": opsHub("/inventory-health?view=valuation"),
|
|
149
|
+
"action-queue": opsHub("/action-queue"),
|
|
150
|
+
"ordering-tool": opsHub("/ordering"),
|
|
151
|
+
"carton-label-generator": { app: "label_maker", url: "https://label-maker-app.lovable.app" },
|
|
152
|
+
"pm-copilot": { app: "pm_copilot", url: "https://pm-copilot.autosolutions.app" },
|
|
153
|
+
"candidate-hub": { app: "candidate_hub" },
|
|
154
|
+
};
|
|
155
|
+
/* Each tool's status in the map, for catalogueLinks. */
|
|
156
|
+
const STATUS = new Map(Object.values(OS_MENU).flatMap((groups) => groups.flatMap((group) => group.items.map((tool) => [tool.id, tool.status]))));
|
|
157
|
+
/** The Hub's own pages, for the rail's Hub, Admin and Settings rows in other apps. */
|
|
158
|
+
export const HUB_PATHS = {
|
|
159
|
+
home: "/comms/overview",
|
|
160
|
+
admin: "/admin",
|
|
161
|
+
settings: "/comms/settings",
|
|
162
|
+
};
|
|
163
|
+
/** Why a row is locked. A tool whose status is In progress or To build says so instead. */
|
|
164
|
+
export const HINTS = {
|
|
165
|
+
locked: "Ask your company admin to switch this on for you",
|
|
166
|
+
notBuilt: "Not built yet",
|
|
167
|
+
notLinked: "Live, not linked from the Hub yet",
|
|
168
|
+
};
|
|
169
|
+
/** The rail footer: Admin (for someone who manages something), Settings, then Sign out, always last. */
|
|
170
|
+
export function osFooter({ admin = false } = {}) {
|
|
171
|
+
return [
|
|
172
|
+
...(admin ? [{ id: "admin", label: "Admin", icon: "fin-approvals" }] : []),
|
|
173
|
+
{ id: "settings", label: "Settings", icon: "settings" },
|
|
174
|
+
{ id: "signout", label: "Sign out", icon: "signout" },
|
|
175
|
+
];
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Tool id to address, for the tools with a fixed `url`: what a frame off the
|
|
179
|
+
* core, which has no catalogue to ask, can link to. No tenant hint.
|
|
180
|
+
*/
|
|
181
|
+
export function staticLinks() {
|
|
182
|
+
const out = {};
|
|
183
|
+
for (const [tool, link] of Object.entries(OS_TOOL_LINKS))
|
|
184
|
+
if (link.url)
|
|
185
|
+
out[tool] = joinPath(link.url, link.path);
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Tool id to address, and tool id to the reason a row is off, for
|
|
190
|
+
* OsWorkspaceFrame to pass to osFrame. `apps` is os_context().apps: the apps
|
|
191
|
+
* this person holds in the acting company, as the app switcher lists them.
|
|
192
|
+
* For a tool whose OS_TOOL_LINKS entry names an app:
|
|
193
|
+
* - held, with an address: linked to it (plus `path`), with the company as
|
|
194
|
+
* ?tenant=, whatever status the map gives the tool, because the switcher
|
|
195
|
+
* already offers that app;
|
|
196
|
+
* - held, not deployed yet (no address): a Live tool reads "Live, not linked
|
|
197
|
+
* from the Hub yet"; any other keeps the map's own status;
|
|
198
|
+
* - not held: a Live tool is locked ("Ask your company admin to switch this
|
|
199
|
+
* on for you"); any other keeps the map's own status (Not built yet, In
|
|
200
|
+
* progress, To build).
|
|
201
|
+
* A fixed `url` is never consulted here: it is no way round the catalogue.
|
|
202
|
+
* Tools with no app keep osFrame's own rules. Links are final: osFrame adds
|
|
203
|
+
* nothing to them.
|
|
204
|
+
*/
|
|
205
|
+
export function catalogueLinks(apps, tenantSlug = null) {
|
|
206
|
+
const links = {};
|
|
207
|
+
const locked = {};
|
|
208
|
+
for (const [tool, link] of Object.entries(OS_TOOL_LINKS)) {
|
|
209
|
+
if (!link.app)
|
|
210
|
+
continue;
|
|
211
|
+
const app = apps.find((candidate) => candidate.key === link.app);
|
|
212
|
+
if (app?.url)
|
|
213
|
+
links[tool] = withTenantHint(joinPath(app.url, link.path), tenantSlug);
|
|
214
|
+
else if (STATUS.get(tool) !== "Live")
|
|
215
|
+
continue; // the map's own status says it
|
|
216
|
+
else if (app)
|
|
217
|
+
locked[tool] = HINTS.notLinked;
|
|
218
|
+
else
|
|
219
|
+
locked[tool] = HINTS.locked;
|
|
220
|
+
}
|
|
221
|
+
return { links, locked };
|
|
222
|
+
}
|
|
223
|
+
const ORIGIN = "http://os.invalid";
|
|
224
|
+
function joinPath(base, path) {
|
|
225
|
+
if (!path)
|
|
226
|
+
return base;
|
|
227
|
+
try {
|
|
228
|
+
return new URL(path, base.endsWith("/") ? base : `${base}/`).toString();
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
return base;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function trimmed(pathname) {
|
|
235
|
+
return pathname.replace(/\/+$/, "") || "/";
|
|
236
|
+
}
|
|
237
|
+
/** How specifically `route` claims `location`: [path length, query params], or null when it does not. */
|
|
238
|
+
function claim(route, location) {
|
|
239
|
+
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}/`))
|
|
243
|
+
return null;
|
|
244
|
+
let params = 0;
|
|
245
|
+
for (const [key, value] of wanted.searchParams) {
|
|
246
|
+
if (location.searchParams.get(key) !== value)
|
|
247
|
+
return null;
|
|
248
|
+
params += 1;
|
|
249
|
+
}
|
|
250
|
+
return [path === "/" ? 0 : path.length, params];
|
|
251
|
+
}
|
|
252
|
+
function better(a, b) {
|
|
253
|
+
if (!a)
|
|
254
|
+
return false;
|
|
255
|
+
if (!b)
|
|
256
|
+
return true;
|
|
257
|
+
return a[0] > b[0] || (a[0] === b[0] && a[1] > b[1]);
|
|
258
|
+
}
|
|
259
|
+
function best(routes, location) {
|
|
260
|
+
let top = null;
|
|
261
|
+
for (const route of routes) {
|
|
262
|
+
if (!route)
|
|
263
|
+
continue;
|
|
264
|
+
const score = claim(route, location);
|
|
265
|
+
if (better(score, top))
|
|
266
|
+
top = score;
|
|
267
|
+
}
|
|
268
|
+
return top;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* The frame for one app: the rail, every function's menu for this person and
|
|
272
|
+
* company, the footer, and the only routing logic the frame needs.
|
|
273
|
+
*/
|
|
274
|
+
export function osFrame(options) {
|
|
275
|
+
const { appKey, tools = [], hubItems, links = {}, locked = {}, admin = false, settingsPath, hubUrl = HUB_URL, tenantSlug = null, } = options;
|
|
276
|
+
const isHub = appKey === "hub";
|
|
277
|
+
const homePath = options.homePath ?? (isHub ? HUB_PATHS.home : "/");
|
|
278
|
+
const own = new Map(tools.map((tool) => [tool.id, tool]));
|
|
279
|
+
const toHub = (path) => ({ href: withTenantHint(`${hubUrl}${path}`, tenantSlug), external: true });
|
|
280
|
+
const sections = {};
|
|
281
|
+
if (hubItems && hubItems.length)
|
|
282
|
+
sections["hub"] = hubItems.map((section) => ({ ...section, items: [...section.items] }));
|
|
283
|
+
for (const [fn, groups] of Object.entries(OS_MENU)) {
|
|
284
|
+
sections[fn] = groups.map((group) => ({
|
|
285
|
+
title: group.title,
|
|
286
|
+
items: group.items.map((tool) => {
|
|
287
|
+
const mine = own.get(tool.id);
|
|
288
|
+
const base = { id: tool.id, label: tool.label, icon: tool.icon };
|
|
289
|
+
if (mine)
|
|
290
|
+
return rowFor(base, mine);
|
|
291
|
+
/* A link or a reason from the catalogue outranks the map's status:
|
|
292
|
+
the catalogue knows what this person holds. */
|
|
293
|
+
const href = links[tool.id];
|
|
294
|
+
if (href)
|
|
295
|
+
return { ...base, href };
|
|
296
|
+
const reason = locked[tool.id];
|
|
297
|
+
if (reason)
|
|
298
|
+
return { ...base, disabled: true, title: reason };
|
|
299
|
+
if (tool.status !== "Live")
|
|
300
|
+
return { ...base, disabled: true, title: tool.status === "No status" ? HINTS.notBuilt : tool.status };
|
|
301
|
+
return { ...base, disabled: true, title: HINTS.notLinked };
|
|
302
|
+
}),
|
|
303
|
+
}));
|
|
304
|
+
}
|
|
305
|
+
/* This app's tools the menu map does not have, placed where the app says. */
|
|
306
|
+
const mapped = new Set(Object.values(OS_MENU).flatMap((groups) => groups.flatMap((group) => group.items.map((tool) => tool.id))));
|
|
307
|
+
for (const tool of tools) {
|
|
308
|
+
if (mapped.has(tool.id) || !tool.fn)
|
|
309
|
+
continue;
|
|
310
|
+
const list = sections[tool.fn] ?? (sections[tool.fn] = []);
|
|
311
|
+
const title = tool.section;
|
|
312
|
+
let section = list.find((candidate) => candidate.title === title);
|
|
313
|
+
if (!section) {
|
|
314
|
+
section = title === undefined ? { items: [] } : { title, items: [] };
|
|
315
|
+
list.push(section);
|
|
316
|
+
}
|
|
317
|
+
section.items.push(rowFor({ id: tool.id, label: tool.label ?? tool.id, ...(tool.icon ? { icon: tool.icon } : {}) }, tool));
|
|
318
|
+
}
|
|
319
|
+
const footerItems = osFooter({ admin });
|
|
320
|
+
/* Every place a location can land, most specific claim wins. */
|
|
321
|
+
const claims = [];
|
|
322
|
+
if (settingsPath)
|
|
323
|
+
claims.push({ routes: [settingsPath], spot: { fn: "settings", item: null, tab: null } });
|
|
324
|
+
if (isHub)
|
|
325
|
+
claims.push({ routes: [HUB_PATHS.admin], spot: { fn: "admin", item: null, tab: null } });
|
|
326
|
+
for (const [fn, list] of Object.entries(sections)) {
|
|
327
|
+
for (const section of list) {
|
|
328
|
+
for (const row of section.items) {
|
|
329
|
+
if (row.disabled)
|
|
330
|
+
continue;
|
|
331
|
+
claims.push({ routes: [row.path, ...(row.match ?? [])], spot: { fn, item: row.id, tab: null } });
|
|
332
|
+
for (const tab of flatTabs(row.tabs)) {
|
|
333
|
+
claims.push({ routes: [tab.path, ...(tab.match ?? [])], spot: { fn, item: row.id, tab: tab.id } });
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
const landingFn = tools.map((tool) => fnOf(sections, tool.id)).find((fn) => fn !== undefined);
|
|
339
|
+
const locate = (location) => {
|
|
340
|
+
let url;
|
|
341
|
+
try {
|
|
342
|
+
url = new URL(location, ORIGIN);
|
|
343
|
+
}
|
|
344
|
+
catch {
|
|
345
|
+
url = new URL("/", ORIGIN);
|
|
346
|
+
}
|
|
347
|
+
let top = null;
|
|
348
|
+
let found;
|
|
349
|
+
for (const candidate of claims) {
|
|
350
|
+
const score = best(candidate.routes, url);
|
|
351
|
+
if (better(score, top)) {
|
|
352
|
+
top = score;
|
|
353
|
+
found = candidate.spot;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (found)
|
|
357
|
+
return { ...found };
|
|
358
|
+
/* Nowhere in particular: the Hub's landing, menu closed, or this app's function. */
|
|
359
|
+
if (isHub)
|
|
360
|
+
return { fn: "hub", item: null, tab: null, open: false };
|
|
361
|
+
return { fn: landingFn ?? "hub", item: null, tab: null };
|
|
362
|
+
};
|
|
363
|
+
/* Is `location` already exactly at `path`? */
|
|
364
|
+
const at = (location, path) => {
|
|
365
|
+
try {
|
|
366
|
+
const here = new URL(location, ORIGIN);
|
|
367
|
+
const there = new URL(path, ORIGIN);
|
|
368
|
+
return trimmed(here.pathname) === trimmed(there.pathname) && here.search === there.search;
|
|
369
|
+
}
|
|
370
|
+
catch {
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
const targetFor = (state, location) => {
|
|
375
|
+
const fn = state.fn.id;
|
|
376
|
+
const here = locate(location);
|
|
377
|
+
const again = state.reselect === true;
|
|
378
|
+
const internal = (href, spot) => (here.fn === spot.fn && here.item === spot.item && here.tab === spot.tab ? null : { href, external: false });
|
|
379
|
+
/* A path of this app, unless the URL is exactly there already. */
|
|
380
|
+
const goTo = (href) => (at(location, href) ? null : { href, external: false });
|
|
381
|
+
if (fn === "settings") {
|
|
382
|
+
const path = settingsPath ?? (isHub ? HUB_PATHS.settings : undefined);
|
|
383
|
+
if (!path)
|
|
384
|
+
return toHub(HUB_PATHS.settings);
|
|
385
|
+
return goTo(path);
|
|
386
|
+
}
|
|
387
|
+
if (fn === "admin") {
|
|
388
|
+
if (!isHub)
|
|
389
|
+
return toHub(HUB_PATHS.admin);
|
|
390
|
+
return again ? goTo(HUB_PATHS.admin) : internal(HUB_PATHS.admin, { fn, item: null, tab: null });
|
|
391
|
+
}
|
|
392
|
+
const row = state.item ? (sections[fn] ?? []).flatMap((section) => section.items).find((r) => r.id === state.item?.id) : undefined;
|
|
393
|
+
if (!row) {
|
|
394
|
+
if (fn !== "hub")
|
|
395
|
+
return null; // opening a function's menu is not a navigation
|
|
396
|
+
if (!isHub)
|
|
397
|
+
return toHub(HUB_PATHS.home);
|
|
398
|
+
/* The Hub: stay anywhere on the landing's own ground, else land on it. */
|
|
399
|
+
const landing = locate(homePath);
|
|
400
|
+
return here.fn === landing.fn && here.item === landing.item ? null : { href: homePath, external: false };
|
|
401
|
+
}
|
|
402
|
+
if (row.disabled)
|
|
403
|
+
return null; // locked: the frame never reports a click on it, and it goes nowhere
|
|
404
|
+
const tab = state.tab ? flatTabs(row.tabs).find((t) => t.id === state.tab?.id) : undefined;
|
|
405
|
+
/* A click on the tab or row the frame already shows: its own path, from
|
|
406
|
+
anywhere under it (a draft filed under Requests, the Agent's threads),
|
|
407
|
+
and nothing when the URL is exactly that path. A tab with no path is
|
|
408
|
+
page state, with no page to go back to. A row that carries its own tab
|
|
409
|
+
row in the page (`menu: false`, the Hub's Smart Comms) keeps the rule
|
|
410
|
+
below: its page's tabs are all its own ground. */
|
|
411
|
+
if (again && row.menu !== false) {
|
|
412
|
+
if (tab)
|
|
413
|
+
return tab.path ? goTo(tab.path) : null;
|
|
414
|
+
if (row.path)
|
|
415
|
+
return goTo(row.path);
|
|
416
|
+
}
|
|
417
|
+
if (tab?.path)
|
|
418
|
+
return internal(tab.path, { fn, item: row.id, tab: tab.id });
|
|
419
|
+
if (row.path)
|
|
420
|
+
return internal(row.path, { fn, item: row.id, tab: here.fn === fn && here.item === row.id ? here.tab : null });
|
|
421
|
+
if (row.href)
|
|
422
|
+
return { href: row.href, external: true };
|
|
423
|
+
return null;
|
|
424
|
+
};
|
|
425
|
+
return { functions: OS_FUNCTIONS, sections, footerItems, homeFunction: "hub", locate, targetFor };
|
|
426
|
+
}
|
|
427
|
+
function rowFor(base, tool) {
|
|
428
|
+
const row = { ...base };
|
|
429
|
+
if (tool.path)
|
|
430
|
+
row.path = tool.path;
|
|
431
|
+
if (tool.match)
|
|
432
|
+
row.match = tool.match;
|
|
433
|
+
if (tool.tabs)
|
|
434
|
+
row.tabs = tool.tabs;
|
|
435
|
+
if (tool.menu !== undefined)
|
|
436
|
+
row.menu = tool.menu;
|
|
437
|
+
if (tool.badge !== undefined)
|
|
438
|
+
row.badge = tool.badge;
|
|
439
|
+
return row;
|
|
440
|
+
}
|
|
441
|
+
/** Tabs as one list, whether given flat or in groups. */
|
|
442
|
+
function flatTabs(tabs) {
|
|
443
|
+
if (!tabs)
|
|
444
|
+
return [];
|
|
445
|
+
return tabs.flatMap((tab) => ("items" in tab && Array.isArray(tab.items) ? tab.items : [tab]));
|
|
446
|
+
}
|
|
447
|
+
function fnOf(sections, id) {
|
|
448
|
+
for (const [fn, list] of Object.entries(sections)) {
|
|
449
|
+
if (list.some((section) => section.items.some((row) => row.id === id)))
|
|
450
|
+
return fn;
|
|
451
|
+
}
|
|
452
|
+
return undefined;
|
|
453
|
+
}
|
package/dist/server.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* project accepts.
|
|
9
9
|
*/
|
|
10
10
|
import { createClient } from "@supabase/supabase-js";
|
|
11
|
-
import { corePublishableKey, coreProjectRef, coreUrl } from "./config";
|
|
12
|
-
import { joinChunks, sharedSessionCookieName } from "./session";
|
|
11
|
+
import { corePublishableKey, coreProjectRef, coreUrl } from "./config.js";
|
|
12
|
+
import { joinChunks, sharedSessionCookieName } from "./session.js";
|
|
13
13
|
function clientForToken(token, schema) {
|
|
14
14
|
return createClient(coreUrl(), corePublishableKey(), {
|
|
15
15
|
...(schema ? { db: { schema } } : {}),
|
package/dist/session.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* cold load, so opening the hub in a fresh tab silently signed the user out of
|
|
19
19
|
* every other app.
|
|
20
20
|
*/
|
|
21
|
-
import { PARENT_DOMAIN } from "./config";
|
|
21
|
+
import { PARENT_DOMAIN } from "./config.js";
|
|
22
22
|
/** Cookies cap around 4KB each, and sessions can exceed that, so they chunk. */
|
|
23
23
|
const CHUNK = 3200;
|
|
24
24
|
const MAX_CHUNKS = 8;
|
package/dist/url.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
/**
|
|
6
|
+
* Apps show the acting company's branding, so a link carries it as a hint.
|
|
7
|
+
* Access is still decided by the core; this only saves a round trip.
|
|
8
|
+
*/
|
|
9
|
+
export declare function withTenantHint(url: string, slug: string | null): string;
|
package/dist/url.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
/**
|
|
6
|
+
* Apps show the acting company's branding, so a link carries it as a hint.
|
|
7
|
+
* Access is still decided by the core; this only saves a round trip.
|
|
8
|
+
*/
|
|
9
|
+
export function withTenantHint(url, slug) {
|
|
10
|
+
if (!slug)
|
|
11
|
+
return url;
|
|
12
|
+
try {
|
|
13
|
+
const parsed = new URL(url);
|
|
14
|
+
parsed.searchParams.set("tenant", slug);
|
|
15
|
+
return parsed.toString();
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return url;
|
|
19
|
+
}
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autosolutions-os",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
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",
|
|
@@ -9,18 +9,23 @@
|
|
|
9
9
|
"exports": {
|
|
10
10
|
".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
|
|
11
11
|
"./server": { "types": "./dist/server.d.ts", "import": "./dist/server.js" },
|
|
12
|
+
"./nav": { "types": "./dist/nav.d.ts", "import": "./dist/nav.js" },
|
|
13
|
+
"./frame": { "types": "./dist/frame.d.ts", "import": "./dist/frame.js" },
|
|
12
14
|
"./chrome.css": "./dist/chrome.css"
|
|
13
15
|
},
|
|
14
|
-
"files": ["dist"],
|
|
16
|
+
"files": ["dist", "CHANGELOG.md"],
|
|
15
17
|
"scripts": {
|
|
16
18
|
"build": "tsc -p tsconfig.build.json && cp src/chrome.css dist/chrome.css",
|
|
17
|
-
"typecheck": "tsc --noEmit"
|
|
19
|
+
"typecheck": "tsc --noEmit",
|
|
20
|
+
"test": "bun test"
|
|
18
21
|
},
|
|
19
22
|
"peerDependencies": {
|
|
20
23
|
"@supabase/supabase-js": ">=2.40.0",
|
|
24
|
+
"autosolutions-design-system": ">=6.3.0 <7",
|
|
21
25
|
"react": ">=18"
|
|
22
26
|
},
|
|
23
27
|
"peerDependenciesMeta": {
|
|
28
|
+
"autosolutions-design-system": { "optional": true },
|
|
24
29
|
"react": { "optional": true }
|
|
25
30
|
},
|
|
26
31
|
"devDependencies": {
|