@7k-inari/ui-plugin-sdk 0.1.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.
Files changed (39) hide show
  1. package/README.md +46 -0
  2. package/bin/create-inari-ui-extension.mjs +10 -0
  3. package/bin/inari-ui-ext.mjs +38 -0
  4. package/dist/api-CJrl4sLH.d.cts +167 -0
  5. package/dist/api-CJrl4sLH.d.ts +167 -0
  6. package/dist/chunk-OCKSMPCZ.js +103 -0
  7. package/dist/chunk-OCKSMPCZ.js.map +1 -0
  8. package/dist/harness/index.cjs +197 -0
  9. package/dist/harness/index.cjs.map +1 -0
  10. package/dist/harness/index.d.cts +32 -0
  11. package/dist/harness/index.d.ts +32 -0
  12. package/dist/harness/index.js +169 -0
  13. package/dist/harness/index.js.map +1 -0
  14. package/dist/index.cjs +268 -0
  15. package/dist/index.cjs.map +1 -0
  16. package/dist/index.d.cts +80 -0
  17. package/dist/index.d.ts +80 -0
  18. package/dist/index.js +137 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/testing/index.cjs +164 -0
  21. package/dist/testing/index.cjs.map +1 -0
  22. package/dist/testing/index.d.cts +11 -0
  23. package/dist/testing/index.d.ts +11 -0
  24. package/dist/testing/index.js +52 -0
  25. package/dist/testing/index.js.map +1 -0
  26. package/dist/tokens/index.cjs +60 -0
  27. package/dist/tokens/index.cjs.map +1 -0
  28. package/dist/tokens/index.d.cts +41 -0
  29. package/dist/tokens/index.d.ts +41 -0
  30. package/dist/tokens/index.js +35 -0
  31. package/dist/tokens/index.js.map +1 -0
  32. package/harness/shell/index.html +12 -0
  33. package/harness/shell/main.tsx +222 -0
  34. package/harness/shell/vite.config.ts +6 -0
  35. package/package.json +80 -0
  36. package/src/tokens/tokens.css +26 -0
  37. package/templates/extension/package.json +21 -0
  38. package/templates/extension/src/index.tsx +29 -0
  39. package/templates/extension/tsconfig.json +12 -0
