@7k-inari/ui-plugin-sdk 0.1.6 → 0.1.7
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/dist/chunk-SEVFUJHN.js +236 -0
- package/dist/chunk-SEVFUJHN.js.map +1 -0
- package/dist/{api-Br2Mnkqb.d.cts → extension-errors-B3h-BfUa.d.cts} +47 -5
- package/dist/{api-Br2Mnkqb.d.ts → extension-errors-B3h-BfUa.d.ts} +47 -5
- package/dist/index.cjs +142 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -1
- package/dist/testing/index.cjs +147 -1
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +8 -2
- package/dist/testing/index.d.ts +8 -2
- package/dist/testing/index.js +25 -1
- package/dist/testing/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-E5P565T6.js +0 -103
- package/dist/chunk-E5P565T6.js.map +0 -1
|
@@ -0,0 +1,236 @@
|
|
|
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-error.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
|
+
|
|
43
|
+
// src/host/extension-errors.ts
|
|
44
|
+
var CODE_TO_KIND = {
|
|
45
|
+
session_expired: "session-expired",
|
|
46
|
+
reauth_required: "session-expired",
|
|
47
|
+
downstream_permission_denied: "downstream-denied",
|
|
48
|
+
fga_denied: "fga-denied",
|
|
49
|
+
permission_denied: "fga-denied",
|
|
50
|
+
exchange_failed: "exchange-failed",
|
|
51
|
+
auth_model_failure: "exchange-failed"
|
|
52
|
+
};
|
|
53
|
+
var ExtensionApiError = class extends ApiError {
|
|
54
|
+
retryable = false;
|
|
55
|
+
requestId;
|
|
56
|
+
extension;
|
|
57
|
+
reauth;
|
|
58
|
+
constructor(status, message, meta = {}) {
|
|
59
|
+
super(status, message);
|
|
60
|
+
this.name = new.target.name;
|
|
61
|
+
if (meta.requestId !== void 0) this.requestId = meta.requestId;
|
|
62
|
+
if (meta.extension !== void 0) this.extension = meta.extension;
|
|
63
|
+
if (meta.reauth !== void 0) this.reauth = meta.reauth;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var SessionExpiredError = class extends ExtensionApiError {
|
|
67
|
+
kind = "session-expired";
|
|
68
|
+
retryable = true;
|
|
69
|
+
};
|
|
70
|
+
var DownstreamDeniedError = class extends ExtensionApiError {
|
|
71
|
+
kind = "downstream-denied";
|
|
72
|
+
};
|
|
73
|
+
var FgaDeniedError = class extends ExtensionApiError {
|
|
74
|
+
kind = "fga-denied";
|
|
75
|
+
};
|
|
76
|
+
var ExchangeFailedError = class extends ExtensionApiError {
|
|
77
|
+
kind = "exchange-failed";
|
|
78
|
+
};
|
|
79
|
+
var ExtensionFailureError = class extends ExtensionApiError {
|
|
80
|
+
kind = "extension-failure";
|
|
81
|
+
};
|
|
82
|
+
var KIND_TO_CLASS = {
|
|
83
|
+
"session-expired": SessionExpiredError,
|
|
84
|
+
"downstream-denied": DownstreamDeniedError,
|
|
85
|
+
"fga-denied": FgaDeniedError,
|
|
86
|
+
"exchange-failed": ExchangeFailedError,
|
|
87
|
+
"extension-failure": ExtensionFailureError
|
|
88
|
+
};
|
|
89
|
+
function isExtensionApiError(err) {
|
|
90
|
+
return err instanceof ExtensionApiError;
|
|
91
|
+
}
|
|
92
|
+
function parseBody(body) {
|
|
93
|
+
if (typeof body !== "object" || body === null) return {};
|
|
94
|
+
const err = body.error;
|
|
95
|
+
if (typeof err !== "object" || err === null) return {};
|
|
96
|
+
const rec = err;
|
|
97
|
+
const out = {};
|
|
98
|
+
if (typeof rec.code === "string") out.code = rec.code;
|
|
99
|
+
if (typeof rec.message === "string") out.message = rec.message;
|
|
100
|
+
if (typeof rec.requestId === "string") out.requestId = rec.requestId;
|
|
101
|
+
if (typeof rec.reauth === "object" && rec.reauth !== null) {
|
|
102
|
+
const r = rec.reauth;
|
|
103
|
+
const reauth = {};
|
|
104
|
+
if (typeof r.provider === "string") reauth.provider = r.provider;
|
|
105
|
+
if (typeof r.hint === "string") reauth.hint = r.hint;
|
|
106
|
+
out.reauth = reauth;
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
function fallbackKind(status) {
|
|
111
|
+
if (status === 401) return "session-expired";
|
|
112
|
+
if (status === 403) return "fga-denied";
|
|
113
|
+
return "extension-failure";
|
|
114
|
+
}
|
|
115
|
+
var MAX_MESSAGE_LENGTH = 300;
|
|
116
|
+
function sanitizeMessage(message) {
|
|
117
|
+
return message.length > MAX_MESSAGE_LENGTH ? `${message.slice(0, MAX_MESSAGE_LENGTH)}\u2026` : message;
|
|
118
|
+
}
|
|
119
|
+
function classifyExtensionError(status, body, extension) {
|
|
120
|
+
const parsed = parseBody(body);
|
|
121
|
+
const mapped = parsed.code ? CODE_TO_KIND[parsed.code] : void 0;
|
|
122
|
+
const kind = mapped ?? fallbackKind(status);
|
|
123
|
+
const message = parsed.message !== void 0 ? sanitizeMessage(parsed.message) : `extension invocation failed: ${status}`;
|
|
124
|
+
const meta = {};
|
|
125
|
+
if (parsed.requestId !== void 0) meta.requestId = parsed.requestId;
|
|
126
|
+
if (extension !== void 0) meta.extension = extension;
|
|
127
|
+
if (kind === "session-expired" && parsed.reauth !== void 0) meta.reauth = parsed.reauth;
|
|
128
|
+
const Cls = KIND_TO_CLASS[kind];
|
|
129
|
+
return new Cls(status, message, meta);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/host/api.ts
|
|
133
|
+
var ApiClient = class {
|
|
134
|
+
baseUrl;
|
|
135
|
+
getToken;
|
|
136
|
+
fetchImpl;
|
|
137
|
+
constructor(options) {
|
|
138
|
+
this.baseUrl = options.baseUrl.replace(/\/$/, "");
|
|
139
|
+
this.getToken = options.getToken;
|
|
140
|
+
this.fetchImpl = options.fetchImpl ?? fetch;
|
|
141
|
+
}
|
|
142
|
+
async request(method, path, body) {
|
|
143
|
+
const token = await this.getToken();
|
|
144
|
+
const res = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
145
|
+
method,
|
|
146
|
+
headers: {
|
|
147
|
+
"content-type": "application/json",
|
|
148
|
+
...token ? { authorization: `Bearer ${token}` } : {}
|
|
149
|
+
},
|
|
150
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
151
|
+
});
|
|
152
|
+
if (!res.ok) {
|
|
153
|
+
throw new ApiError(res.status, `${method} ${path} failed: ${res.status}`);
|
|
154
|
+
}
|
|
155
|
+
if (res.status === 204) return void 0;
|
|
156
|
+
return await res.json();
|
|
157
|
+
}
|
|
158
|
+
listClusters() {
|
|
159
|
+
return this.request("GET", "/api/v1/clusters");
|
|
160
|
+
}
|
|
161
|
+
getCluster(id) {
|
|
162
|
+
return this.request("GET", `/api/v1/clusters/${encodeURIComponent(id)}`);
|
|
163
|
+
}
|
|
164
|
+
listCatalogItems(clusterId) {
|
|
165
|
+
const q = clusterId ? `?clusterId=${encodeURIComponent(clusterId)}` : "";
|
|
166
|
+
return this.request("GET", `/api/v1/catalog/items${q}`);
|
|
167
|
+
}
|
|
168
|
+
getCatalogItem(id) {
|
|
169
|
+
return this.request("GET", `/api/v1/catalog/items/${encodeURIComponent(id)}`);
|
|
170
|
+
}
|
|
171
|
+
listResourceInstances(clusterId) {
|
|
172
|
+
const q = clusterId ? `?clusterId=${encodeURIComponent(clusterId)}` : "";
|
|
173
|
+
return this.request("GET", `/api/v1/resources${q}`);
|
|
174
|
+
}
|
|
175
|
+
getResourceInstance(id) {
|
|
176
|
+
return this.request("GET", `/api/v1/resources/${encodeURIComponent(id)}`);
|
|
177
|
+
}
|
|
178
|
+
listApprovals() {
|
|
179
|
+
return this.request("GET", "/api/v1/approvals");
|
|
180
|
+
}
|
|
181
|
+
approveApproval(id) {
|
|
182
|
+
return this.request("POST", `/api/v1/approvals/${encodeURIComponent(id)}/approve`);
|
|
183
|
+
}
|
|
184
|
+
async invokeExtension(name, path, init = {}) {
|
|
185
|
+
const token = await this.getToken();
|
|
186
|
+
const res = await this.fetchImpl(
|
|
187
|
+
`${this.baseUrl}/api/extensions/${encodeURIComponent(name)}${path}`,
|
|
188
|
+
{
|
|
189
|
+
method: init.method ?? "GET",
|
|
190
|
+
headers: {
|
|
191
|
+
"content-type": "application/json",
|
|
192
|
+
...token ? { authorization: `Bearer ${token}` } : {}
|
|
193
|
+
},
|
|
194
|
+
body: init.body === void 0 ? void 0 : JSON.stringify(init.body)
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
const text = await res.text();
|
|
198
|
+
let parsed;
|
|
199
|
+
let parseFailed = false;
|
|
200
|
+
try {
|
|
201
|
+
parsed = text ? JSON.parse(text) : void 0;
|
|
202
|
+
} catch {
|
|
203
|
+
parsed = void 0;
|
|
204
|
+
parseFailed = true;
|
|
205
|
+
}
|
|
206
|
+
if (!res.ok) {
|
|
207
|
+
throw classifyExtensionError(res.status, parsed, name);
|
|
208
|
+
}
|
|
209
|
+
if (parseFailed) {
|
|
210
|
+
throw new ExtensionFailureError(
|
|
211
|
+
res.status,
|
|
212
|
+
`extension '${name}' returned a non-JSON response (${res.status})`,
|
|
213
|
+
{ extension: name }
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
return parsed;
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
export {
|
|
221
|
+
TenantContext,
|
|
222
|
+
TenantProvider,
|
|
223
|
+
useTenant,
|
|
224
|
+
createTenantState,
|
|
225
|
+
ApiError,
|
|
226
|
+
ExtensionApiError,
|
|
227
|
+
SessionExpiredError,
|
|
228
|
+
DownstreamDeniedError,
|
|
229
|
+
FgaDeniedError,
|
|
230
|
+
ExchangeFailedError,
|
|
231
|
+
ExtensionFailureError,
|
|
232
|
+
isExtensionApiError,
|
|
233
|
+
classifyExtensionError,
|
|
234
|
+
ApiClient
|
|
235
|
+
};
|
|
236
|
+
//# sourceMappingURL=chunk-SEVFUJHN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/host/tenant.ts","../src/host/api-error.ts","../src/host/extension-errors.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 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","import { ApiError } from './api-error';\n\nexport type ExtensionErrorKind =\n | 'session-expired'\n | 'downstream-denied'\n | 'fga-denied'\n | 'exchange-failed'\n | 'extension-failure';\n\nexport interface ExtensionReauthMeta {\n provider?: string;\n hint?: string;\n}\n\nconst CODE_TO_KIND: Record<string, ExtensionErrorKind> = {\n session_expired: 'session-expired',\n reauth_required: 'session-expired',\n downstream_permission_denied: 'downstream-denied',\n fga_denied: 'fga-denied',\n permission_denied: 'fga-denied',\n exchange_failed: 'exchange-failed',\n auth_model_failure: 'exchange-failed',\n};\n\nexport abstract class ExtensionApiError extends ApiError {\n abstract readonly kind: ExtensionErrorKind;\n readonly retryable: boolean = false;\n readonly requestId?: string;\n readonly extension?: string;\n readonly reauth?: ExtensionReauthMeta;\n\n constructor(\n status: number,\n message: string,\n meta: { requestId?: string; extension?: string; reauth?: ExtensionReauthMeta } = {},\n ) {\n super(status, message);\n this.name = new.target.name;\n if (meta.requestId !== undefined) this.requestId = meta.requestId;\n if (meta.extension !== undefined) this.extension = meta.extension;\n if (meta.reauth !== undefined) this.reauth = meta.reauth;\n }\n}\n\nexport class SessionExpiredError extends ExtensionApiError {\n readonly kind = 'session-expired' as const;\n readonly retryable = true;\n}\n\nexport class DownstreamDeniedError extends ExtensionApiError {\n readonly kind = 'downstream-denied' as const;\n}\n\nexport class FgaDeniedError extends ExtensionApiError {\n readonly kind = 'fga-denied' as const;\n}\n\nexport class ExchangeFailedError extends ExtensionApiError {\n readonly kind = 'exchange-failed' as const;\n}\n\nexport class ExtensionFailureError extends ExtensionApiError {\n readonly kind = 'extension-failure' as const;\n}\n\nexport type AnyExtensionApiError =\n | SessionExpiredError\n | DownstreamDeniedError\n | FgaDeniedError\n | ExchangeFailedError\n | ExtensionFailureError;\n\nconst KIND_TO_CLASS = {\n 'session-expired': SessionExpiredError,\n 'downstream-denied': DownstreamDeniedError,\n 'fga-denied': FgaDeniedError,\n 'exchange-failed': ExchangeFailedError,\n 'extension-failure': ExtensionFailureError,\n} as const;\n\nexport function isExtensionApiError(err: unknown): err is ExtensionApiError {\n return err instanceof ExtensionApiError;\n}\n\ninterface ParsedErrorBody {\n code?: string;\n message?: string;\n requestId?: string;\n reauth?: ExtensionReauthMeta;\n}\n\nfunction parseBody(body: unknown): ParsedErrorBody {\n if (typeof body !== 'object' || body === null) return {};\n const err = (body as Record<string, unknown>).error;\n if (typeof err !== 'object' || err === null) return {};\n const rec = err as Record<string, unknown>;\n const out: ParsedErrorBody = {};\n if (typeof rec.code === 'string') out.code = rec.code;\n if (typeof rec.message === 'string') out.message = rec.message;\n if (typeof rec.requestId === 'string') out.requestId = rec.requestId;\n if (typeof rec.reauth === 'object' && rec.reauth !== null) {\n const r = rec.reauth as Record<string, unknown>;\n const reauth: ExtensionReauthMeta = {};\n if (typeof r.provider === 'string') reauth.provider = r.provider;\n if (typeof r.hint === 'string') reauth.hint = r.hint;\n out.reauth = reauth;\n }\n return out;\n}\n\nfunction fallbackKind(status: number): ExtensionErrorKind {\n if (status === 401) return 'session-expired';\n if (status === 403) return 'fga-denied';\n return 'extension-failure';\n}\n\nconst MAX_MESSAGE_LENGTH = 300;\n\nfunction sanitizeMessage(message: string): string {\n return message.length > MAX_MESSAGE_LENGTH\n ? `${message.slice(0, MAX_MESSAGE_LENGTH)}…`\n : message;\n}\n\nexport function classifyExtensionError(\n status: number,\n body: unknown,\n extension?: string,\n): AnyExtensionApiError {\n const parsed = parseBody(body);\n const mapped = parsed.code ? CODE_TO_KIND[parsed.code] : undefined;\n const kind = mapped ?? fallbackKind(status);\n const message = parsed.message !== undefined\n ? sanitizeMessage(parsed.message)\n : `extension invocation failed: ${status}`;\n const meta: { requestId?: string; extension?: string; reauth?: ExtensionReauthMeta } = {};\n if (parsed.requestId !== undefined) meta.requestId = parsed.requestId;\n if (extension !== undefined) meta.extension = extension;\n if (kind === 'session-expired' && parsed.reauth !== undefined) meta.reauth = parsed.reauth;\n const Cls = KIND_TO_CLASS[kind];\n return new Cls(status, message, meta);\n}\n","import { ApiError } from './api-error';\nimport { classifyExtensionError, ExtensionFailureError } from './extension-errors';\n\nexport { ApiError } from './api-error';\n\nexport 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' | 'template';\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 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 async invokeExtension<T>(\n name: string,\n path: string,\n init: { method?: string; body?: unknown } = {},\n ): Promise<T> {\n const token = await this.getToken();\n const res = await this.fetchImpl(\n `${this.baseUrl}/api/extensions/${encodeURIComponent(name)}${path}`,\n {\n method: init.method ?? 'GET',\n headers: {\n 'content-type': 'application/json',\n ...(token ? { authorization: `Bearer ${token}` } : {}),\n },\n body: init.body === undefined ? undefined : JSON.stringify(init.body),\n },\n );\n const text = await res.text();\n let parsed: unknown;\n let parseFailed = false;\n try {\n parsed = text ? JSON.parse(text) : undefined;\n } catch {\n parsed = undefined;\n parseFailed = true;\n }\n if (!res.ok) {\n throw classifyExtensionError(res.status, parsed, name);\n }\n if (parseFailed) {\n throw new ExtensionFailureError(\n res.status,\n `extension '${name}' returned a non-JSON response (${res.status})`,\n { extension: name },\n );\n }\n return parsed as T;\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;AAEO,SAAS,YAAyB;AACvC,QAAM,MAAM,WAAW,aAAa;AACpC,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,gDAAgD;AAC1E,SAAO;AACT;AAEO,SAAS,kBAAkB,WAAiF;AACjH,QAAM,YAAY,oBAAI,IAA0B;AAChD,QAAM,QAAQ;AAAA,IACZ,SAAS,UAAU,CAAC,KAAK;AAAA,IACzB;AAAA,IACA,YAAY;AAAA,IACZ,aAAa,OAAe,MAAe;AACzC,YAAM,OAAO,UAAU,KAAK,CAAC,MAAM,EAAE,UAAU,UAAU,SAAS,UAAa,EAAE,SAAS,KAAK;AAC/F,UAAI,CAAC,KAAM,OAAM,I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B,QAAI;AACJ,QAAI,cAAc;AAClB,QAAI;AACF,eAAS,OAAO,KAAK,MAAM,IAAI,IAAI;AAAA,IACrC,QAAQ;AACN,eAAS;AACT,oBAAc;AAAA,IAChB;AACA,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,uBAAuB,IAAI,QAAQ,QAAQ,IAAI;AAAA,IACvD;AACA,QAAI,aAAa;AACf,YAAM,IAAI;AAAA,QACR,IAAI;AAAA,QACJ,cAAc,IAAI,mCAAmC,IAAI,MAAM;AAAA,QAC/D,EAAE,WAAW,KAAK;AAAA,MACpB;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -108,6 +108,11 @@ interface SlotContext {
|
|
|
108
108
|
tenant: TenantState;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
declare class ApiError extends Error {
|
|
112
|
+
readonly status: number;
|
|
113
|
+
constructor(status: number, message: string);
|
|
114
|
+
}
|
|
115
|
+
|
|
111
116
|
interface Cluster {
|
|
112
117
|
id: string;
|
|
113
118
|
name: string;
|
|
@@ -147,10 +152,6 @@ interface ApiClientOptions {
|
|
|
147
152
|
getToken: () => Promise<string | undefined> | string | undefined;
|
|
148
153
|
fetchImpl?: typeof fetch;
|
|
149
154
|
}
|
|
150
|
-
declare class ApiError extends Error {
|
|
151
|
-
readonly status: number;
|
|
152
|
-
constructor(status: number, message: string);
|
|
153
|
-
}
|
|
154
155
|
declare class ApiClient {
|
|
155
156
|
private readonly baseUrl;
|
|
156
157
|
private readonly getToken;
|
|
@@ -165,6 +166,47 @@ declare class ApiClient {
|
|
|
165
166
|
getResourceInstance(id: string): Promise<ResourceInstance>;
|
|
166
167
|
listApprovals(): Promise<ApprovalRequest[]>;
|
|
167
168
|
approveApproval(id: string): Promise<ApprovalRequest>;
|
|
169
|
+
invokeExtension<T>(name: string, path: string, init?: {
|
|
170
|
+
method?: string;
|
|
171
|
+
body?: unknown;
|
|
172
|
+
}): Promise<T>;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
type ExtensionErrorKind = 'session-expired' | 'downstream-denied' | 'fga-denied' | 'exchange-failed' | 'extension-failure';
|
|
176
|
+
interface ExtensionReauthMeta {
|
|
177
|
+
provider?: string;
|
|
178
|
+
hint?: string;
|
|
179
|
+
}
|
|
180
|
+
declare abstract class ExtensionApiError extends ApiError {
|
|
181
|
+
abstract readonly kind: ExtensionErrorKind;
|
|
182
|
+
readonly retryable: boolean;
|
|
183
|
+
readonly requestId?: string;
|
|
184
|
+
readonly extension?: string;
|
|
185
|
+
readonly reauth?: ExtensionReauthMeta;
|
|
186
|
+
constructor(status: number, message: string, meta?: {
|
|
187
|
+
requestId?: string;
|
|
188
|
+
extension?: string;
|
|
189
|
+
reauth?: ExtensionReauthMeta;
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
declare class SessionExpiredError extends ExtensionApiError {
|
|
193
|
+
readonly kind: "session-expired";
|
|
194
|
+
readonly retryable = true;
|
|
195
|
+
}
|
|
196
|
+
declare class DownstreamDeniedError extends ExtensionApiError {
|
|
197
|
+
readonly kind: "downstream-denied";
|
|
198
|
+
}
|
|
199
|
+
declare class FgaDeniedError extends ExtensionApiError {
|
|
200
|
+
readonly kind: "fga-denied";
|
|
201
|
+
}
|
|
202
|
+
declare class ExchangeFailedError extends ExtensionApiError {
|
|
203
|
+
readonly kind: "exchange-failed";
|
|
204
|
+
}
|
|
205
|
+
declare class ExtensionFailureError extends ExtensionApiError {
|
|
206
|
+
readonly kind: "extension-failure";
|
|
168
207
|
}
|
|
208
|
+
type AnyExtensionApiError = SessionExpiredError | DownstreamDeniedError | FgaDeniedError | ExchangeFailedError | ExtensionFailureError;
|
|
209
|
+
declare function isExtensionApiError(err: unknown): err is ExtensionApiError;
|
|
210
|
+
declare function classifyExtensionError(status: number, body: unknown, extension?: string): AnyExtensionApiError;
|
|
169
211
|
|
|
170
|
-
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,
|
|
212
|
+
export { type AnySlotContribution as A, extensionManifestSchema as B, type CatalogItem as C, DownstreamDeniedError as D, type ExtensionManifestInput as E, FgaDeniedError as F, getAuthState as G, isExtensionApiError as H, type InariExtension as I, parseExtensionManifest as J, useAuth as K, usePrincipal as L, useTenant as M, type ParsedExtensionManifest as P, type ResourceInstance as R, type SlotContribution as S, type TenantChangeEvent as T, type Cluster as a, type SlotContext as b, type AnyExtensionApiError as c, ApiClient as d, type ApiClientOptions as e, ApiError as f, type ApprovalRequest as g, AuthContext as h, AuthProvider as i, type AuthState as j, ExchangeFailedError as k, ExtensionApiError as l, type ExtensionErrorKind as m, ExtensionFailureError as n, type ExtensionReauthMeta as o, type Principal as p, SLOT_KINDS as q, SessionExpiredError as r, type SlotKind as s, type TenantChangeListener as t, TenantContext as u, TenantProvider as v, type TenantRef as w, type TenantState as x, classifyExtensionError as y, createTenantState as z };
|
|
@@ -108,6 +108,11 @@ interface SlotContext {
|
|
|
108
108
|
tenant: TenantState;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
declare class ApiError extends Error {
|
|
112
|
+
readonly status: number;
|
|
113
|
+
constructor(status: number, message: string);
|
|
114
|
+
}
|
|
115
|
+
|
|
111
116
|
interface Cluster {
|
|
112
117
|
id: string;
|
|
113
118
|
name: string;
|
|
@@ -147,10 +152,6 @@ interface ApiClientOptions {
|
|
|
147
152
|
getToken: () => Promise<string | undefined> | string | undefined;
|
|
148
153
|
fetchImpl?: typeof fetch;
|
|
149
154
|
}
|
|
150
|
-
declare class ApiError extends Error {
|
|
151
|
-
readonly status: number;
|
|
152
|
-
constructor(status: number, message: string);
|
|
153
|
-
}
|
|
154
155
|
declare class ApiClient {
|
|
155
156
|
private readonly baseUrl;
|
|
156
157
|
private readonly getToken;
|
|
@@ -165,6 +166,47 @@ declare class ApiClient {
|
|
|
165
166
|
getResourceInstance(id: string): Promise<ResourceInstance>;
|
|
166
167
|
listApprovals(): Promise<ApprovalRequest[]>;
|
|
167
168
|
approveApproval(id: string): Promise<ApprovalRequest>;
|
|
169
|
+
invokeExtension<T>(name: string, path: string, init?: {
|
|
170
|
+
method?: string;
|
|
171
|
+
body?: unknown;
|
|
172
|
+
}): Promise<T>;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
type ExtensionErrorKind = 'session-expired' | 'downstream-denied' | 'fga-denied' | 'exchange-failed' | 'extension-failure';
|
|
176
|
+
interface ExtensionReauthMeta {
|
|
177
|
+
provider?: string;
|
|
178
|
+
hint?: string;
|
|
179
|
+
}
|
|
180
|
+
declare abstract class ExtensionApiError extends ApiError {
|
|
181
|
+
abstract readonly kind: ExtensionErrorKind;
|
|
182
|
+
readonly retryable: boolean;
|
|
183
|
+
readonly requestId?: string;
|
|
184
|
+
readonly extension?: string;
|
|
185
|
+
readonly reauth?: ExtensionReauthMeta;
|
|
186
|
+
constructor(status: number, message: string, meta?: {
|
|
187
|
+
requestId?: string;
|
|
188
|
+
extension?: string;
|
|
189
|
+
reauth?: ExtensionReauthMeta;
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
declare class SessionExpiredError extends ExtensionApiError {
|
|
193
|
+
readonly kind: "session-expired";
|
|
194
|
+
readonly retryable = true;
|
|
195
|
+
}
|
|
196
|
+
declare class DownstreamDeniedError extends ExtensionApiError {
|
|
197
|
+
readonly kind: "downstream-denied";
|
|
198
|
+
}
|
|
199
|
+
declare class FgaDeniedError extends ExtensionApiError {
|
|
200
|
+
readonly kind: "fga-denied";
|
|
201
|
+
}
|
|
202
|
+
declare class ExchangeFailedError extends ExtensionApiError {
|
|
203
|
+
readonly kind: "exchange-failed";
|
|
204
|
+
}
|
|
205
|
+
declare class ExtensionFailureError extends ExtensionApiError {
|
|
206
|
+
readonly kind: "extension-failure";
|
|
168
207
|
}
|
|
208
|
+
type AnyExtensionApiError = SessionExpiredError | DownstreamDeniedError | FgaDeniedError | ExchangeFailedError | ExtensionFailureError;
|
|
209
|
+
declare function isExtensionApiError(err: unknown): err is ExtensionApiError;
|
|
210
|
+
declare function classifyExtensionError(status: number, body: unknown, extension?: string): AnyExtensionApiError;
|
|
169
211
|
|
|
170
|
-
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,
|
|
212
|
+
export { type AnySlotContribution as A, extensionManifestSchema as B, type CatalogItem as C, DownstreamDeniedError as D, type ExtensionManifestInput as E, FgaDeniedError as F, getAuthState as G, isExtensionApiError as H, type InariExtension as I, parseExtensionManifest as J, useAuth as K, usePrincipal as L, useTenant as M, type ParsedExtensionManifest as P, type ResourceInstance as R, type SlotContribution as S, type TenantChangeEvent as T, type Cluster as a, type SlotContext as b, type AnyExtensionApiError as c, ApiClient as d, type ApiClientOptions as e, ApiError as f, type ApprovalRequest as g, AuthContext as h, AuthProvider as i, type AuthState as j, ExchangeFailedError as k, ExtensionApiError as l, type ExtensionErrorKind as m, ExtensionFailureError as n, type ExtensionReauthMeta as o, type Principal as p, SLOT_KINDS as q, SessionExpiredError as r, type SlotKind as s, type TenantChangeListener as t, TenantContext as u, TenantProvider as v, type TenantRef as w, type TenantState as x, classifyExtensionError as y, createTenantState as z };
|
package/dist/index.cjs
CHANGED
|
@@ -26,17 +26,25 @@ __export(src_exports, {
|
|
|
26
26
|
AuthProvider: () => AuthProvider,
|
|
27
27
|
CatalogCardBlueprint: () => CatalogCardBlueprint,
|
|
28
28
|
ClusterTabBlueprint: () => ClusterTabBlueprint,
|
|
29
|
+
DownstreamDeniedError: () => DownstreamDeniedError,
|
|
30
|
+
ExchangeFailedError: () => ExchangeFailedError,
|
|
31
|
+
ExtensionApiError: () => ExtensionApiError,
|
|
32
|
+
ExtensionFailureError: () => ExtensionFailureError,
|
|
33
|
+
FgaDeniedError: () => FgaDeniedError,
|
|
29
34
|
FormWidgetBlueprint: () => FormWidgetBlueprint,
|
|
30
35
|
InstanceActionBlueprint: () => InstanceActionBlueprint,
|
|
31
36
|
NavItemBlueprint: () => NavItemBlueprint,
|
|
32
37
|
PageBlueprint: () => PageBlueprint,
|
|
33
38
|
SLOT_KINDS: () => SLOT_KINDS,
|
|
39
|
+
SessionExpiredError: () => SessionExpiredError,
|
|
34
40
|
TenantContext: () => TenantContext,
|
|
35
41
|
TenantProvider: () => TenantProvider,
|
|
42
|
+
classifyExtensionError: () => classifyExtensionError,
|
|
36
43
|
createExtension: () => createExtension,
|
|
37
44
|
createTenantState: () => createTenantState,
|
|
38
45
|
extensionManifestSchema: () => extensionManifestSchema,
|
|
39
46
|
getAuthState: () => getAuthState,
|
|
47
|
+
isExtensionApiError: () => isExtensionApiError,
|
|
40
48
|
parseExtensionManifest: () => parseExtensionManifest,
|
|
41
49
|
useAuth: () => useAuth,
|
|
42
50
|
usePrincipal: () => usePrincipal,
|
|
@@ -187,7 +195,7 @@ function createTenantState(available) {
|
|
|
187
195
|
return state;
|
|
188
196
|
}
|
|
189
197
|
|
|
190
|
-
// src/host/api.ts
|
|
198
|
+
// src/host/api-error.ts
|
|
191
199
|
var ApiError = class extends Error {
|
|
192
200
|
constructor(status, message) {
|
|
193
201
|
super(message);
|
|
@@ -196,6 +204,97 @@ var ApiError = class extends Error {
|
|
|
196
204
|
}
|
|
197
205
|
status;
|
|
198
206
|
};
|
|
207
|
+
|
|
208
|
+
// src/host/extension-errors.ts
|
|
209
|
+
var CODE_TO_KIND = {
|
|
210
|
+
session_expired: "session-expired",
|
|
211
|
+
reauth_required: "session-expired",
|
|
212
|
+
downstream_permission_denied: "downstream-denied",
|
|
213
|
+
fga_denied: "fga-denied",
|
|
214
|
+
permission_denied: "fga-denied",
|
|
215
|
+
exchange_failed: "exchange-failed",
|
|
216
|
+
auth_model_failure: "exchange-failed"
|
|
217
|
+
};
|
|
218
|
+
var ExtensionApiError = class extends ApiError {
|
|
219
|
+
retryable = false;
|
|
220
|
+
requestId;
|
|
221
|
+
extension;
|
|
222
|
+
reauth;
|
|
223
|
+
constructor(status, message, meta = {}) {
|
|
224
|
+
super(status, message);
|
|
225
|
+
this.name = new.target.name;
|
|
226
|
+
if (meta.requestId !== void 0) this.requestId = meta.requestId;
|
|
227
|
+
if (meta.extension !== void 0) this.extension = meta.extension;
|
|
228
|
+
if (meta.reauth !== void 0) this.reauth = meta.reauth;
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
var SessionExpiredError = class extends ExtensionApiError {
|
|
232
|
+
kind = "session-expired";
|
|
233
|
+
retryable = true;
|
|
234
|
+
};
|
|
235
|
+
var DownstreamDeniedError = class extends ExtensionApiError {
|
|
236
|
+
kind = "downstream-denied";
|
|
237
|
+
};
|
|
238
|
+
var FgaDeniedError = class extends ExtensionApiError {
|
|
239
|
+
kind = "fga-denied";
|
|
240
|
+
};
|
|
241
|
+
var ExchangeFailedError = class extends ExtensionApiError {
|
|
242
|
+
kind = "exchange-failed";
|
|
243
|
+
};
|
|
244
|
+
var ExtensionFailureError = class extends ExtensionApiError {
|
|
245
|
+
kind = "extension-failure";
|
|
246
|
+
};
|
|
247
|
+
var KIND_TO_CLASS = {
|
|
248
|
+
"session-expired": SessionExpiredError,
|
|
249
|
+
"downstream-denied": DownstreamDeniedError,
|
|
250
|
+
"fga-denied": FgaDeniedError,
|
|
251
|
+
"exchange-failed": ExchangeFailedError,
|
|
252
|
+
"extension-failure": ExtensionFailureError
|
|
253
|
+
};
|
|
254
|
+
function isExtensionApiError(err) {
|
|
255
|
+
return err instanceof ExtensionApiError;
|
|
256
|
+
}
|
|
257
|
+
function parseBody(body) {
|
|
258
|
+
if (typeof body !== "object" || body === null) return {};
|
|
259
|
+
const err = body.error;
|
|
260
|
+
if (typeof err !== "object" || err === null) return {};
|
|
261
|
+
const rec = err;
|
|
262
|
+
const out = {};
|
|
263
|
+
if (typeof rec.code === "string") out.code = rec.code;
|
|
264
|
+
if (typeof rec.message === "string") out.message = rec.message;
|
|
265
|
+
if (typeof rec.requestId === "string") out.requestId = rec.requestId;
|
|
266
|
+
if (typeof rec.reauth === "object" && rec.reauth !== null) {
|
|
267
|
+
const r = rec.reauth;
|
|
268
|
+
const reauth = {};
|
|
269
|
+
if (typeof r.provider === "string") reauth.provider = r.provider;
|
|
270
|
+
if (typeof r.hint === "string") reauth.hint = r.hint;
|
|
271
|
+
out.reauth = reauth;
|
|
272
|
+
}
|
|
273
|
+
return out;
|
|
274
|
+
}
|
|
275
|
+
function fallbackKind(status) {
|
|
276
|
+
if (status === 401) return "session-expired";
|
|
277
|
+
if (status === 403) return "fga-denied";
|
|
278
|
+
return "extension-failure";
|
|
279
|
+
}
|
|
280
|
+
var MAX_MESSAGE_LENGTH = 300;
|
|
281
|
+
function sanitizeMessage(message) {
|
|
282
|
+
return message.length > MAX_MESSAGE_LENGTH ? `${message.slice(0, MAX_MESSAGE_LENGTH)}\u2026` : message;
|
|
283
|
+
}
|
|
284
|
+
function classifyExtensionError(status, body, extension) {
|
|
285
|
+
const parsed = parseBody(body);
|
|
286
|
+
const mapped = parsed.code ? CODE_TO_KIND[parsed.code] : void 0;
|
|
287
|
+
const kind = mapped ?? fallbackKind(status);
|
|
288
|
+
const message = parsed.message !== void 0 ? sanitizeMessage(parsed.message) : `extension invocation failed: ${status}`;
|
|
289
|
+
const meta = {};
|
|
290
|
+
if (parsed.requestId !== void 0) meta.requestId = parsed.requestId;
|
|
291
|
+
if (extension !== void 0) meta.extension = extension;
|
|
292
|
+
if (kind === "session-expired" && parsed.reauth !== void 0) meta.reauth = parsed.reauth;
|
|
293
|
+
const Cls = KIND_TO_CLASS[kind];
|
|
294
|
+
return new Cls(status, message, meta);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// src/host/api.ts
|
|
199
298
|
var ApiClient = class {
|
|
200
299
|
baseUrl;
|
|
201
300
|
getToken;
|
|
@@ -247,6 +346,40 @@ var ApiClient = class {
|
|
|
247
346
|
approveApproval(id) {
|
|
248
347
|
return this.request("POST", `/api/v1/approvals/${encodeURIComponent(id)}/approve`);
|
|
249
348
|
}
|
|
349
|
+
async invokeExtension(name, path, init = {}) {
|
|
350
|
+
const token = await this.getToken();
|
|
351
|
+
const res = await this.fetchImpl(
|
|
352
|
+
`${this.baseUrl}/api/extensions/${encodeURIComponent(name)}${path}`,
|
|
353
|
+
{
|
|
354
|
+
method: init.method ?? "GET",
|
|
355
|
+
headers: {
|
|
356
|
+
"content-type": "application/json",
|
|
357
|
+
...token ? { authorization: `Bearer ${token}` } : {}
|
|
358
|
+
},
|
|
359
|
+
body: init.body === void 0 ? void 0 : JSON.stringify(init.body)
|
|
360
|
+
}
|
|
361
|
+
);
|
|
362
|
+
const text = await res.text();
|
|
363
|
+
let parsed;
|
|
364
|
+
let parseFailed = false;
|
|
365
|
+
try {
|
|
366
|
+
parsed = text ? JSON.parse(text) : void 0;
|
|
367
|
+
} catch {
|
|
368
|
+
parsed = void 0;
|
|
369
|
+
parseFailed = true;
|
|
370
|
+
}
|
|
371
|
+
if (!res.ok) {
|
|
372
|
+
throw classifyExtensionError(res.status, parsed, name);
|
|
373
|
+
}
|
|
374
|
+
if (parseFailed) {
|
|
375
|
+
throw new ExtensionFailureError(
|
|
376
|
+
res.status,
|
|
377
|
+
`extension '${name}' returned a non-JSON response (${res.status})`,
|
|
378
|
+
{ extension: name }
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
return parsed;
|
|
382
|
+
}
|
|
250
383
|
};
|
|
251
384
|
// Annotate the CommonJS export names for ESM import in node:
|
|
252
385
|
0 && (module.exports = {
|
|
@@ -256,17 +389,25 @@ var ApiClient = class {
|
|
|
256
389
|
AuthProvider,
|
|
257
390
|
CatalogCardBlueprint,
|
|
258
391
|
ClusterTabBlueprint,
|
|
392
|
+
DownstreamDeniedError,
|
|
393
|
+
ExchangeFailedError,
|
|
394
|
+
ExtensionApiError,
|
|
395
|
+
ExtensionFailureError,
|
|
396
|
+
FgaDeniedError,
|
|
259
397
|
FormWidgetBlueprint,
|
|
260
398
|
InstanceActionBlueprint,
|
|
261
399
|
NavItemBlueprint,
|
|
262
400
|
PageBlueprint,
|
|
263
401
|
SLOT_KINDS,
|
|
402
|
+
SessionExpiredError,
|
|
264
403
|
TenantContext,
|
|
265
404
|
TenantProvider,
|
|
405
|
+
classifyExtensionError,
|
|
266
406
|
createExtension,
|
|
267
407
|
createTenantState,
|
|
268
408
|
extensionManifestSchema,
|
|
269
409
|
getAuthState,
|
|
410
|
+
isExtensionApiError,
|
|
270
411
|
parseExtensionManifest,
|
|
271
412
|
useAuth,
|
|
272
413
|
usePrincipal,
|