autosolutions-os 0.2.3 → 0.2.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 +191 -0
- package/README.md +67 -16
- package/dist/chrome.d.ts +4 -1
- package/dist/chrome.js +10 -16
- package/dist/client.js +4 -1
- package/dist/context.d.ts +6 -33
- package/dist/context.js +22 -49
- package/dist/contextCache.d.ts +50 -0
- package/dist/contextCache.js +224 -0
- package/dist/frame.d.ts +47 -13
- package/dist/frame.js +102 -26
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/nav.d.ts +12 -2
- package/dist/nav.js +37 -12
- package/dist/session.d.ts +33 -6
- package/dist/session.js +443 -25
- package/dist/url.d.ts +16 -4
- package/dist/url.js +29 -2
- package/package.json +2 -2
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
|
-
/**
|
|
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
|
-
/**
|
|
238
|
-
|
|
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
|
|
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;
|
package/dist/session.d.ts
CHANGED
|
@@ -1,16 +1,43 @@
|
|
|
1
1
|
/** Reassemble a chunked value from any source of name/value pairs. */
|
|
2
2
|
export declare function joinChunks(key: string, read: (name: string) => string | undefined): string | null;
|
|
3
3
|
/**
|
|
4
|
-
* Copy a session that arrived from another app into this origin's storage
|
|
5
|
-
*
|
|
6
|
-
* calls it at module
|
|
4
|
+
* Copy a session that arrived from another app into this origin's storage,
|
|
5
|
+
* or share this origin's when it is the newer one. Must run before the
|
|
6
|
+
* Supabase client reads its storage, so `createOsClient` calls it at module
|
|
7
|
+
* scope.
|
|
7
8
|
*/
|
|
8
9
|
export declare function adoptSharedSession(projectRef: string): void;
|
|
9
|
-
|
|
10
|
-
export declare function publishSessionChanges(client: {
|
|
10
|
+
type AuthEvents = {
|
|
11
11
|
auth: {
|
|
12
|
-
onAuthStateChange: (cb: (event: string
|
|
12
|
+
onAuthStateChange: (cb: (event: string, session: {
|
|
13
|
+
user?: {
|
|
14
|
+
id?: string;
|
|
15
|
+
} | null;
|
|
16
|
+
} | null) => void) => unknown;
|
|
13
17
|
};
|
|
18
|
+
};
|
|
19
|
+
/** Keep the shared cookie in step with this app's session. */
|
|
20
|
+
export declare function publishSessionChanges(client: AuthEvents, projectRef: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* Keep a running page on the newest session. Call it once, right after
|
|
23
|
+
* creating the client and calling `publishSessionChanges`; `createOsClient`
|
|
24
|
+
* does. It:
|
|
25
|
+
*
|
|
26
|
+
* - takes the newest session whenever the tab comes back into view or to
|
|
27
|
+
* focus, before supabase-js's own wake-up (which refreshes) reads it;
|
|
28
|
+
* - takes it whenever supabase-js reads its session, which it does before
|
|
29
|
+
* every refresh, so a refresh never uses a token older than the shared one
|
|
30
|
+
* (while one is in flight, a newer copy of the same person waits for the
|
|
31
|
+
* next read, so supabase-js keeps that refresh);
|
|
32
|
+
* - makes `client.auth.signOut()` (any scope but "others") the sign-out that
|
|
33
|
+
* clears the shared session everywhere.
|
|
34
|
+
*
|
|
35
|
+
* Every part is best effort: where a part cannot be installed, the others
|
|
36
|
+
* still work, and nothing here can stop the client from signing in.
|
|
37
|
+
*/
|
|
38
|
+
export declare function followSharedSession(client: {
|
|
39
|
+
auth: object;
|
|
14
40
|
}, projectRef: string): void;
|
|
15
41
|
/** The storage key, for server code that needs to find the cookie by name. */
|
|
16
42
|
export declare function sharedSessionCookieName(projectRef: string): string;
|
|
43
|
+
export {};
|