@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.
- package/README.md +46 -0
- package/bin/create-inari-ui-extension.mjs +10 -0
- package/bin/inari-ui-ext.mjs +38 -0
- package/dist/api-CJrl4sLH.d.cts +167 -0
- package/dist/api-CJrl4sLH.d.ts +167 -0
- package/dist/chunk-OCKSMPCZ.js +103 -0
- package/dist/chunk-OCKSMPCZ.js.map +1 -0
- package/dist/harness/index.cjs +197 -0
- package/dist/harness/index.cjs.map +1 -0
- package/dist/harness/index.d.cts +32 -0
- package/dist/harness/index.d.ts +32 -0
- package/dist/harness/index.js +169 -0
- package/dist/harness/index.js.map +1 -0
- package/dist/index.cjs +268 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +80 -0
- package/dist/index.d.ts +80 -0
- package/dist/index.js +137 -0
- package/dist/index.js.map +1 -0
- package/dist/testing/index.cjs +164 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +11 -0
- package/dist/testing/index.d.ts +11 -0
- package/dist/testing/index.js +52 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/tokens/index.cjs +60 -0
- package/dist/tokens/index.cjs.map +1 -0
- package/dist/tokens/index.d.cts +41 -0
- package/dist/tokens/index.d.ts +41 -0
- package/dist/tokens/index.js +35 -0
- package/dist/tokens/index.js.map +1 -0
- package/harness/shell/index.html +12 -0
- package/harness/shell/main.tsx +222 -0
- package/harness/shell/vite.config.ts +6 -0
- package/package.json +80 -0
- package/src/tokens/tokens.css +26 -0
- package/templates/extension/package.json +21 -0
- package/templates/extension/src/index.tsx +29 -0
- package/templates/extension/tsconfig.json +12 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
ApiClient: () => ApiClient,
|
|
24
|
+
ApiError: () => ApiError,
|
|
25
|
+
AuthContext: () => AuthContext,
|
|
26
|
+
AuthProvider: () => AuthProvider,
|
|
27
|
+
CatalogCardBlueprint: () => CatalogCardBlueprint,
|
|
28
|
+
ClusterTabBlueprint: () => ClusterTabBlueprint,
|
|
29
|
+
FormWidgetBlueprint: () => FormWidgetBlueprint,
|
|
30
|
+
InstanceActionBlueprint: () => InstanceActionBlueprint,
|
|
31
|
+
NavItemBlueprint: () => NavItemBlueprint,
|
|
32
|
+
PageBlueprint: () => PageBlueprint,
|
|
33
|
+
SLOT_KINDS: () => SLOT_KINDS,
|
|
34
|
+
TenantContext: () => TenantContext,
|
|
35
|
+
TenantProvider: () => TenantProvider,
|
|
36
|
+
createExtension: () => createExtension,
|
|
37
|
+
createTenantState: () => createTenantState,
|
|
38
|
+
extensionManifestSchema: () => extensionManifestSchema,
|
|
39
|
+
parseExtensionManifest: () => parseExtensionManifest,
|
|
40
|
+
useAuth: () => useAuth,
|
|
41
|
+
usePrincipal: () => usePrincipal,
|
|
42
|
+
useTenant: () => useTenant
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(src_exports);
|
|
45
|
+
|
|
46
|
+
// src/manifest.ts
|
|
47
|
+
var import_zod = require("zod");
|
|
48
|
+
var nameSchema = import_zod.z.string().min(1).regex(/^[a-z0-9][a-z0-9-]*$/, "name must be kebab-case");
|
|
49
|
+
var slotContributionSchema = import_zod.z.object({
|
|
50
|
+
kind: import_zod.z.enum([
|
|
51
|
+
"nav-item",
|
|
52
|
+
"catalog-card",
|
|
53
|
+
"cluster-tab",
|
|
54
|
+
"instance-action",
|
|
55
|
+
"form-widget",
|
|
56
|
+
"page"
|
|
57
|
+
]),
|
|
58
|
+
name: nameSchema
|
|
59
|
+
});
|
|
60
|
+
var extensionManifestSchema = import_zod.z.object({
|
|
61
|
+
name: nameSchema,
|
|
62
|
+
version: import_zod.z.string().min(1),
|
|
63
|
+
kind: import_zod.z.literal("ui"),
|
|
64
|
+
title: import_zod.z.string().optional(),
|
|
65
|
+
description: import_zod.z.string().optional(),
|
|
66
|
+
slots: import_zod.z.array(slotContributionSchema).min(1)
|
|
67
|
+
});
|
|
68
|
+
function parseExtensionManifest(input) {
|
|
69
|
+
return extensionManifestSchema.parse(input);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// src/extension.ts
|
|
73
|
+
function createExtension(params) {
|
|
74
|
+
const slotDescriptors = params.slots.map((s) => ({ kind: s.kind, name: s.name }));
|
|
75
|
+
const manifest = parseExtensionManifest({ ...params.manifest, slots: slotDescriptors });
|
|
76
|
+
return { manifest, slots: params.slots };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/blueprints/types.ts
|
|
80
|
+
var SLOT_KINDS = [
|
|
81
|
+
"nav-item",
|
|
82
|
+
"catalog-card",
|
|
83
|
+
"cluster-tab",
|
|
84
|
+
"instance-action",
|
|
85
|
+
"form-widget",
|
|
86
|
+
"page"
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
// src/blueprints/nav-item.ts
|
|
90
|
+
var NavItemBlueprint = (params) => ({
|
|
91
|
+
kind: "nav-item",
|
|
92
|
+
name: params.name,
|
|
93
|
+
props: { title: params.title, path: params.path, icon: params.icon }
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// src/blueprints/catalog-card.ts
|
|
97
|
+
var CatalogCardBlueprint = (params) => ({
|
|
98
|
+
kind: "catalog-card",
|
|
99
|
+
name: params.name,
|
|
100
|
+
props: {},
|
|
101
|
+
component: params.component
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// src/blueprints/cluster-tab.ts
|
|
105
|
+
var ClusterTabBlueprint = (params) => ({
|
|
106
|
+
kind: "cluster-tab",
|
|
107
|
+
name: params.name,
|
|
108
|
+
props: {},
|
|
109
|
+
options: { title: params.title },
|
|
110
|
+
component: params.component
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// src/blueprints/instance-action.ts
|
|
114
|
+
var InstanceActionBlueprint = (params) => ({
|
|
115
|
+
kind: "instance-action",
|
|
116
|
+
name: params.name,
|
|
117
|
+
props: { label: params.label, run: params.run }
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// src/blueprints/form-widget.ts
|
|
121
|
+
var FormWidgetBlueprint = (params) => ({
|
|
122
|
+
kind: "form-widget",
|
|
123
|
+
name: params.name,
|
|
124
|
+
props: {},
|
|
125
|
+
component: params.component
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// src/blueprints/page.ts
|
|
129
|
+
var PageBlueprint = (params) => ({
|
|
130
|
+
kind: "page",
|
|
131
|
+
name: params.name,
|
|
132
|
+
props: {},
|
|
133
|
+
options: { path: params.path, title: params.title },
|
|
134
|
+
component: params.component
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// src/host/auth.ts
|
|
138
|
+
var import_react = require("react");
|
|
139
|
+
var AuthContext = (0, import_react.createContext)(null);
|
|
140
|
+
function AuthProvider(props) {
|
|
141
|
+
return (0, import_react.createElement)(AuthContext.Provider, { value: props.value }, props.children);
|
|
142
|
+
}
|
|
143
|
+
function useAuth() {
|
|
144
|
+
const ctx = (0, import_react.useContext)(AuthContext);
|
|
145
|
+
if (!ctx) throw new Error("useAuth must be used within an AuthProvider");
|
|
146
|
+
return ctx;
|
|
147
|
+
}
|
|
148
|
+
function usePrincipal() {
|
|
149
|
+
return useAuth().principal;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/host/tenant.ts
|
|
153
|
+
var import_react2 = require("react");
|
|
154
|
+
var TenantContext = (0, import_react2.createContext)(null);
|
|
155
|
+
function TenantProvider(props) {
|
|
156
|
+
return (0, import_react2.createElement)(TenantContext.Provider, { value: props.value }, props.children);
|
|
157
|
+
}
|
|
158
|
+
function useTenant() {
|
|
159
|
+
const ctx = (0, import_react2.useContext)(TenantContext);
|
|
160
|
+
if (!ctx) throw new Error("useTenant must be used within a TenantProvider");
|
|
161
|
+
return ctx;
|
|
162
|
+
}
|
|
163
|
+
function createTenantState(available) {
|
|
164
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
165
|
+
const state = {
|
|
166
|
+
current: available[0] ?? null,
|
|
167
|
+
available,
|
|
168
|
+
_listeners: listeners,
|
|
169
|
+
switchTenant(orgId, team) {
|
|
170
|
+
const next = available.find((t) => t.orgId === orgId && (team === void 0 || t.team === team));
|
|
171
|
+
if (!next) throw new Error(`unknown tenant: ${orgId}${team ? `/${team}` : ""}`);
|
|
172
|
+
const previous = state.current;
|
|
173
|
+
state.current = next;
|
|
174
|
+
listeners.forEach((l) => l({ previous, current: next }));
|
|
175
|
+
},
|
|
176
|
+
onTenantChange(listener) {
|
|
177
|
+
listeners.add(listener);
|
|
178
|
+
return () => listeners.delete(listener);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
return state;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// src/host/api.ts
|
|
185
|
+
var ApiError = class extends Error {
|
|
186
|
+
constructor(status, message) {
|
|
187
|
+
super(message);
|
|
188
|
+
this.status = status;
|
|
189
|
+
this.name = "ApiError";
|
|
190
|
+
}
|
|
191
|
+
status;
|
|
192
|
+
};
|
|
193
|
+
var ApiClient = class {
|
|
194
|
+
baseUrl;
|
|
195
|
+
getToken;
|
|
196
|
+
fetchImpl;
|
|
197
|
+
constructor(options) {
|
|
198
|
+
this.baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
199
|
+
this.getToken = options.getToken;
|
|
200
|
+
this.fetchImpl = options.fetchImpl ?? fetch;
|
|
201
|
+
}
|
|
202
|
+
async request(method, path, body) {
|
|
203
|
+
const token = await this.getToken();
|
|
204
|
+
const res = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
205
|
+
method,
|
|
206
|
+
headers: {
|
|
207
|
+
"content-type": "application/json",
|
|
208
|
+
...token ? { authorization: `Bearer ${token}` } : {}
|
|
209
|
+
},
|
|
210
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
211
|
+
});
|
|
212
|
+
if (!res.ok) {
|
|
213
|
+
throw new ApiError(res.status, `${method} ${path} failed: ${res.status}`);
|
|
214
|
+
}
|
|
215
|
+
if (res.status === 204) return void 0;
|
|
216
|
+
return await res.json();
|
|
217
|
+
}
|
|
218
|
+
listClusters() {
|
|
219
|
+
return this.request("GET", "/api/v1/clusters");
|
|
220
|
+
}
|
|
221
|
+
getCluster(id) {
|
|
222
|
+
return this.request("GET", `/api/v1/clusters/${encodeURIComponent(id)}`);
|
|
223
|
+
}
|
|
224
|
+
listCatalogItems(clusterId) {
|
|
225
|
+
const q = clusterId ? `?clusterId=${encodeURIComponent(clusterId)}` : "";
|
|
226
|
+
return this.request("GET", `/api/v1/catalog/items${q}`);
|
|
227
|
+
}
|
|
228
|
+
getCatalogItem(id) {
|
|
229
|
+
return this.request("GET", `/api/v1/catalog/items/${encodeURIComponent(id)}`);
|
|
230
|
+
}
|
|
231
|
+
listResourceInstances(clusterId) {
|
|
232
|
+
const q = clusterId ? `?clusterId=${encodeURIComponent(clusterId)}` : "";
|
|
233
|
+
return this.request("GET", `/api/v1/resources${q}`);
|
|
234
|
+
}
|
|
235
|
+
getResourceInstance(id) {
|
|
236
|
+
return this.request("GET", `/api/v1/resources/${encodeURIComponent(id)}`);
|
|
237
|
+
}
|
|
238
|
+
listApprovals() {
|
|
239
|
+
return this.request("GET", "/api/v1/approvals");
|
|
240
|
+
}
|
|
241
|
+
approveApproval(id) {
|
|
242
|
+
return this.request("POST", `/api/v1/approvals/${encodeURIComponent(id)}/approve`);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
246
|
+
0 && (module.exports = {
|
|
247
|
+
ApiClient,
|
|
248
|
+
ApiError,
|
|
249
|
+
AuthContext,
|
|
250
|
+
AuthProvider,
|
|
251
|
+
CatalogCardBlueprint,
|
|
252
|
+
ClusterTabBlueprint,
|
|
253
|
+
FormWidgetBlueprint,
|
|
254
|
+
InstanceActionBlueprint,
|
|
255
|
+
NavItemBlueprint,
|
|
256
|
+
PageBlueprint,
|
|
257
|
+
SLOT_KINDS,
|
|
258
|
+
TenantContext,
|
|
259
|
+
TenantProvider,
|
|
260
|
+
createExtension,
|
|
261
|
+
createTenantState,
|
|
262
|
+
extensionManifestSchema,
|
|
263
|
+
parseExtensionManifest,
|
|
264
|
+
useAuth,
|
|
265
|
+
usePrincipal,
|
|
266
|
+
useTenant
|
|
267
|
+
});
|
|
268
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/manifest.ts","../src/extension.ts","../src/blueprints/types.ts","../src/blueprints/nav-item.ts","../src/blueprints/catalog-card.ts","../src/blueprints/cluster-tab.ts","../src/blueprints/instance-action.ts","../src/blueprints/form-widget.ts","../src/blueprints/page.ts","../src/host/auth.ts","../src/host/tenant.ts","../src/host/api.ts"],"sourcesContent":["export * from './manifest';\nexport * from './extension';\nexport * from './blueprints';\nexport * from './host';\n","import { z } from 'zod';\n\nconst nameSchema = z\n .string()\n .min(1)\n .regex(/^[a-z0-9][a-z0-9-]*$/, 'name must be kebab-case');\n\nconst slotContributionSchema = z.object({\n kind: z.enum([\n 'nav-item',\n 'catalog-card',\n 'cluster-tab',\n 'instance-action',\n 'form-widget',\n 'page',\n ]),\n name: nameSchema,\n});\n\nexport const extensionManifestSchema = z.object({\n name: nameSchema,\n version: z.string().min(1),\n kind: z.literal('ui'),\n title: z.string().optional(),\n description: z.string().optional(),\n slots: z.array(slotContributionSchema).min(1),\n});\n\nexport type ExtensionManifestInput = z.input<typeof extensionManifestSchema>;\nexport type ParsedExtensionManifest = z.output<typeof extensionManifestSchema>;\n\nexport function parseExtensionManifest(input: unknown): ParsedExtensionManifest {\n return extensionManifestSchema.parse(input);\n}\n","import type { ExtensionManifestInput } from './manifest';\nimport { parseExtensionManifest } from './manifest';\nimport type { AnySlotContribution, InariExtension } from './blueprints/types';\n\nexport interface CreateExtensionParams {\n manifest: Omit<ExtensionManifestInput, 'slots'>;\n slots: AnySlotContribution[];\n}\n\nexport function createExtension(params: CreateExtensionParams): InariExtension {\n const slotDescriptors = params.slots.map((s) => ({ kind: s.kind, name: s.name }));\n const manifest = parseExtensionManifest({ ...params.manifest, slots: slotDescriptors });\n return { manifest, slots: params.slots };\n}\n","import type { ComponentType } from 'react';\n\nexport const SLOT_KINDS = [\n 'nav-item',\n 'catalog-card',\n 'cluster-tab',\n 'instance-action',\n 'form-widget',\n 'page',\n] as const;\n\nexport type SlotKind = (typeof SLOT_KINDS)[number];\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport interface SlotContribution<K extends SlotKind = SlotKind, P = unknown, O = unknown> {\n readonly kind: K;\n readonly name: string;\n readonly props: P;\n readonly options?: O;\n readonly component?: ComponentType<any>;\n}\n\nexport type AnySlotContribution = SlotContribution<SlotKind, any, any>;\n\nexport interface InariExtension {\n readonly manifest: import('../manifest.js').ParsedExtensionManifest;\n readonly slots: readonly AnySlotContribution[];\n}\n\nexport interface SlotContext {\n auth: import('../host/auth.js').AuthState;\n tenant: import('../host/tenant.js').TenantState;\n}\n","import type { ComponentType } from 'react';\nimport type { SlotContribution } from './types';\n\nexport interface NavItemProps {\n title: string;\n path: string;\n icon?: ComponentType;\n}\n\nexport const NavItemBlueprint = (params: { name: string } & NavItemProps): SlotContribution<'nav-item', NavItemProps> => ({\n kind: 'nav-item',\n name: params.name,\n props: { title: params.title, path: params.path, icon: params.icon },\n});\n","import type { ComponentType } from 'react';\nimport type { SlotContribution } from './types';\nimport type { CatalogItem } from '../host/api';\n\nexport interface CatalogCardSlotProps {\n catalogItem: CatalogItem;\n}\n\nexport const CatalogCardBlueprint = (params: {\n name: string;\n component: ComponentType<CatalogCardSlotProps>;\n}): SlotContribution<'catalog-card', CatalogCardSlotProps> => ({\n kind: 'catalog-card',\n name: params.name,\n props: {} as CatalogCardSlotProps,\n component: params.component,\n});\n","import type { ComponentType } from 'react';\nimport type { SlotContribution } from './types';\nimport type { Cluster } from '../host/api';\n\nexport interface ClusterTabSlotProps {\n cluster: Cluster;\n}\n\nexport interface ClusterTabOptions {\n title: string;\n}\n\nexport const ClusterTabBlueprint = (params: {\n name: string;\n title: string;\n component: ComponentType<ClusterTabSlotProps>;\n}): SlotContribution<'cluster-tab', ClusterTabSlotProps, ClusterTabOptions> => ({\n kind: 'cluster-tab',\n name: params.name,\n props: {} as ClusterTabSlotProps,\n options: { title: params.title },\n component: params.component,\n});\n","import type { SlotContribution } from './types';\nimport type { ResourceInstance } from '../host/api';\n\nexport interface InstanceActionSlotProps {\n instance: ResourceInstance;\n}\n\nexport interface InstanceActionProps {\n label: string;\n run: (instance: ResourceInstance) => Promise<void> | void;\n}\n\nexport const InstanceActionBlueprint = (params: {\n name: string;\n label: string;\n run: (instance: ResourceInstance) => Promise<void> | void;\n}): SlotContribution<'instance-action', InstanceActionProps> => ({\n kind: 'instance-action',\n name: params.name,\n props: { label: params.label, run: params.run },\n});\n","import type { ComponentType } from 'react';\nimport type { SlotContribution } from './types';\n\nexport interface FormWidgetSlotProps<T = unknown> {\n value: T | undefined;\n onChange: (value: T) => void;\n schema: Record<string, unknown>;\n disabled?: boolean;\n}\n\nexport const FormWidgetBlueprint = <T = unknown>(params: {\n name: string;\n component: ComponentType<FormWidgetSlotProps<T>>;\n schemaType?: string;\n}): SlotContribution<'form-widget', FormWidgetSlotProps<T>> => ({\n kind: 'form-widget',\n name: params.name,\n props: {} as FormWidgetSlotProps<T>,\n component: params.component as ComponentType<FormWidgetSlotProps<T>>,\n});\n","import type { ComponentType } from 'react';\nimport type { SlotContribution, SlotContext } from './types';\n\nexport interface PageSlotProps {\n context: SlotContext;\n}\n\nexport interface PageOptions {\n path: string;\n title?: string;\n}\n\nexport const PageBlueprint = (params: {\n name: string;\n path: string;\n title?: string;\n component: ComponentType<PageSlotProps>;\n}): SlotContribution<'page', PageSlotProps, PageOptions> => ({\n kind: 'page',\n name: params.name,\n props: {} as PageSlotProps,\n options: { path: params.path, title: params.title },\n component: params.component,\n});\n","import { createContext, createElement, useContext, type ReactNode } from 'react';\n\nexport interface Principal {\n subject: string;\n displayName: string;\n groups: string[];\n}\n\nexport interface AuthState {\n principal: Principal | null;\n getToken: () => Promise<string | undefined> | string | undefined;\n}\n\nexport const AuthContext = createContext<AuthState | null>(null);\n\nexport function AuthProvider(props: { value: AuthState; children: ReactNode }) {\n return createElement(AuthContext.Provider, { value: props.value }, props.children);\n}\n\nexport function useAuth(): AuthState {\n const ctx = useContext(AuthContext);\n if (!ctx) throw new Error('useAuth must be used within an AuthProvider');\n return ctx;\n}\n\nexport function usePrincipal(): Principal | null {\n return useAuth().principal;\n}\n","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":";;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,OAAO,mBAAmB;AAAA,EAChD;AAAA,EAEA,gBAAgB,IAAsC;AACpD,WAAO,KAAK,QAAQ,QAAQ,qBAAqB,mBAAmB,EAAE,CAAC,UAAU;AAAA,EACnF;AACF;","names":["import_react"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { E as ExtensionManifestInput, A as AnySlotContribution, I as InariExtension, S as SlotContribution, C as CatalogItem, a as Cluster, R as ResourceInstance, b as SlotContext } from './api-CJrl4sLH.cjs';
|
|
2
|
+
export { c as ApiClient, d as ApiClientOptions, e as ApiError, f as ApprovalRequest, g as AuthContext, h as AuthProvider, i as AuthState, P as ParsedExtensionManifest, j as Principal, k as SLOT_KINDS, l as SlotKind, T as TenantChangeEvent, m as TenantChangeListener, n as TenantContext, o as TenantProvider, p as TenantRef, q as TenantState, r as createTenantState, s as extensionManifestSchema, t as parseExtensionManifest, u as useAuth, v as usePrincipal, w as useTenant } from './api-CJrl4sLH.cjs';
|
|
3
|
+
import { ComponentType } from 'react';
|
|
4
|
+
import 'zod';
|
|
5
|
+
|
|
6
|
+
interface CreateExtensionParams {
|
|
7
|
+
manifest: Omit<ExtensionManifestInput, 'slots'>;
|
|
8
|
+
slots: AnySlotContribution[];
|
|
9
|
+
}
|
|
10
|
+
declare function createExtension(params: CreateExtensionParams): InariExtension;
|
|
11
|
+
|
|
12
|
+
interface NavItemProps {
|
|
13
|
+
title: string;
|
|
14
|
+
path: string;
|
|
15
|
+
icon?: ComponentType;
|
|
16
|
+
}
|
|
17
|
+
declare const NavItemBlueprint: (params: {
|
|
18
|
+
name: string;
|
|
19
|
+
} & NavItemProps) => SlotContribution<"nav-item", NavItemProps>;
|
|
20
|
+
|
|
21
|
+
interface CatalogCardSlotProps {
|
|
22
|
+
catalogItem: CatalogItem;
|
|
23
|
+
}
|
|
24
|
+
declare const CatalogCardBlueprint: (params: {
|
|
25
|
+
name: string;
|
|
26
|
+
component: ComponentType<CatalogCardSlotProps>;
|
|
27
|
+
}) => SlotContribution<"catalog-card", CatalogCardSlotProps>;
|
|
28
|
+
|
|
29
|
+
interface ClusterTabSlotProps {
|
|
30
|
+
cluster: Cluster;
|
|
31
|
+
}
|
|
32
|
+
interface ClusterTabOptions {
|
|
33
|
+
title: string;
|
|
34
|
+
}
|
|
35
|
+
declare const ClusterTabBlueprint: (params: {
|
|
36
|
+
name: string;
|
|
37
|
+
title: string;
|
|
38
|
+
component: ComponentType<ClusterTabSlotProps>;
|
|
39
|
+
}) => SlotContribution<"cluster-tab", ClusterTabSlotProps, ClusterTabOptions>;
|
|
40
|
+
|
|
41
|
+
interface InstanceActionSlotProps {
|
|
42
|
+
instance: ResourceInstance;
|
|
43
|
+
}
|
|
44
|
+
interface InstanceActionProps {
|
|
45
|
+
label: string;
|
|
46
|
+
run: (instance: ResourceInstance) => Promise<void> | void;
|
|
47
|
+
}
|
|
48
|
+
declare const InstanceActionBlueprint: (params: {
|
|
49
|
+
name: string;
|
|
50
|
+
label: string;
|
|
51
|
+
run: (instance: ResourceInstance) => Promise<void> | void;
|
|
52
|
+
}) => SlotContribution<"instance-action", InstanceActionProps>;
|
|
53
|
+
|
|
54
|
+
interface FormWidgetSlotProps<T = unknown> {
|
|
55
|
+
value: T | undefined;
|
|
56
|
+
onChange: (value: T) => void;
|
|
57
|
+
schema: Record<string, unknown>;
|
|
58
|
+
disabled?: boolean;
|
|
59
|
+
}
|
|
60
|
+
declare const FormWidgetBlueprint: <T = unknown>(params: {
|
|
61
|
+
name: string;
|
|
62
|
+
component: ComponentType<FormWidgetSlotProps<T>>;
|
|
63
|
+
schemaType?: string;
|
|
64
|
+
}) => SlotContribution<"form-widget", FormWidgetSlotProps<T>>;
|
|
65
|
+
|
|
66
|
+
interface PageSlotProps {
|
|
67
|
+
context: SlotContext;
|
|
68
|
+
}
|
|
69
|
+
interface PageOptions {
|
|
70
|
+
path: string;
|
|
71
|
+
title?: string;
|
|
72
|
+
}
|
|
73
|
+
declare const PageBlueprint: (params: {
|
|
74
|
+
name: string;
|
|
75
|
+
path: string;
|
|
76
|
+
title?: string;
|
|
77
|
+
component: ComponentType<PageSlotProps>;
|
|
78
|
+
}) => SlotContribution<"page", PageSlotProps, PageOptions>;
|
|
79
|
+
|
|
80
|
+
export { AnySlotContribution, CatalogCardBlueprint, type CatalogCardSlotProps, CatalogItem, Cluster, ClusterTabBlueprint, type ClusterTabOptions, type ClusterTabSlotProps, type CreateExtensionParams, ExtensionManifestInput, FormWidgetBlueprint, type FormWidgetSlotProps, InariExtension, InstanceActionBlueprint, type InstanceActionProps, type InstanceActionSlotProps, NavItemBlueprint, type NavItemProps, PageBlueprint, type PageOptions, type PageSlotProps, ResourceInstance, SlotContext, SlotContribution, createExtension };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { E as ExtensionManifestInput, A as AnySlotContribution, I as InariExtension, S as SlotContribution, C as CatalogItem, a as Cluster, R as ResourceInstance, b as SlotContext } from './api-CJrl4sLH.js';
|
|
2
|
+
export { c as ApiClient, d as ApiClientOptions, e as ApiError, f as ApprovalRequest, g as AuthContext, h as AuthProvider, i as AuthState, P as ParsedExtensionManifest, j as Principal, k as SLOT_KINDS, l as SlotKind, T as TenantChangeEvent, m as TenantChangeListener, n as TenantContext, o as TenantProvider, p as TenantRef, q as TenantState, r as createTenantState, s as extensionManifestSchema, t as parseExtensionManifest, u as useAuth, v as usePrincipal, w as useTenant } from './api-CJrl4sLH.js';
|
|
3
|
+
import { ComponentType } from 'react';
|
|
4
|
+
import 'zod';
|
|
5
|
+
|
|
6
|
+
interface CreateExtensionParams {
|
|
7
|
+
manifest: Omit<ExtensionManifestInput, 'slots'>;
|
|
8
|
+
slots: AnySlotContribution[];
|
|
9
|
+
}
|
|
10
|
+
declare function createExtension(params: CreateExtensionParams): InariExtension;
|
|
11
|
+
|
|
12
|
+
interface NavItemProps {
|
|
13
|
+
title: string;
|
|
14
|
+
path: string;
|
|
15
|
+
icon?: ComponentType;
|
|
16
|
+
}
|
|
17
|
+
declare const NavItemBlueprint: (params: {
|
|
18
|
+
name: string;
|
|
19
|
+
} & NavItemProps) => SlotContribution<"nav-item", NavItemProps>;
|
|
20
|
+
|
|
21
|
+
interface CatalogCardSlotProps {
|
|
22
|
+
catalogItem: CatalogItem;
|
|
23
|
+
}
|
|
24
|
+
declare const CatalogCardBlueprint: (params: {
|
|
25
|
+
name: string;
|
|
26
|
+
component: ComponentType<CatalogCardSlotProps>;
|
|
27
|
+
}) => SlotContribution<"catalog-card", CatalogCardSlotProps>;
|
|
28
|
+
|
|
29
|
+
interface ClusterTabSlotProps {
|
|
30
|
+
cluster: Cluster;
|
|
31
|
+
}
|
|
32
|
+
interface ClusterTabOptions {
|
|
33
|
+
title: string;
|
|
34
|
+
}
|
|
35
|
+
declare const ClusterTabBlueprint: (params: {
|
|
36
|
+
name: string;
|
|
37
|
+
title: string;
|
|
38
|
+
component: ComponentType<ClusterTabSlotProps>;
|
|
39
|
+
}) => SlotContribution<"cluster-tab", ClusterTabSlotProps, ClusterTabOptions>;
|
|
40
|
+
|
|
41
|
+
interface InstanceActionSlotProps {
|
|
42
|
+
instance: ResourceInstance;
|
|
43
|
+
}
|
|
44
|
+
interface InstanceActionProps {
|
|
45
|
+
label: string;
|
|
46
|
+
run: (instance: ResourceInstance) => Promise<void> | void;
|
|
47
|
+
}
|
|
48
|
+
declare const InstanceActionBlueprint: (params: {
|
|
49
|
+
name: string;
|
|
50
|
+
label: string;
|
|
51
|
+
run: (instance: ResourceInstance) => Promise<void> | void;
|
|
52
|
+
}) => SlotContribution<"instance-action", InstanceActionProps>;
|
|
53
|
+
|
|
54
|
+
interface FormWidgetSlotProps<T = unknown> {
|
|
55
|
+
value: T | undefined;
|
|
56
|
+
onChange: (value: T) => void;
|
|
57
|
+
schema: Record<string, unknown>;
|
|
58
|
+
disabled?: boolean;
|
|
59
|
+
}
|
|
60
|
+
declare const FormWidgetBlueprint: <T = unknown>(params: {
|
|
61
|
+
name: string;
|
|
62
|
+
component: ComponentType<FormWidgetSlotProps<T>>;
|
|
63
|
+
schemaType?: string;
|
|
64
|
+
}) => SlotContribution<"form-widget", FormWidgetSlotProps<T>>;
|
|
65
|
+
|
|
66
|
+
interface PageSlotProps {
|
|
67
|
+
context: SlotContext;
|
|
68
|
+
}
|
|
69
|
+
interface PageOptions {
|
|
70
|
+
path: string;
|
|
71
|
+
title?: string;
|
|
72
|
+
}
|
|
73
|
+
declare const PageBlueprint: (params: {
|
|
74
|
+
name: string;
|
|
75
|
+
path: string;
|
|
76
|
+
title?: string;
|
|
77
|
+
component: ComponentType<PageSlotProps>;
|
|
78
|
+
}) => SlotContribution<"page", PageSlotProps, PageOptions>;
|
|
79
|
+
|
|
80
|
+
export { AnySlotContribution, CatalogCardBlueprint, type CatalogCardSlotProps, CatalogItem, Cluster, ClusterTabBlueprint, type ClusterTabOptions, type ClusterTabSlotProps, type CreateExtensionParams, ExtensionManifestInput, FormWidgetBlueprint, type FormWidgetSlotProps, InariExtension, InstanceActionBlueprint, type InstanceActionProps, type InstanceActionSlotProps, NavItemBlueprint, type NavItemProps, PageBlueprint, type PageOptions, type PageSlotProps, ResourceInstance, SlotContext, SlotContribution, createExtension };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApiClient,
|
|
3
|
+
ApiError,
|
|
4
|
+
TenantContext,
|
|
5
|
+
TenantProvider,
|
|
6
|
+
createTenantState,
|
|
7
|
+
useTenant
|
|
8
|
+
} from "./chunk-OCKSMPCZ.js";
|
|
9
|
+
|
|
10
|
+
// src/manifest.ts
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
var nameSchema = z.string().min(1).regex(/^[a-z0-9][a-z0-9-]*$/, "name must be kebab-case");
|
|
13
|
+
var slotContributionSchema = z.object({
|
|
14
|
+
kind: z.enum([
|
|
15
|
+
"nav-item",
|
|
16
|
+
"catalog-card",
|
|
17
|
+
"cluster-tab",
|
|
18
|
+
"instance-action",
|
|
19
|
+
"form-widget",
|
|
20
|
+
"page"
|
|
21
|
+
]),
|
|
22
|
+
name: nameSchema
|
|
23
|
+
});
|
|
24
|
+
var extensionManifestSchema = z.object({
|
|
25
|
+
name: nameSchema,
|
|
26
|
+
version: z.string().min(1),
|
|
27
|
+
kind: z.literal("ui"),
|
|
28
|
+
title: z.string().optional(),
|
|
29
|
+
description: z.string().optional(),
|
|
30
|
+
slots: z.array(slotContributionSchema).min(1)
|
|
31
|
+
});
|
|
32
|
+
function parseExtensionManifest(input) {
|
|
33
|
+
return extensionManifestSchema.parse(input);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/extension.ts
|
|
37
|
+
function createExtension(params) {
|
|
38
|
+
const slotDescriptors = params.slots.map((s) => ({ kind: s.kind, name: s.name }));
|
|
39
|
+
const manifest = parseExtensionManifest({ ...params.manifest, slots: slotDescriptors });
|
|
40
|
+
return { manifest, slots: params.slots };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/blueprints/types.ts
|
|
44
|
+
var SLOT_KINDS = [
|
|
45
|
+
"nav-item",
|
|
46
|
+
"catalog-card",
|
|
47
|
+
"cluster-tab",
|
|
48
|
+
"instance-action",
|
|
49
|
+
"form-widget",
|
|
50
|
+
"page"
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
// src/blueprints/nav-item.ts
|
|
54
|
+
var NavItemBlueprint = (params) => ({
|
|
55
|
+
kind: "nav-item",
|
|
56
|
+
name: params.name,
|
|
57
|
+
props: { title: params.title, path: params.path, icon: params.icon }
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// src/blueprints/catalog-card.ts
|
|
61
|
+
var CatalogCardBlueprint = (params) => ({
|
|
62
|
+
kind: "catalog-card",
|
|
63
|
+
name: params.name,
|
|
64
|
+
props: {},
|
|
65
|
+
component: params.component
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// src/blueprints/cluster-tab.ts
|
|
69
|
+
var ClusterTabBlueprint = (params) => ({
|
|
70
|
+
kind: "cluster-tab",
|
|
71
|
+
name: params.name,
|
|
72
|
+
props: {},
|
|
73
|
+
options: { title: params.title },
|
|
74
|
+
component: params.component
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// src/blueprints/instance-action.ts
|
|
78
|
+
var InstanceActionBlueprint = (params) => ({
|
|
79
|
+
kind: "instance-action",
|
|
80
|
+
name: params.name,
|
|
81
|
+
props: { label: params.label, run: params.run }
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// src/blueprints/form-widget.ts
|
|
85
|
+
var FormWidgetBlueprint = (params) => ({
|
|
86
|
+
kind: "form-widget",
|
|
87
|
+
name: params.name,
|
|
88
|
+
props: {},
|
|
89
|
+
component: params.component
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// src/blueprints/page.ts
|
|
93
|
+
var PageBlueprint = (params) => ({
|
|
94
|
+
kind: "page",
|
|
95
|
+
name: params.name,
|
|
96
|
+
props: {},
|
|
97
|
+
options: { path: params.path, title: params.title },
|
|
98
|
+
component: params.component
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// src/host/auth.ts
|
|
102
|
+
import { createContext, createElement, useContext } from "react";
|
|
103
|
+
var AuthContext = createContext(null);
|
|
104
|
+
function AuthProvider(props) {
|
|
105
|
+
return createElement(AuthContext.Provider, { value: props.value }, props.children);
|
|
106
|
+
}
|
|
107
|
+
function useAuth() {
|
|
108
|
+
const ctx = useContext(AuthContext);
|
|
109
|
+
if (!ctx) throw new Error("useAuth must be used within an AuthProvider");
|
|
110
|
+
return ctx;
|
|
111
|
+
}
|
|
112
|
+
function usePrincipal() {
|
|
113
|
+
return useAuth().principal;
|
|
114
|
+
}
|
|
115
|
+
export {
|
|
116
|
+
ApiClient,
|
|
117
|
+
ApiError,
|
|
118
|
+
AuthContext,
|
|
119
|
+
AuthProvider,
|
|
120
|
+
CatalogCardBlueprint,
|
|
121
|
+
ClusterTabBlueprint,
|
|
122
|
+
FormWidgetBlueprint,
|
|
123
|
+
InstanceActionBlueprint,
|
|
124
|
+
NavItemBlueprint,
|
|
125
|
+
PageBlueprint,
|
|
126
|
+
SLOT_KINDS,
|
|
127
|
+
TenantContext,
|
|
128
|
+
TenantProvider,
|
|
129
|
+
createExtension,
|
|
130
|
+
createTenantState,
|
|
131
|
+
extensionManifestSchema,
|
|
132
|
+
parseExtensionManifest,
|
|
133
|
+
useAuth,
|
|
134
|
+
usePrincipal,
|
|
135
|
+
useTenant
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/manifest.ts","../src/extension.ts","../src/blueprints/types.ts","../src/blueprints/nav-item.ts","../src/blueprints/catalog-card.ts","../src/blueprints/cluster-tab.ts","../src/blueprints/instance-action.ts","../src/blueprints/form-widget.ts","../src/blueprints/page.ts","../src/host/auth.ts"],"sourcesContent":["import { z } from 'zod';\n\nconst nameSchema = z\n .string()\n .min(1)\n .regex(/^[a-z0-9][a-z0-9-]*$/, 'name must be kebab-case');\n\nconst slotContributionSchema = z.object({\n kind: z.enum([\n 'nav-item',\n 'catalog-card',\n 'cluster-tab',\n 'instance-action',\n 'form-widget',\n 'page',\n ]),\n name: nameSchema,\n});\n\nexport const extensionManifestSchema = z.object({\n name: nameSchema,\n version: z.string().min(1),\n kind: z.literal('ui'),\n title: z.string().optional(),\n description: z.string().optional(),\n slots: z.array(slotContributionSchema).min(1),\n});\n\nexport type ExtensionManifestInput = z.input<typeof extensionManifestSchema>;\nexport type ParsedExtensionManifest = z.output<typeof extensionManifestSchema>;\n\nexport function parseExtensionManifest(input: unknown): ParsedExtensionManifest {\n return extensionManifestSchema.parse(input);\n}\n","import type { ExtensionManifestInput } from './manifest';\nimport { parseExtensionManifest } from './manifest';\nimport type { AnySlotContribution, InariExtension } from './blueprints/types';\n\nexport interface CreateExtensionParams {\n manifest: Omit<ExtensionManifestInput, 'slots'>;\n slots: AnySlotContribution[];\n}\n\nexport function createExtension(params: CreateExtensionParams): InariExtension {\n const slotDescriptors = params.slots.map((s) => ({ kind: s.kind, name: s.name }));\n const manifest = parseExtensionManifest({ ...params.manifest, slots: slotDescriptors });\n return { manifest, slots: params.slots };\n}\n","import type { ComponentType } from 'react';\n\nexport const SLOT_KINDS = [\n 'nav-item',\n 'catalog-card',\n 'cluster-tab',\n 'instance-action',\n 'form-widget',\n 'page',\n] as const;\n\nexport type SlotKind = (typeof SLOT_KINDS)[number];\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport interface SlotContribution<K extends SlotKind = SlotKind, P = unknown, O = unknown> {\n readonly kind: K;\n readonly name: string;\n readonly props: P;\n readonly options?: O;\n readonly component?: ComponentType<any>;\n}\n\nexport type AnySlotContribution = SlotContribution<SlotKind, any, any>;\n\nexport interface InariExtension {\n readonly manifest: import('../manifest.js').ParsedExtensionManifest;\n readonly slots: readonly AnySlotContribution[];\n}\n\nexport interface SlotContext {\n auth: import('../host/auth.js').AuthState;\n tenant: import('../host/tenant.js').TenantState;\n}\n","import type { ComponentType } from 'react';\nimport type { SlotContribution } from './types';\n\nexport interface NavItemProps {\n title: string;\n path: string;\n icon?: ComponentType;\n}\n\nexport const NavItemBlueprint = (params: { name: string } & NavItemProps): SlotContribution<'nav-item', NavItemProps> => ({\n kind: 'nav-item',\n name: params.name,\n props: { title: params.title, path: params.path, icon: params.icon },\n});\n","import type { ComponentType } from 'react';\nimport type { SlotContribution } from './types';\nimport type { CatalogItem } from '../host/api';\n\nexport interface CatalogCardSlotProps {\n catalogItem: CatalogItem;\n}\n\nexport const CatalogCardBlueprint = (params: {\n name: string;\n component: ComponentType<CatalogCardSlotProps>;\n}): SlotContribution<'catalog-card', CatalogCardSlotProps> => ({\n kind: 'catalog-card',\n name: params.name,\n props: {} as CatalogCardSlotProps,\n component: params.component,\n});\n","import type { ComponentType } from 'react';\nimport type { SlotContribution } from './types';\nimport type { Cluster } from '../host/api';\n\nexport interface ClusterTabSlotProps {\n cluster: Cluster;\n}\n\nexport interface ClusterTabOptions {\n title: string;\n}\n\nexport const ClusterTabBlueprint = (params: {\n name: string;\n title: string;\n component: ComponentType<ClusterTabSlotProps>;\n}): SlotContribution<'cluster-tab', ClusterTabSlotProps, ClusterTabOptions> => ({\n kind: 'cluster-tab',\n name: params.name,\n props: {} as ClusterTabSlotProps,\n options: { title: params.title },\n component: params.component,\n});\n","import type { SlotContribution } from './types';\nimport type { ResourceInstance } from '../host/api';\n\nexport interface InstanceActionSlotProps {\n instance: ResourceInstance;\n}\n\nexport interface InstanceActionProps {\n label: string;\n run: (instance: ResourceInstance) => Promise<void> | void;\n}\n\nexport const InstanceActionBlueprint = (params: {\n name: string;\n label: string;\n run: (instance: ResourceInstance) => Promise<void> | void;\n}): SlotContribution<'instance-action', InstanceActionProps> => ({\n kind: 'instance-action',\n name: params.name,\n props: { label: params.label, run: params.run },\n});\n","import type { ComponentType } from 'react';\nimport type { SlotContribution } from './types';\n\nexport interface FormWidgetSlotProps<T = unknown> {\n value: T | undefined;\n onChange: (value: T) => void;\n schema: Record<string, unknown>;\n disabled?: boolean;\n}\n\nexport const FormWidgetBlueprint = <T = unknown>(params: {\n name: string;\n component: ComponentType<FormWidgetSlotProps<T>>;\n schemaType?: string;\n}): SlotContribution<'form-widget', FormWidgetSlotProps<T>> => ({\n kind: 'form-widget',\n name: params.name,\n props: {} as FormWidgetSlotProps<T>,\n component: params.component as ComponentType<FormWidgetSlotProps<T>>,\n});\n","import type { ComponentType } from 'react';\nimport type { SlotContribution, SlotContext } from './types';\n\nexport interface PageSlotProps {\n context: SlotContext;\n}\n\nexport interface PageOptions {\n path: string;\n title?: string;\n}\n\nexport const PageBlueprint = (params: {\n name: string;\n path: string;\n title?: string;\n component: ComponentType<PageSlotProps>;\n}): SlotContribution<'page', PageSlotProps, PageOptions> => ({\n kind: 'page',\n name: params.name,\n props: {} as PageSlotProps,\n options: { path: params.path, title: params.title },\n component: params.component,\n});\n","import { createContext, createElement, useContext, type ReactNode } from 'react';\n\nexport interface Principal {\n subject: string;\n displayName: string;\n groups: string[];\n}\n\nexport interface AuthState {\n principal: Principal | null;\n getToken: () => Promise<string | undefined> | string | undefined;\n}\n\nexport const AuthContext = createContext<AuthState | null>(null);\n\nexport function AuthProvider(props: { value: AuthState; children: ReactNode }) {\n return createElement(AuthContext.Provider, { value: props.value }, props.children);\n}\n\nexport function useAuth(): AuthState {\n const ctx = useContext(AuthContext);\n if (!ctx) throw new Error('useAuth must be used within an AuthProvider');\n return ctx;\n}\n\nexport function usePrincipal(): Principal | null {\n return useAuth().principal;\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAS,SAAS;AAElB,IAAM,aAAa,EAChB,OAAO,EACP,IAAI,CAAC,EACL,MAAM,wBAAwB,yBAAyB;AAE1D,IAAM,yBAAyB,EAAE,OAAO;AAAA,EACtC,MAAM,EAAE,KAAK;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAAA,EACD,MAAM;AACR,CAAC;AAEM,IAAM,0BAA0B,EAAE,OAAO;AAAA,EAC9C,MAAM;AAAA,EACN,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACzB,MAAM,EAAE,QAAQ,IAAI;AAAA,EACpB,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,aAAa,EAAE,OAAO,EAAE,SAAS;AAAA,EACjC,OAAO,EAAE,MAAM,sBAAsB,EAAE,IAAI,CAAC;AAC9C,CAAC;AAKM,SAAS,uBAAuB,OAAyC;AAC9E,SAAO,wBAAwB,MAAM,KAAK;AAC5C;;;ACxBO,SAAS,gBAAgB,QAA+C;AAC7E,QAAM,kBAAkB,OAAO,MAAM,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,EAAE,KAAK,EAAE;AAChF,QAAM,WAAW,uBAAuB,EAAE,GAAG,OAAO,UAAU,OAAO,gBAAgB,CAAC;AACtF,SAAO,EAAE,UAAU,OAAO,OA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