@burtson-labs/bandit-nav 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may accept and charge a
167
+ fee for acceptance of support, warranty, indemnity, or other liability
168
+ obligations and/or rights consistent with this License. However, in
169
+ accepting such obligations, You may act only on Your own behalf
170
+ and on Your sole responsibility, not on behalf of any other Contributor,
171
+ and only if You agree to indemnify, defend, and hold each Contributor
172
+ harmless for any liability incurred by, or claims asserted against,
173
+ such Contributor by reason of your accepting any such warranty or
174
+ additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Burtson Labs
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,63 @@
1
- # Temporary Holding Version
1
+ # @burtson-labs/bandit-nav
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Bandit product navigation: **Chat · Agents · Artifacts · Settings**, one
4
+ implementation rendered by banditailabs.com (web and the Capacitor apps) and
5
+ stealth.banditailabs.com. Each host says which site it is and where its own
6
+ settings live; the package decides which items are local routes and which
7
+ cross to the other site. Cross-site items are ordinary same-tab links, and
8
+ single sign-on between the two sites makes the destination open signed in.
9
+
10
+ Agents and Artifacts are Stealth, and Stealth access is membership in a
11
+ Stealth organization: a user outside every organization sees **Chat ·
12
+ Settings** only, so the bar never offers a link that dead-ends.
13
+
14
+ ```tsx
15
+ import {
16
+ ProductNav,
17
+ productNavActive,
18
+ productNavItems,
19
+ stealthAccessFromToken,
20
+ } from '@burtson-labs/bandit-nav';
21
+
22
+ const items = productNavItems({
23
+ site: 'stealth',
24
+ settingsPath: '/settings',
25
+ stealthAccess: stealthAccessFromToken(accessToken),
26
+ });
27
+ const active = productNavActive(items, location.pathname);
28
+
29
+ <ProductNav
30
+ items={items}
31
+ active={active}
32
+ onNavigate={(item, event) => {
33
+ if (item.external) return; // plain link to the other site
34
+ event.preventDefault();
35
+ navigate(item.href); // the host's router
36
+ }}
37
+ />;
38
+ ```
39
+
40
+ - `productNavItems({ site, settingsPath, chatOrigin?, stealthOrigin?, artifactsHref?, stealthAccess? })`
41
+ returns the items in display order: all four with `stealthAccess: true`,
42
+ Chat and Settings otherwise (the default, so an unknown session fails
43
+ closed). `artifactsHref` is for a host that serves the shared artifacts
44
+ page itself (default: Stealth's page).
45
+ - `stealthAccessFromToken(token)` / `stealthAccessFromClaims(claims)` apply
46
+ the access rule to the host's access token: true when it carries a
47
+ non-empty `stealthTenants` array (AuthApi stamps the user's active Stealth
48
+ memberships on platform tokens) or an organization session's `tenant_sso`.
49
+ The token is decoded, not verified: this decides what the bar shows, and
50
+ the Stealth APIs enforce membership themselves. Membership changes show
51
+ with the next token the host receives.
52
+ - `productNavActive(items, pathname, aliases?)` picks the item the page
53
+ belongs to; `aliases` adds host paths to a section (account pages under
54
+ Settings, for instance).
55
+ - `ProductNav` is a `<nav>` of links with `aria-current="page"` on the active
56
+ item. `density="compact"` for phone-width bars. It injects one small
57
+ stylesheet on first render and styles itself from the host's
58
+ `--foreground`, `--muted-foreground`, `--muted` and `--ring` tokens
59
+ (override with `--bandit-nav-foreground`, `--bandit-nav-muted`,
60
+ `--bandit-nav-hover`, `--bandit-nav-ring`). No fills, borders or shadows:
61
+ it is meant to sit inside the host's existing header.
62
+
63
+ Peer dependency: `react` 18 or 19. No router, no UI kit.
@@ -0,0 +1,23 @@
1
+ import type { CSSProperties, MouseEvent } from 'react';
2
+ import type { ProductNavItem, ProductNavItemId } from './items.js';
3
+ export interface ProductNavProps {
4
+ items: readonly ProductNavItem[];
5
+ /** The section the current page belongs to; it is marked `aria-current`. */
6
+ active?: ProductNavItemId | null;
7
+ /**
8
+ * Called for a plain left click on an item (not for modified clicks, which
9
+ * the browser handles: new tab, new window). A host that routes locally
10
+ * calls `event.preventDefault()` and navigates itself; cross-site items are
11
+ * ordinary links either way.
12
+ */
13
+ onNavigate?: (item: ProductNavItem, event: MouseEvent<HTMLAnchorElement>) => void;
14
+ /** Tighter spacing for phone-width bars. */
15
+ density?: 'regular' | 'compact';
16
+ /** Accessible name of the landmark. */
17
+ label?: string;
18
+ className?: string;
19
+ style?: CSSProperties;
20
+ }
21
+ /** Add the stylesheet to the document once; a no-op off the DOM. */
22
+ export declare function ensureProductNavStyles(doc?: Document | undefined): void;
23
+ export declare function ProductNav({ items, active, onNavigate, density, label, className, style, }: ProductNavProps): import("react").JSX.Element;
@@ -0,0 +1,47 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ const STYLE_ID = 'bandit-nav-styles';
3
+ /*
4
+ * Neutral by design: text in the host's foreground tokens, the active item
5
+ * underlined in the current colour, hover as a surface change. No fills,
6
+ * borders or shadows, so the bar sits in either site's header unchanged.
7
+ * Hosts can tune through the --bandit-nav-* properties; the fallbacks are the
8
+ * Burtson UI tokens both sites define, then plain inheritance.
9
+ */
10
+ const CSS = `
11
+ .bandit-nav{display:flex;align-items:center;gap:2px;min-width:0;max-width:100%;overflow-x:auto;scrollbar-width:none;font:inherit}
12
+ .bandit-nav::-webkit-scrollbar{display:none}
13
+ .bandit-nav__item{position:relative;display:inline-flex;align-items:center;flex:0 0 auto;height:36px;padding:0 10px;border-radius:6px;color:var(--bandit-nav-muted,var(--muted-foreground,inherit));text-decoration:none;font-size:14px;font-weight:500;line-height:1;white-space:nowrap;transition:color 120ms ease,background-color 120ms ease}
14
+ .bandit-nav__item:hover{color:var(--bandit-nav-foreground,var(--foreground,inherit));background:var(--bandit-nav-hover,var(--muted,rgba(127,127,127,0.12)))}
15
+ .bandit-nav__item:focus-visible{outline:2px solid var(--bandit-nav-ring,var(--ring,currentColor));outline-offset:2px}
16
+ .bandit-nav__item[aria-current="page"]{color:var(--bandit-nav-foreground,var(--foreground,inherit))}
17
+ .bandit-nav__item[aria-current="page"]::after{content:"";position:absolute;left:10px;right:10px;bottom:3px;height:2px;border-radius:1px;background:currentColor}
18
+ .bandit-nav--compact{gap:0}
19
+ .bandit-nav--compact .bandit-nav__item{height:32px;padding:0 8px;font-size:13px}
20
+ .bandit-nav--compact .bandit-nav__item[aria-current="page"]::after{left:8px;right:8px;bottom:2px}
21
+ `;
22
+ /** Add the stylesheet to the document once; a no-op off the DOM. */
23
+ export function ensureProductNavStyles(doc = typeof document === 'undefined' ? undefined : document) {
24
+ if (!doc || doc.getElementById(STYLE_ID))
25
+ return;
26
+ const style = doc.createElement('style');
27
+ style.id = STYLE_ID;
28
+ style.textContent = CSS;
29
+ doc.head.appendChild(style);
30
+ }
31
+ const isPlainLeftClick = (event) => event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey;
32
+ export function ProductNav({ items, active = null, onNavigate, density = 'regular', label = 'Bandit', className, style, }) {
33
+ ensureProductNavStyles();
34
+ const classes = [
35
+ 'bandit-nav',
36
+ density === 'compact' ? 'bandit-nav--compact' : '',
37
+ className ?? '',
38
+ ]
39
+ .filter(Boolean)
40
+ .join(' ');
41
+ return (_jsx("nav", { "aria-label": label, className: classes, style: style, "data-bandit-nav": "", children: items.map((item) => (_jsx("a", { className: "bandit-nav__item", href: item.href, "data-item": item.id, "data-external": item.external ? '' : undefined, "aria-current": item.id === active ? 'page' : undefined, onClick: onNavigate
42
+ ? (event) => {
43
+ if (isPlainLeftClick(event))
44
+ onNavigate(item, event);
45
+ }
46
+ : undefined, children: item.label }, item.id))) }));
47
+ }
@@ -0,0 +1,2 @@
1
+ export { PRODUCT_ORIGINS, STEALTH_SECTIONS, decodeJwtPayload, productNavActive, productNavItems, stealthAccessFromClaims, stealthAccessFromToken, type ProductNavItem, type ProductNavItemId, type ProductNavOptions, type ProductSite, } from './items.js';
2
+ export { ProductNav, ensureProductNavStyles, type ProductNavProps } from './ProductNav.js';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { PRODUCT_ORIGINS, STEALTH_SECTIONS, decodeJwtPayload, productNavActive, productNavItems, stealthAccessFromClaims, stealthAccessFromToken, } from './items.js';
2
+ export { ProductNav, ensureProductNavStyles } from './ProductNav.js';
@@ -0,0 +1,68 @@
1
+ /**
2
+ * The four product sections and where each one lives. Both sites render the
3
+ * same list; the only difference is which items are local routes and which
4
+ * cross to the other origin (a plain link there, single sign-on does the rest).
5
+ */
6
+ export type ProductNavItemId = 'chat' | 'agents' | 'artifacts' | 'settings';
7
+ /** Which host is rendering the bar. */
8
+ export type ProductSite = 'chat' | 'stealth';
9
+ export interface ProductNavItem {
10
+ id: ProductNavItemId;
11
+ label: string;
12
+ /** A path on the host (starts with `/`) or an absolute URL on the other site. */
13
+ href: string;
14
+ /** True when `href` leaves the host's origin. */
15
+ external: boolean;
16
+ }
17
+ export declare const PRODUCT_ORIGINS: {
18
+ readonly chat: "https://banditailabs.com";
19
+ readonly stealth: "https://stealth.banditailabs.com";
20
+ };
21
+ export interface ProductNavOptions {
22
+ site: ProductSite;
23
+ /** The host's own settings route, e.g. `/management` or `/settings`. */
24
+ settingsPath: string;
25
+ /** Overrides for local development. */
26
+ chatOrigin?: string;
27
+ stealthOrigin?: string;
28
+ /**
29
+ * Where Artifacts opens. By default it is Stealth's page (local there,
30
+ * cross-site from banditailabs.com); a host that serves the shared artifacts
31
+ * page itself passes its own path.
32
+ */
33
+ artifactsHref?: string;
34
+ /**
35
+ * Whether the signed-in user may use Stealth (Agents and Artifacts): a
36
+ * member of at least one Stealth organization. Off or omitted, the bar is
37
+ * Chat and Settings only, so a user without Stealth never gets a link that
38
+ * dead-ends. Derive it with `stealthAccessFromToken` (or
39
+ * `stealthAccessFromClaims`); unknown means no.
40
+ */
41
+ stealthAccess?: boolean;
42
+ }
43
+ /** The Stealth-only sections, shown to members of a Stealth organization. */
44
+ export declare const STEALTH_SECTIONS: readonly ProductNavItemId[];
45
+ /**
46
+ * The canonical list, in display order: Chat, Agents, Artifacts, Settings with
47
+ * `stealthAccess`, Chat and Settings without it.
48
+ */
49
+ export declare function productNavItems(options: ProductNavOptions): ProductNavItem[];
50
+ /**
51
+ * The access rule, from a token's claims: Stealth access is membership in a
52
+ * Stealth organization. AuthApi puts `stealthTenants` (the organizations
53
+ * where the user is an active member) on platform tokens, and an organization
54
+ * session token names its organization in `tenant_sso`. Anything else, or a
55
+ * value of the wrong shape, is no access. A display decision only: the
56
+ * Stealth APIs enforce membership themselves.
57
+ */
58
+ export declare function stealthAccessFromClaims(claims: unknown): boolean;
59
+ /** The payload of a JWT, unverified; null when it is not one. */
60
+ export declare function decodeJwtPayload(token: string | null | undefined): unknown;
61
+ /** `stealthAccessFromClaims` for the host's access token; no token is no access. */
62
+ export declare function stealthAccessFromToken(token: string | null | undefined): boolean;
63
+ /**
64
+ * Which item the current page belongs to: the local item whose path is the
65
+ * pathname or one of its ancestors, or one of the host's extra paths for it
66
+ * (`aliases`, e.g. the account pages under Settings). Null on any other page.
67
+ */
68
+ export declare function productNavActive(items: readonly ProductNavItem[], pathname: string, aliases?: Partial<Record<ProductNavItemId, readonly string[]>>): ProductNavItemId | null;
package/dist/items.js ADDED
@@ -0,0 +1,105 @@
1
+ export const PRODUCT_ORIGINS = {
2
+ chat: 'https://banditailabs.com',
3
+ stealth: 'https://stealth.banditailabs.com',
4
+ };
5
+ // Section paths are kept without their leading slash and joined at run time:
6
+ // the banditailabs.com store build scans its bundle for route literals it does
7
+ // not serve, and `/agents` or `/artifacts` would read as one even though they
8
+ // only ever appear here as part of an absolute URL to the other site.
9
+ const SECTION_PATHS = {
10
+ chat: 'chat',
11
+ agents: 'agents',
12
+ artifacts: 'artifacts',
13
+ };
14
+ const LABELS = {
15
+ chat: 'Chat',
16
+ agents: 'Agents',
17
+ artifacts: 'Artifacts',
18
+ settings: 'Settings',
19
+ };
20
+ const trimSlash = (origin) => origin.replace(/\/+$/, '');
21
+ const hrefFor = (section, home, site, origin) => {
22
+ const path = `/${SECTION_PATHS[section]}`;
23
+ return home === site ? path : `${trimSlash(origin)}${path}`;
24
+ };
25
+ /** The Stealth-only sections, shown to members of a Stealth organization. */
26
+ export const STEALTH_SECTIONS = ['agents', 'artifacts'];
27
+ /**
28
+ * The canonical list, in display order: Chat, Agents, Artifacts, Settings with
29
+ * `stealthAccess`, Chat and Settings without it.
30
+ */
31
+ export function productNavItems(options) {
32
+ const chatOrigin = options.chatOrigin ?? PRODUCT_ORIGINS.chat;
33
+ const stealthOrigin = options.stealthOrigin ?? PRODUCT_ORIGINS.stealth;
34
+ const entries = [
35
+ ['chat', hrefFor('chat', 'chat', options.site, chatOrigin)],
36
+ ['agents', hrefFor('agents', 'stealth', options.site, stealthOrigin)],
37
+ [
38
+ 'artifacts',
39
+ options.artifactsHref ?? hrefFor('artifacts', 'stealth', options.site, stealthOrigin),
40
+ ],
41
+ ['settings', options.settingsPath],
42
+ ];
43
+ return entries
44
+ .filter(([id]) => options.stealthAccess === true || !STEALTH_SECTIONS.includes(id))
45
+ .map(([id, href]) => ({
46
+ id,
47
+ label: LABELS[id],
48
+ href,
49
+ external: !href.startsWith('/'),
50
+ }));
51
+ }
52
+ /**
53
+ * The access rule, from a token's claims: Stealth access is membership in a
54
+ * Stealth organization. AuthApi puts `stealthTenants` (the organizations
55
+ * where the user is an active member) on platform tokens, and an organization
56
+ * session token names its organization in `tenant_sso`. Anything else, or a
57
+ * value of the wrong shape, is no access. A display decision only: the
58
+ * Stealth APIs enforce membership themselves.
59
+ */
60
+ export function stealthAccessFromClaims(claims) {
61
+ if (!claims || typeof claims !== 'object')
62
+ return false;
63
+ const { stealthTenants, tenant_sso: orgSession } = claims;
64
+ if (Array.isArray(stealthTenants) &&
65
+ stealthTenants.some((tenant) => typeof tenant === 'string' && tenant.trim() !== '')) {
66
+ return true;
67
+ }
68
+ return typeof orgSession === 'string' && orgSession.trim() !== '';
69
+ }
70
+ /** The payload of a JWT, unverified; null when it is not one. */
71
+ export function decodeJwtPayload(token) {
72
+ if (typeof token !== 'string')
73
+ return null;
74
+ const part = token.split('.')[1];
75
+ if (!part)
76
+ return null;
77
+ try {
78
+ const base64 = part.replace(/-/g, '+').replace(/_/g, '/');
79
+ const binary = atob(base64 + '='.repeat((4 - (base64.length % 4)) % 4));
80
+ const bytes = Uint8Array.from(binary, (c) => c.charCodeAt(0));
81
+ return JSON.parse(new TextDecoder().decode(bytes));
82
+ }
83
+ catch {
84
+ return null;
85
+ }
86
+ }
87
+ /** `stealthAccessFromClaims` for the host's access token; no token is no access. */
88
+ export function stealthAccessFromToken(token) {
89
+ return stealthAccessFromClaims(decodeJwtPayload(token));
90
+ }
91
+ /**
92
+ * Which item the current page belongs to: the local item whose path is the
93
+ * pathname or one of its ancestors, or one of the host's extra paths for it
94
+ * (`aliases`, e.g. the account pages under Settings). Null on any other page.
95
+ */
96
+ export function productNavActive(items, pathname, aliases = {}) {
97
+ const matches = (path) => path !== '/' && (pathname === path || pathname.startsWith(`${path.replace(/\/+$/, '')}/`));
98
+ for (const item of items) {
99
+ if (!item.external && matches(item.href))
100
+ return item.id;
101
+ if ((aliases[item.id] ?? []).some(matches))
102
+ return item.id;
103
+ }
104
+ return null;
105
+ }
package/package.json CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
2
  "name": "@burtson-labs/bandit-nav",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "The Bandit product navigation (Chat, Agents, Artifacts, Settings) shared by banditailabs.com, stealth.banditailabs.com and the mobile apps.",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "Burtson Labs",
8
+ "email": "team@burtson.ai",
9
+ "url": "https://burtson.ai"
10
+ },
11
+ "type": "module",
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ },
19
+ "./package.json": "./package.json"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md",
24
+ "LICENSE"
25
+ ],
26
+ "sideEffects": false,
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "peerDependencies": {
31
+ "react": ">=18.2.0 <20.0.0"
32
+ },
33
+ "keywords": [
34
+ "bandit",
35
+ "navigation",
36
+ "burtson"
37
+ ],
38
+ "scripts": {
39
+ "build": "rm -rf dist && tsc -p tsconfig.build.json"
40
+ }
6
41
  }