@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
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # inari-ui-plugin-sdk
2
+
3
+ TypeScript SDK for Inari UI extensions: extension-point blueprints, host APIs, dev harness to run an extension standalone against a dev control plane (plan §6 #7, §5.8, §8.4).
4
+
5
+ Stack: TypeScript, npm package
6
+
7
+ ## Quickstart
8
+
9
+ ```sh
10
+ npm create inari-ui-extension my-extension
11
+ cd my-extension && npm install && npm run dev
12
+ ```
13
+
14
+ ## Writing an extension
15
+
16
+ ```tsx
17
+ import { createExtension, NavItemBlueprint, PageBlueprint } from '@7k-inari/ui-plugin-sdk';
18
+
19
+ export default createExtension({
20
+ manifest: { name: 'my-extension', version: '0.1.0', kind: 'ui' },
21
+ slots: [
22
+ NavItemBlueprint({ name: 'my-nav', title: 'Mine', path: '/mine' }),
23
+ PageBlueprint({ name: 'my-page', path: '/mine', component: MyPage }),
24
+ ],
25
+ });
26
+ ```
27
+
28
+ ## Docs
29
+
30
+ - [Blueprint contract](docs/blueprints.md) — typed slots, zod manifests
31
+ - [Host APIs](docs/host-apis.md) — auth/tenant contexts, API client, design tokens, testing mocks
32
+ - [Dev harness](docs/harness.md) — standalone dev against a mock control plane
33
+ - [Shared dependencies](docs/shared-dependencies.md) — React singleton contract
34
+
35
+ ## Package entry points
36
+
37
+ | Import | Contents |
38
+ |---|---|
39
+ | `@7k-inari/ui-plugin-sdk` | blueprints, `createExtension`, manifest, host APIs |
40
+ | `@7k-inari/ui-plugin-sdk/tokens` | design tokens (TS object) |
41
+ | `@7k-inari/ui-plugin-sdk/tokens.css` | design tokens (CSS custom properties) |
42
+ | `@7k-inari/ui-plugin-sdk/testing` | mock host contexts for unit tests |
43
+ | `@7k-inari/ui-plugin-sdk/harness` | `startDevHarness`, mock control plane |
44
+
45
+ Part of the **Inari** multi-tenant Internal Developer Platform (GitHub org `7K-Inari`).
46
+ Canonical architecture & development plan: [inari-docs/docs/architecture/inari-platform-plan.md](https://github.com/7K-Inari/inari-docs/blob/main/docs/architecture/inari-platform-plan.md)
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from 'node:child_process';
3
+ import { dirname, resolve } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+
6
+ const here = dirname(fileURLToPath(import.meta.url));
7
+ const result = spawnSync(process.execPath, [resolve(here, 'inari-ui-ext.mjs'), 'init', ...process.argv.slice(2)], {
8
+ stdio: 'inherit',
9
+ });
10
+ process.exit(result.status ?? 0);
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env node
2
+ import { cpSync, existsSync, mkdirSync } from 'node:fs';
3
+ import { resolve, dirname } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+
6
+ const here = dirname(fileURLToPath(import.meta.url));
7
+ const [command, ...args] = process.argv.slice(2);
8
+
9
+ async function dev() {
10
+ const entry = args[0] ?? './src/index.ts';
11
+ const { startDevHarness } = await import(resolve(here, '../dist/harness/index.js'));
12
+ const harness = await startDevHarness({ extensionEntry: resolve(process.cwd(), entry) });
13
+ console.log(`Dev harness running at ${harness.url} (mock control plane: ${harness.apiUrl})`);
14
+ }
15
+
16
+ function init() {
17
+ const target = resolve(process.cwd(), args[0] ?? 'my-inari-extension');
18
+ if (existsSync(target)) {
19
+ console.error(`target directory already exists: ${target}`);
20
+ process.exit(1);
21
+ }
22
+ mkdirSync(target, { recursive: true });
23
+ cpSync(resolve(here, '../templates/extension'), target, { recursive: true });
24
+ console.log(`Scaffolded extension in ${target}`);
25
+ console.log('Next: cd into it, npm install, then: npx inari-ui-ext dev');
26
+ }
27
+
28
+ switch (command) {
29
+ case 'dev':
30
+ await dev();
31
+ break;
32
+ case 'init':
33
+ init();
34
+ break;
35
+ default:
36
+ console.log('Usage: inari-ui-ext <dev [entry] | init [dir]>');
37
+ process.exit(command ? 1 : 0);
38
+ }
@@ -0,0 +1,167 @@
1
+ import * as react from 'react';
2
+ import { ReactNode, ComponentType } from 'react';
3
+ import { z } from 'zod';
4
+
5
+ declare const extensionManifestSchema: z.ZodObject<{
6
+ name: z.ZodString;
7
+ version: z.ZodString;
8
+ kind: z.ZodLiteral<"ui">;
9
+ title: z.ZodOptional<z.ZodString>;
10
+ description: z.ZodOptional<z.ZodString>;
11
+ slots: z.ZodArray<z.ZodObject<{
12
+ kind: z.ZodEnum<["nav-item", "catalog-card", "cluster-tab", "instance-action", "form-widget", "page"]>;
13
+ name: z.ZodString;
14
+ }, "strip", z.ZodTypeAny, {
15
+ kind: "nav-item" | "catalog-card" | "cluster-tab" | "instance-action" | "form-widget" | "page";
16
+ name: string;
17
+ }, {
18
+ kind: "nav-item" | "catalog-card" | "cluster-tab" | "instance-action" | "form-widget" | "page";
19
+ name: string;
20
+ }>, "many">;
21
+ }, "strip", z.ZodTypeAny, {
22
+ kind: "ui";
23
+ name: string;
24
+ version: string;
25
+ slots: {
26
+ kind: "nav-item" | "catalog-card" | "cluster-tab" | "instance-action" | "form-widget" | "page";
27
+ name: string;
28
+ }[];
29
+ title?: string | undefined;
30
+ description?: string | undefined;
31
+ }, {
32
+ kind: "ui";
33
+ name: string;
34
+ version: string;
35
+ slots: {
36
+ kind: "nav-item" | "catalog-card" | "cluster-tab" | "instance-action" | "form-widget" | "page";
37
+ name: string;
38
+ }[];
39
+ title?: string | undefined;
40
+ description?: string | undefined;
41
+ }>;
42
+ type ExtensionManifestInput = z.input<typeof extensionManifestSchema>;
43
+ type ParsedExtensionManifest = z.output<typeof extensionManifestSchema>;
44
+ declare function parseExtensionManifest(input: unknown): ParsedExtensionManifest;
45
+
46
+ interface TenantRef {
47
+ orgId: string;
48
+ orgName: string;
49
+ team?: string;
50
+ }
51
+ interface TenantChangeEvent {
52
+ previous: TenantRef | null;
53
+ current: TenantRef;
54
+ }
55
+ type TenantChangeListener = (event: TenantChangeEvent) => void;
56
+ interface TenantState {
57
+ current: TenantRef | null;
58
+ available: TenantRef[];
59
+ switchTenant: (orgId: string, team?: string) => void;
60
+ onTenantChange: (listener: TenantChangeListener) => () => void;
61
+ }
62
+ declare const TenantContext: react.Context<TenantState | null>;
63
+ declare function TenantProvider(props: {
64
+ value: TenantState;
65
+ children: ReactNode;
66
+ }): react.FunctionComponentElement<react.ProviderProps<TenantState | null>>;
67
+ declare function useTenant(): TenantState;
68
+ declare function createTenantState(available: TenantRef[]): TenantState & {
69
+ _listeners: Set<TenantChangeListener>;
70
+ };
71
+
72
+ interface Principal {
73
+ subject: string;
74
+ displayName: string;
75
+ groups: string[];
76
+ }
77
+ interface AuthState {
78
+ principal: Principal | null;
79
+ getToken: () => Promise<string | undefined> | string | undefined;
80
+ }
81
+ declare const AuthContext: react.Context<AuthState | null>;
82
+ declare function AuthProvider(props: {
83
+ value: AuthState;
84
+ children: ReactNode;
85
+ }): react.FunctionComponentElement<react.ProviderProps<AuthState | null>>;
86
+ declare function useAuth(): AuthState;
87
+ declare function usePrincipal(): Principal | null;
88
+
89
+ declare const SLOT_KINDS: readonly ["nav-item", "catalog-card", "cluster-tab", "instance-action", "form-widget", "page"];
90
+ type SlotKind = (typeof SLOT_KINDS)[number];
91
+ interface SlotContribution<K extends SlotKind = SlotKind, P = unknown, O = unknown> {
92
+ readonly kind: K;
93
+ readonly name: string;
94
+ readonly props: P;
95
+ readonly options?: O;
96
+ readonly component?: ComponentType<any>;
97
+ }
98
+ type AnySlotContribution = SlotContribution<SlotKind, any, any>;
99
+ interface InariExtension {
100
+ readonly manifest: ParsedExtensionManifest;
101
+ readonly slots: readonly AnySlotContribution[];
102
+ }
103
+ interface SlotContext {
104
+ auth: AuthState;
105
+ tenant: TenantState;
106
+ }
107
+
108
+ interface Cluster {
109
+ id: string;
110
+ name: string;
111
+ tenantId: string;
112
+ state: 'Pending' | 'Active' | 'Degraded' | 'Cordoned' | 'Decommissioned';
113
+ kubernetesVersion?: string;
114
+ labels?: Record<string, string>;
115
+ }
116
+ interface CatalogItem {
117
+ id: string;
118
+ name: string;
119
+ source: 'discovered' | 'curated' | 'platform';
120
+ version: string;
121
+ description?: string;
122
+ schema?: Record<string, unknown>;
123
+ uiHints?: Record<string, unknown>;
124
+ }
125
+ interface ResourceInstance {
126
+ id: string;
127
+ catalogItemId: string;
128
+ clusterId: string;
129
+ cloudAccountId?: string;
130
+ name: string;
131
+ namespace?: string;
132
+ health?: string;
133
+ status?: Record<string, unknown>;
134
+ ownerTeam?: string;
135
+ }
136
+ interface ApprovalRequest {
137
+ id: string;
138
+ action: string;
139
+ requester: string;
140
+ state: 'pending' | 'approved' | 'rejected';
141
+ }
142
+ interface ApiClientOptions {
143
+ baseUrl: string;
144
+ getToken: () => Promise<string | undefined> | string | undefined;
145
+ fetchImpl?: typeof fetch;
146
+ }
147
+ declare class ApiError extends Error {
148
+ readonly status: number;
149
+ constructor(status: number, message: string);
150
+ }
151
+ declare class ApiClient {
152
+ private readonly baseUrl;
153
+ private readonly getToken;
154
+ private readonly fetchImpl;
155
+ constructor(options: ApiClientOptions);
156
+ private request;
157
+ listClusters(): Promise<Cluster[]>;
158
+ getCluster(id: string): Promise<Cluster>;
159
+ listCatalogItems(clusterId?: string): Promise<CatalogItem[]>;
160
+ getCatalogItem(id: string): Promise<CatalogItem>;
161
+ listResourceInstances(clusterId?: string): Promise<ResourceInstance[]>;
162
+ getResourceInstance(id: string): Promise<ResourceInstance>;
163
+ listApprovals(): Promise<ApprovalRequest[]>;
164
+ approveApproval(id: string): Promise<ApprovalRequest>;
165
+ }
166
+
167
+ export { type AnySlotContribution as A, type CatalogItem as C, type ExtensionManifestInput as E, type InariExtension as I, type ParsedExtensionManifest as P, type ResourceInstance as R, type SlotContribution as S, type TenantChangeEvent as T, type Cluster as a, type SlotContext as b, ApiClient as c, type ApiClientOptions as d, ApiError as e, type ApprovalRequest as f, AuthContext as g, AuthProvider as h, type AuthState as i, type Principal as j, SLOT_KINDS as k, type SlotKind as l, type TenantChangeListener as m, TenantContext as n, TenantProvider as o, type TenantRef as p, type TenantState as q, createTenantState as r, extensionManifestSchema as s, parseExtensionManifest as t, useAuth as u, usePrincipal as v, useTenant as w };
@@ -0,0 +1,167 @@
1
+ import * as react from 'react';
2
+ import { ReactNode, ComponentType } from 'react';
3
+ import { z } from 'zod';
4
+
5
+ declare const extensionManifestSchema: z.ZodObject<{
6
+ name: z.ZodString;
7
+ version: z.ZodString;
8
+ kind: z.ZodLiteral<"ui">;
9
+ title: z.ZodOptional<z.ZodString>;
10
+ description: z.ZodOptional<z.ZodString>;
11
+ slots: z.ZodArray<z.ZodObject<{
12
+ kind: z.ZodEnum<["nav-item", "catalog-card", "cluster-tab", "instance-action", "form-widget", "page"]>;
13
+ name: z.ZodString;
14
+ }, "strip", z.ZodTypeAny, {
15
+ kind: "nav-item" | "catalog-card" | "cluster-tab" | "instance-action" | "form-widget" | "page";
16
+ name: string;
17
+ }, {
18
+ kind: "nav-item" | "catalog-card" | "cluster-tab" | "instance-action" | "form-widget" | "page";
19
+ name: string;
20
+ }>, "many">;
21
+ }, "strip", z.ZodTypeAny, {
22
+ kind: "ui";
23
+ name: string;
24
+ version: string;
25
+ slots: {
26
+ kind: "nav-item" | "catalog-card" | "cluster-tab" | "instance-action" | "form-widget" | "page";
27
+ name: string;
28
+ }[];
29
+ title?: string | undefined;
30
+ description?: string | undefined;
31
+ }, {
32
+ kind: "ui";
33
+ name: string;
34
+ version: string;
35
+ slots: {
36
+ kind: "nav-item" | "catalog-card" | "cluster-tab" | "instance-action" | "form-widget" | "page";
37
+ name: string;
38
+ }[];
39
+ title?: string | undefined;
40
+ description?: string | undefined;
41
+ }>;
42
+ type ExtensionManifestInput = z.input<typeof extensionManifestSchema>;
43
+ type ParsedExtensionManifest = z.output<typeof extensionManifestSchema>;
44
+ declare function parseExtensionManifest(input: unknown): ParsedExtensionManifest;
45
+
46
+ interface TenantRef {
47
+ orgId: string;
48
+ orgName: string;
49
+ team?: string;
50
+ }
51
+ interface TenantChangeEvent {
52
+ previous: TenantRef | null;
53
+ current: TenantRef;
54
+ }
55
+ type TenantChangeListener = (event: TenantChangeEvent) => void;
56
+ interface TenantState {
57
+ current: TenantRef | null;
58
+ available: TenantRef[];
59
+ switchTenant: (orgId: string, team?: string) => void;
60
+ onTenantChange: (listener: TenantChangeListener) => () => void;
61
+ }
62
+ declare const TenantContext: react.Context<TenantState | null>;
63
+ declare function TenantProvider(props: {
64
+ value: TenantState;
65
+ children: ReactNode;
66
+ }): react.FunctionComponentElement<react.ProviderProps<TenantState | null>>;
67
+ declare function useTenant(): TenantState;
68
+ declare function createTenantState(available: TenantRef[]): TenantState & {
69
+ _listeners: Set<TenantChangeListener>;
70
+ };
71
+
72
+ interface Principal {
73
+ subject: string;
74
+ displayName: string;
75
+ groups: string[];
76
+ }
77
+ interface AuthState {
78
+ principal: Principal | null;
79
+ getToken: () => Promise<string | undefined> | string | undefined;
80
+ }
81
+ declare const AuthContext: react.Context<AuthState | null>;
82
+ declare function AuthProvider(props: {
83
+ value: AuthState;
84
+ children: ReactNode;
85
+ }): react.FunctionComponentElement<react.ProviderProps<AuthState | null>>;
86
+ declare function useAuth(): AuthState;
87
+ declare function usePrincipal(): Principal | null;
88
+
89
+ declare const SLOT_KINDS: readonly ["nav-item", "catalog-card", "cluster-tab", "instance-action", "form-widget", "page"];
90
+ type SlotKind = (typeof SLOT_KINDS)[number];
91
+ interface SlotContribution<K extends SlotKind = SlotKind, P = unknown, O = unknown> {
92
+ readonly kind: K;
93
+ readonly name: string;
94
+ readonly props: P;
95
+ readonly options?: O;
96
+ readonly component?: ComponentType<any>;
97
+ }
98
+ type AnySlotContribution = SlotContribution<SlotKind, any, any>;
99
+ interface InariExtension {
100
+ readonly manifest: ParsedExtensionManifest;
101
+ readonly slots: readonly AnySlotContribution[];
102
+ }
103
+ interface SlotContext {
104
+ auth: AuthState;
105
+ tenant: TenantState;
106
+ }
107
+
108
+ interface Cluster {
109
+ id: string;
110
+ name: string;
111
+ tenantId: string;
112
+ state: 'Pending' | 'Active' | 'Degraded' | 'Cordoned' | 'Decommissioned';
113
+ kubernetesVersion?: string;
114
+ labels?: Record<string, string>;
115
+ }
116
+ interface CatalogItem {
117
+ id: string;
118
+ name: string;
119
+ source: 'discovered' | 'curated' | 'platform';
120
+ version: string;
121
+ description?: string;
122
+ schema?: Record<string, unknown>;
123
+ uiHints?: Record<string, unknown>;
124
+ }
125
+ interface ResourceInstance {
126
+ id: string;
127
+ catalogItemId: string;
128
+ clusterId: string;
129
+ cloudAccountId?: string;
130
+ name: string;
131
+ namespace?: string;
132
+ health?: string;
133
+ status?: Record<string, unknown>;
134
+ ownerTeam?: string;
135
+ }
136
+ interface ApprovalRequest {
137
+ id: string;
138
+ action: string;
139
+ requester: string;
140
+ state: 'pending' | 'approved' | 'rejected';
141
+ }
142
+ interface ApiClientOptions {
143
+ baseUrl: string;
144
+ getToken: () => Promise<string | undefined> | string | undefined;
145
+ fetchImpl?: typeof fetch;
146
+ }
147
+ declare class ApiError extends Error {
148
+ readonly status: number;
149
+ constructor(status: number, message: string);
150
+ }
151
+ declare class ApiClient {
152
+ private readonly baseUrl;
153
+ private readonly getToken;
154
+ private readonly fetchImpl;
155
+ constructor(options: ApiClientOptions);
156
+ private request;
157
+ listClusters(): Promise<Cluster[]>;
158
+ getCluster(id: string): Promise<Cluster>;
159
+ listCatalogItems(clusterId?: string): Promise<CatalogItem[]>;
160
+ getCatalogItem(id: string): Promise<CatalogItem>;
161
+ listResourceInstances(clusterId?: string): Promise<ResourceInstance[]>;
162
+ getResourceInstance(id: string): Promise<ResourceInstance>;
163
+ listApprovals(): Promise<ApprovalRequest[]>;
164
+ approveApproval(id: string): Promise<ApprovalRequest>;
165
+ }
166
+
167
+ export { type AnySlotContribution as A, type CatalogItem as C, type ExtensionManifestInput as E, type InariExtension as I, type ParsedExtensionManifest as P, type ResourceInstance as R, type SlotContribution as S, type TenantChangeEvent as T, type Cluster as a, type SlotContext as b, ApiClient as c, type ApiClientOptions as d, ApiError as e, type ApprovalRequest as f, AuthContext as g, AuthProvider as h, type AuthState as i, type Principal as j, SLOT_KINDS as k, type SlotKind as l, type TenantChangeListener as m, TenantContext as n, TenantProvider as o, type TenantRef as p, type TenantState as q, createTenantState as r, extensionManifestSchema as s, parseExtensionManifest as t, useAuth as u, usePrincipal as v, useTenant as w };
@@ -0,0 +1,103 @@
1
+ // src/host/tenant.ts
2
+ import { createContext, createElement, useContext } from "react";
3
+ var TenantContext = createContext(null);
4
+ function TenantProvider(props) {
5
+ return createElement(TenantContext.Provider, { value: props.value }, props.children);
6
+ }
7
+ function useTenant() {
8
+ const ctx = useContext(TenantContext);
9
+ if (!ctx) throw new Error("useTenant must be used within a TenantProvider");
10
+ return ctx;
11
+ }
12
+ function createTenantState(available) {
13
+ const listeners = /* @__PURE__ */ new Set();
14
+ const state = {
15
+ current: available[0] ?? null,
16
+ available,
17
+ _listeners: listeners,
18
+ switchTenant(orgId, team) {
19
+ const next = available.find((t) => t.orgId === orgId && (team === void 0 || t.team === team));
20
+ if (!next) throw new Error(`unknown tenant: ${orgId}${team ? `/${team}` : ""}`);
21
+ const previous = state.current;
22
+ state.current = next;
23
+ listeners.forEach((l) => l({ previous, current: next }));
24
+ },
25
+ onTenantChange(listener) {
26
+ listeners.add(listener);
27
+ return () => listeners.delete(listener);
28
+ }
29
+ };
30
+ return state;
31
+ }
32
+
33
+ // src/host/api.ts
34
+ var ApiError = class extends Error {
35
+ constructor(status, message) {
36
+ super(message);
37
+ this.status = status;
38
+ this.name = "ApiError";
39
+ }
40
+ status;
41
+ };
42
+ var ApiClient = class {
43
+ baseUrl;
44
+ getToken;
45
+ fetchImpl;
46
+ constructor(options) {
47
+ this.baseUrl = options.baseUrl.replace(/\/$/, "");
48
+ this.getToken = options.getToken;
49
+ this.fetchImpl = options.fetchImpl ?? fetch;
50
+ }
51
+ async request(method, path, body) {
52
+ const token = await this.getToken();
53
+ const res = await this.fetchImpl(`${this.baseUrl}${path}`, {
54
+ method,
55
+ headers: {
56
+ "content-type": "application/json",
57
+ ...token ? { authorization: `Bearer ${token}` } : {}
58
+ },
59
+ body: body === void 0 ? void 0 : JSON.stringify(body)
60
+ });
61
+ if (!res.ok) {
62
+ throw new ApiError(res.status, `${method} ${path} failed: ${res.status}`);
63
+ }
64
+ if (res.status === 204) return void 0;
65
+ return await res.json();
66
+ }
67
+ listClusters() {
68
+ return this.request("GET", "/api/v1/clusters");
69
+ }
70
+ getCluster(id) {
71
+ return this.request("GET", `/api/v1/clusters/${encodeURIComponent(id)}`);
72
+ }
73
+ listCatalogItems(clusterId) {
74
+ const q = clusterId ? `?clusterId=${encodeURIComponent(clusterId)}` : "";
75
+ return this.request("GET", `/api/v1/catalog/items${q}`);
76
+ }
77
+ getCatalogItem(id) {
78
+ return this.request("GET", `/api/v1/catalog/items/${encodeURIComponent(id)}`);
79
+ }
80
+ listResourceInstances(clusterId) {
81
+ const q = clusterId ? `?clusterId=${encodeURIComponent(clusterId)}` : "";
82
+ return this.request("GET", `/api/v1/resources${q}`);
83
+ }
84
+ getResourceInstance(id) {
85
+ return this.request("GET", `/api/v1/resources/${encodeURIComponent(id)}`);
86
+ }
87
+ listApprovals() {
88
+ return this.request("GET", "/api/v1/approvals");
89
+ }
90
+ approveApproval(id) {
91
+ return this.request("POST", `/api/v1/approvals/${encodeURIComponent(id)}/approve`);
92
+ }
93
+ };
94
+
95
+ export {
96
+ TenantContext,
97
+ TenantProvider,
98
+ useTenant,
99
+ createTenantState,
100
+ ApiError,
101
+ ApiClient
102
+ };
103
+ //# sourceMappingURL=chunk-OCKSMPCZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/host/tenant.ts","../src/host/api.ts"],"sourcesContent":["import { createContext, createElement, useContext, type ReactNode } from 'react';\n\nexport interface TenantRef {\n orgId: string;\n orgName: string;\n team?: string;\n}\n\nexport interface TenantChangeEvent {\n previous: TenantRef | null;\n current: TenantRef;\n}\n\nexport type TenantChangeListener = (event: TenantChangeEvent) => void;\n\nexport interface TenantState {\n current: TenantRef | null;\n available: TenantRef[];\n switchTenant: (orgId: string, team?: string) => void;\n onTenantChange: (listener: TenantChangeListener) => () => void;\n}\n\nexport const TenantContext = createContext<TenantState | null>(null);\n\nexport function TenantProvider(props: { value: TenantState; children: ReactNode }) {\n return createElement(TenantContext.Provider, { value: props.value }, props.children);\n}\n\nexport function useTenant(): TenantState {\n const ctx = useContext(TenantContext);\n if (!ctx) throw new Error('useTenant must be used within a TenantProvider');\n return ctx;\n}\n\nexport function createTenantState(available: TenantRef[]): TenantState & { _listeners: Set<TenantChangeListener> } {\n const listeners = new Set<TenantChangeListener>();\n const state = {\n current: available[0] ?? null,\n available,\n _listeners: listeners,\n switchTenant(orgId: string, team?: string) {\n const next = available.find((t) => t.orgId === orgId && (team === undefined || t.team === team));\n if (!next) throw new Error(`unknown tenant: ${orgId}${team ? `/${team}` : ''}`);\n const previous = state.current;\n state.current = next;\n listeners.forEach((l) => l({ previous, current: next }));\n },\n onTenantChange(listener: TenantChangeListener) {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n };\n return state;\n}\n","export interface Cluster {\n id: string;\n name: string;\n tenantId: string;\n state: 'Pending' | 'Active' | 'Degraded' | 'Cordoned' | 'Decommissioned';\n kubernetesVersion?: string;\n labels?: Record<string, string>;\n}\n\nexport interface CatalogItem {\n id: string;\n name: string;\n source: 'discovered' | 'curated' | 'platform';\n version: string;\n description?: string;\n schema?: Record<string, unknown>;\n uiHints?: Record<string, unknown>;\n}\n\nexport interface ResourceInstance {\n id: string;\n catalogItemId: string;\n clusterId: string;\n cloudAccountId?: string;\n name: string;\n namespace?: string;\n health?: string;\n status?: Record<string, unknown>;\n ownerTeam?: string;\n}\n\nexport interface ApprovalRequest {\n id: string;\n action: string;\n requester: string;\n state: 'pending' | 'approved' | 'rejected';\n}\n\nexport interface ApiClientOptions {\n baseUrl: string;\n getToken: () => Promise<string | undefined> | string | undefined;\n fetchImpl?: typeof fetch;\n}\n\nexport class ApiError extends Error {\n constructor(\n public readonly status: number,\n message: string,\n ) {\n super(message);\n this.name = 'ApiError';\n }\n}\n\nexport class ApiClient {\n private readonly baseUrl: string;\n private readonly getToken: ApiClientOptions['getToken'];\n private readonly fetchImpl: typeof fetch;\n\n constructor(options: ApiClientOptions) {\n this.baseUrl = options.baseUrl.replace(/\\/$/, '');\n this.getToken = options.getToken;\n this.fetchImpl = options.fetchImpl ?? fetch;\n }\n\n private async request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const token = await this.getToken();\n const res = await this.fetchImpl(`${this.baseUrl}${path}`, {\n method,\n headers: {\n 'content-type': 'application/json',\n ...(token ? { authorization: `Bearer ${token}` } : {}),\n },\n body: body === undefined ? undefined : JSON.stringify(body),\n });\n if (!res.ok) {\n throw new ApiError(res.status, `${method} ${path} failed: ${res.status}`);\n }\n if (res.status === 204) return undefined as T;\n return (await res.json()) as T;\n }\n\n listClusters(): Promise<Cluster[]> {\n return this.request('GET', '/api/v1/clusters');\n }\n\n getCluster(id: string): Promise<Cluster> {\n return this.request('GET', `/api/v1/clusters/${encodeURIComponent(id)}`);\n }\n\n listCatalogItems(clusterId?: string): Promise<CatalogItem[]> {\n const q = clusterId ? `?clusterId=${encodeURIComponent(clusterId)}` : '';\n return this.request('GET', `/api/v1/catalog/items${q}`);\n }\n\n getCatalogItem(id: string): Promise<CatalogItem> {\n return this.request('GET', `/api/v1/catalog/items/${encodeURIComponent(id)}`);\n }\n\n listResourceInstances(clusterId?: string): Promise<ResourceInstance[]> {\n const q = clusterId ? `?clusterId=${encodeURIComponent(clusterId)}` : '';\n return this.request('GET', `/api/v1/resources${q}`);\n }\n\n getResourceInstance(id: string): Promise<ResourceInstance> {\n return this.request('GET', `/api/v1/resources/${encodeURIComponent(id)}`);\n }\n\n listApprovals(): Promise<ApprovalRequest[]> {\n return this.request('GET', '/api/v1/approvals');\n }\n\n approveApproval(id: string): Promise<ApprovalRequest> {\n return this.request('POST', `/api/v1/approvals/${encodeURIComponent(id)}/approve`);\n }\n}\n"],"mappings":";AAAA,SAAS,eAAe,eAAe,kBAAkC;AAsBlE,IAAM,gBAAgB,cAAkC,IAAI;AAE5D,SAAS,eAAe,OAAoD;AACjF,SAAO,cAAc,cAAc,UAAU,EAAE,OAAO,MAAM,MAAM,GAAG,MAAM,QAAQ;AACrF;AA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