@@ -0,0 +1,222 @@
1
+ import React, { useEffect, useMemo, useState } from 'react';
2
+ import { createRoot } from 'react-dom/client';
3
+ import { BrowserRouter, Link, Route, Routes, useParams } from 'react-router-dom';
4
+ import {
5
+ ApiClient,
6
+ AuthProvider,
7
+ TenantProvider,
8
+ createTenantState,
9
+ type CatalogItem,
10
+ type Cluster,
11
+ type InariExtension,
12
+ type ResourceInstance,
13
+ type TenantRef,
14
+ useAuth,
15
+ useTenant,
16
+ } from '@7k-inari/ui-plugin-sdk';
17
+
18
+ declare global {
19
+ interface Window {
20
+ __INARI_API_URL__: string;
21
+ __INARI_EXTENSION_ENTRY__: string;
22
+ }
23
+ }
24
+
25
+ const apiUrl = window.__INARI_API_URL__;
26
+
27
+ function ShellLayout(props: { extension: InariExtension; children: React.ReactNode }) {
28
+ const tenant = useTenant();
29
+ const auth = useAuth();
30
+ const navSlots = props.extension.slots.filter((s) => s.kind === 'nav-item');
31
+ return (
32
+ <div style={{ display: 'flex', fontFamily: 'var(--inari-font, sans-serif)', minHeight: '100vh' }}>
33
+ <aside style={{ width: 220, borderRight: '1px solid var(--inari-border, #ddd)', padding: 16 }}>
34
+ <h1 style={{ fontSize: 18 }}>Inari (dev harness)</h1>
35
+ <div style={{ marginBottom: 12 }}>
36
+ <label htmlFor="tenant-switch">Tenant: </label>
37
+ <select
38
+ id="tenant-switch"
39
+ value={tenant.current?.orgId ?? ''}
40
+ onChange={(e) => tenant.switchTenant(e.target.value)}
41
+ >
42
+ {tenant.available.map((t: TenantRef) => (
43
+ <option key={t.orgId} value={t.orgId}>
44
+ {t.orgName}
45
+ </option>
46
+ ))}
47
+ </select>
48
+ </div>
49
+ <nav>
50
+ <div><Link to="/">Catalog</Link></div>
51
+ <div><Link to="/clusters">Clusters</Link></div>
52
+ <div><Link to="/resources">Resources</Link></div>
53
+ {navSlots.map((s) => (
54
+ <div key={s.name}>
55
+ <Link to={(s.props as { path: string }).path}>
56
+ {(s.props as { title: string }).title}
57
+ </Link>
58
+ </div>
59
+ ))}
60
+ </nav>
61
+ <footer style={{ marginTop: 24, fontSize: 12, color: '#777' }}>
62
+ {auth.principal?.displayName} · {props.extension.manifest.name}@{props.extension.manifest.version}
63
+ </footer>
64
+ </aside>
65
+ <main style={{ flex: 1, padding: 24 }}>{props.children}</main>
66
+ </div>
67
+ );
68
+ }
69
+
70
+ function CatalogPage(props: { extension: InariExtension }) {
71
+ const auth = useAuth();
72
+ const [items, setItems] = useState<CatalogItem[]>([]);
73
+ useEffect(() => {
74
+ new ApiClient({ baseUrl: apiUrl, getToken: auth.getToken }).listCatalogItems().then(setItems);
75
+ }, [auth]);
76
+ const cards = props.extension.slots.filter((s) => s.kind === 'catalog-card');
77
+ return (
78
+ <div>
79
+ <h2>Catalog</h2>
80
+ {items.map((item) => (
81
+ <div key={item.id} style={{ border: '1px solid var(--inari-border, #ddd)', borderRadius: 8, padding: 16, marginBottom: 12 }}>
82
+ <strong>{item.name}</strong> <small>{item.version}</small>
83
+ <p>{item.description}</p>
84
+ {cards.map((c) => {
85
+ const C = c.component!;
86
+ return <C key={c.name} catalogItem={item} />;
87
+ })}
88
+ </div>
89
+ ))}
90
+ </div>
91
+ );
92
+ }
93
+
94
+ function ClustersPage() {
95
+ const auth = useAuth();
96
+ const [clusters, setClusters] = useState<Cluster[]>([]);
97
+ useEffect(() => {
98
+ new ApiClient({ baseUrl: apiUrl, getToken: auth.getToken }).listClusters().then(setClusters);
99
+ }, [auth]);
100
+ return (
101
+ <div>
102
+ <h2>Clusters</h2>
103
+ <ul>
104
+ {clusters.map((c) => (
105
+ <li key={c.id}>
106
+ <Link to={`/clusters/${c.id}`}>{c.name}</Link> — {c.state}
107
+ </li>
108
+ ))}
109
+ </ul>
110
+ </div>
111
+ );
112
+ }
113
+
114
+ function ClusterDetailPage(props: { extension: InariExtension }) {
115
+ const { id } = useParams();
116
+ const auth = useAuth();
117
+ const [cluster, setCluster] = useState<Cluster | null>(null);
118
+ useEffect(() => {
119
+ if (id) new ApiClient({ baseUrl: apiUrl, getToken: auth.getToken }).getCluster(id).then(setCluster);
120
+ }, [auth, id]);
121
+ const tabs = props.extension.slots.filter((s) => s.kind === 'cluster-tab');
122
+ if (!cluster) return <p>Loading…</p>;
123
+ return (
124
+ <div>
125
+ <h2>{cluster.name}</h2>
126
+ <p>State: {cluster.state} · k8s {cluster.kubernetesVersion}</p>
127
+ {tabs.map((t) => {
128
+ const T = t.component!;
129
+ return (
130
+ <section key={t.name} style={{ borderTop: '1px solid #eee', marginTop: 16 }}>
131
+ <h3>{(t.options as { title: string }).title}</h3>
132
+ <T cluster={cluster} />
133
+ </section>
134
+ );
135
+ })}
136
+ </div>
137
+ );
138
+ }
139
+
140
+ function ResourcesPage(props: { extension: InariExtension }) {
141
+ const auth = useAuth();
142
+ const [resources, setResources] = useState<ResourceInstance[]>([]);
143
+ useEffect(() => {
144
+ new ApiClient({ baseUrl: apiUrl, getToken: auth.getToken }).listResourceInstances().then(setResources);
145
+ }, [auth]);
146
+ const actions = props.extension.slots.filter((s) => s.kind === 'instance-action');
147
+ return (
148
+ <div>
149
+ <h2>Resources</h2>
150
+ {resources.map((r) => (
151
+ <div key={r.id} style={{ border: '1px solid #ddd', borderRadius: 8, padding: 16, marginBottom: 12 }}>
152
+ <strong>{r.name}</strong> — {r.health}
153
+ <div>
154
+ {actions.map((a) => (
155
+ <button
156
+ key={a.name}
157
+ style={{ marginRight: 8 }}
158
+ onClick={() => void (a.props as { run: (i: ResourceInstance) => void }).run(r)}
159
+ >
160
+ {(a.props as { label: string }).label}
161
+ </button>
162
+ ))}
163
+ </div>
164
+ </div>
165
+ ))}
166
+ </div>
167
+ );
168
+ }
169
+
170
+ function App(props: { extension: InariExtension }) {
171
+ const pageSlots = props.extension.slots.filter((s) => s.kind === 'page');
172
+ const auth = useAuth();
173
+ const tenant = useTenant();
174
+ const [, setVersion] = useState(0);
175
+ useEffect(() => tenant.onTenantChange(() => setVersion((v) => v + 1)), [tenant]);
176
+ const context = useMemo(() => ({ auth, tenant }), [auth, tenant]);
177
+ return (
178
+ <ShellLayout extension={props.extension}>
179
+ <Routes>
180
+ <Route path="/" element={<CatalogPage extension={props.extension} />} />
181
+ <Route path="/clusters" element={<ClustersPage />} />
182
+ <Route path="/clusters/:id" element={<ClusterDetailPage extension={props.extension} />} />
183
+ <Route path="/resources" element={<ResourcesPage extension={props.extension} />} />
184
+ {pageSlots.map((p) => {
185
+ const P = p.component!;
186
+ return (
187
+ <Route
188
+ key={p.name}
189
+ path={(p.options as { path: string }).path}
190
+ element={<P context={context} />}
191
+ />
192
+ );
193
+ })}
194
+ </Routes>
195
+ </ShellLayout>
196
+ );
197
+ }
198
+
199
+ async function main() {
200
+ const mod = await import(/* @vite-ignore */ window.__INARI_EXTENSION_ENTRY__);
201
+ const extension: InariExtension = mod.default ?? mod.extension;
202
+ if (!extension) throw new Error('extension entry must default-export or export `extension`');
203
+
204
+ const tenants: TenantRef[] = await fetch(`${apiUrl}/api/v1/tenants`).then((r) => r.json());
205
+ const tenantState = createTenantState(tenants);
206
+ const authState = {
207
+ principal: { subject: 'user:dev', displayName: 'Dev User', groups: ['tenant-acme/platform-team'] },
208
+ getToken: () => 'dev-token',
209
+ };
210
+
211
+ createRoot(document.getElementById('root')!).render(
212
+ <AuthProvider value={authState}>
213
+ <TenantProvider value={tenantState}>
214
+ <BrowserRouter>
215
+ <App extension={extension} />
216
+ </BrowserRouter>
217
+ </TenantProvider>
218
+ </AuthProvider>,
219
+ );
220
+ }
221
+
222
+ void main();
@@ -0,0 +1,6 @@
1
+ import { defineConfig } from 'vite';
2
+ import react from '@vitejs/plugin-react';
3
+
4
+ export default defineConfig({
5
+ plugins: [react()],
6
+ });
package/package.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "@7k-inari/ui-plugin-sdk",
3
+ "version": "0.1.1",
4
+ "description": "TypeScript SDK for Inari UI extensions: extension-point blueprints, host APIs, dev harness",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.cjs"
12
+ },
13
+ "./tokens": {
14
+ "types": "./dist/tokens/index.d.ts",
15
+ "import": "./dist/tokens/index.js",
16
+ "require": "./dist/tokens/index.cjs"
17
+ },
18
+ "./testing": {
19
+ "types": "./dist/testing/index.d.ts",
20
+ "import": "./dist/testing/index.js",
21
+ "require": "./dist/testing/index.cjs"
22
+ },
23
+ "./harness": {
24
+ "types": "./dist/harness/index.d.ts",
25
+ "import": "./dist/harness/index.js",
26
+ "require": "./dist/harness/index.cjs"
27
+ },
28
+ "./tokens.css": "./src/tokens/tokens.css"
29
+ },
30
+ "bin": {
31
+ "inari-ui-ext": "./bin/inari-ui-ext.mjs",
32
+ "create-inari-ui-extension": "./bin/create-inari-ui-extension.mjs"
33
+ },
34
+ "scripts": {
35
+ "build": "tsup",
36
+ "test": "vitest run",
37
+ "test:watch": "vitest",
38
+ "typecheck": "tsc --noEmit",
39
+ "lint": "eslint ."
40
+ },
41
+ "files": [
42
+ "dist",
43
+ "bin",
44
+ "templates",
45
+ "harness/shell",
46
+ "src/tokens/tokens.css"
47
+ ],
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "peerDependencies": {
52
+ "react": ">=18",
53
+ "react-dom": ">=18",
54
+ "zod": ">=3"
55
+ },
56
+ "peerDependenciesMeta": {
57
+ "vite": {
58
+ "optional": true
59
+ }
60
+ },
61
+ "devDependencies": {
62
+ "@eslint/js": "^9.13.0",
63
+ "@testing-library/react": "^16.0.1",
64
+ "@types/node": "^22.8.0",
65
+ "@types/react": "^18.3.12",
66
+ "@types/react-dom": "^18.3.1",
67
+ "@vitejs/plugin-react": "^4.7.0",
68
+ "eslint": "^9.13.0",
69
+ "jsdom": "^25.0.1",
70
+ "react": "^18.3.1",
71
+ "react-dom": "^18.3.1",
72
+ "react-router-dom": "^6.30.4",
73
+ "tsup": "^8.3.5",
74
+ "typescript": "^5.9.3",
75
+ "typescript-eslint": "^8.11.0",
76
+ "vite": "^5.4.21",
77
+ "vitest": "^2.1.3",
78
+ "zod": "^3.23.8"
79
+ }
80
+ }
@@ -0,0 +1,26 @@
1
+ :root {
2
+ --inari-bg: #faf9f7;
3
+ --inari-fg: #1c1917;
4
+ --inari-primary: #c2410c;
5
+ --inari-primary-fg: #fff7ed;
6
+ --inari-muted: #e7e5e4;
7
+ --inari-muted-fg: #57534e;
8
+ --inari-border: #d6d3d1;
9
+ --inari-destructive: #b91c1c;
10
+ --inari-radius-sm: 0.25rem;
11
+ --inari-radius-md: 0.5rem;
12
+ --inari-radius-lg: 0.75rem;
13
+ --inari-font: ui-sans-serif, system-ui, sans-serif;
14
+ --inari-font-mono: ui-monospace, SFMono-Regular, monospace;
15
+ }
16
+
17
+ [data-theme='dark'] {
18
+ --inari-bg: #1c1917;
19
+ --inari-fg: #fafaf9;
20
+ --inari-primary: #ea580c;
21
+ --inari-primary-fg: #fff7ed;
22
+ --inari-muted: #292524;
23
+ --inari-muted-fg: #a8a29e;
24
+ --inari-border: #44403c;
25
+ --inari-destructive: #ef4444;
26
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "my-inari-extension",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "inari-ui-ext dev ./src/index.tsx",
8
+ "build": "tsc --noEmit"
9
+ },
10
+ "dependencies": {
11
+ "@7k-inari/ui-plugin-sdk": "^0.1.1",
12
+ "react": "^18.3.1",
13
+ "react-dom": "^18.3.1",
14
+ "zod": "^3.23.8"
15
+ },
16
+ "devDependencies": {
17
+ "@types/react": "^18.3.12",
18
+ "@types/react-dom": "^18.3.1",
19
+ "typescript": "^5.6.3"
20
+ }
21
+ }
@@ -0,0 +1,29 @@
1
+ import { createExtension, NavItemBlueprint, PageBlueprint, ClusterTabBlueprint } from '@7k-inari/ui-plugin-sdk';
2
+
3
+ export default createExtension({
4
+ manifest: {
5
+ name: 'my-inari-extension',
6
+ version: '0.1.0',
7
+ kind: 'ui',
8
+ title: 'My Extension',
9
+ },
10
+ slots: [
11
+ NavItemBlueprint({ name: 'my-nav', title: 'My Extension', path: '/my-extension' }),
12
+ PageBlueprint({
13
+ name: 'my-page',
14
+ path: '/my-extension',
15
+ title: 'My Extension',
16
+ component: ({ context }) => (
17
+ <div>
18
+ <h2>Hello from my extension</h2>
19
+ <p>Current tenant: {context.tenant.current?.orgName ?? 'unknown'}</p>
20
+ </div>
21
+ ),
22
+ }),
23
+ ClusterTabBlueprint({
24
+ name: 'my-cluster-tab',
25
+ title: 'My Tab',
26
+ component: ({ cluster }) => <p>Cluster {cluster.name} is {cluster.state}</p>,
27
+ }),
28
+ ],
29
+ });
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "jsx": "react-jsx",
7
+ "strict": true,
8
+ "skipLibCheck": true,
9
+ "noEmit": true
10
+ },
11
+ "include": ["src"]
12
+ }