@bodhiapp/bodhi-js-react 0.0.4 → 0.0.6
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/bodhi-browser-ext/src/types/bodhiext.d.ts +0 -1
- package/dist/bodhi-browser-ext/src/types/common.d.ts +1 -0
- package/dist/bodhi-browser-ext/src/types/protocol.d.ts +0 -1
- package/dist/bodhi-js-sdk/core/src/direct-client-base.d.ts +5 -5
- package/dist/bodhi-js-sdk/core/src/errors.d.ts +0 -1
- package/dist/bodhi-js-sdk/core/src/facade-client-base.d.ts +5 -6
- package/dist/bodhi-js-sdk/core/src/interface.d.ts +14 -7
- package/dist/bodhi-js-sdk/core/src/logger.d.ts +0 -1
- package/dist/bodhi-js-sdk/core/src/oauth.d.ts +0 -1
- package/dist/bodhi-js-sdk/core/src/onboarding/config.d.ts +0 -1
- package/dist/bodhi-js-sdk/core/src/onboarding/modal.d.ts +1 -2
- package/dist/bodhi-js-sdk/core/src/onboarding/protocol-utils.d.ts +0 -1
- package/dist/bodhi-js-sdk/core/src/platform.d.ts +0 -1
- package/dist/bodhi-js-sdk/core/src/types/api.d.ts +0 -1
- package/dist/bodhi-js-sdk/core/src/types/auth.d.ts +37 -0
- package/dist/bodhi-js-sdk/core/src/types/callback.d.ts +1 -2
- package/dist/bodhi-js-sdk/core/src/types/client-state.d.ts +43 -94
- package/dist/bodhi-js-sdk/core/src/types/config.d.ts +0 -1
- package/dist/bodhi-js-sdk/core/src/types/index.d.ts +4 -3
- package/dist/bodhi-js-sdk/core/src/types/platform.d.ts +0 -1
- package/dist/bodhi-js-sdk/core/src/types/user-info.d.ts +0 -32
- package/dist/bodhi-js-sdk/react/src/BodhiProvider.d.ts +10 -3
- package/dist/bodhi-js-sdk/react/src/SetupModalProcessor.d.ts +0 -1
- package/dist/bodhi-js-sdk/react/src/client-ctx.d.ts +16 -24
- package/dist/bodhi-js-sdk/react/src/index.d.ts +5 -4
- package/dist/bodhi-react.cjs.js +2 -2
- package/dist/bodhi-react.esm.d.ts +1 -0
- package/dist/bodhi-react.esm.js +292 -253
- package/dist/setup-modal/src/types/message-types.d.ts +0 -1
- package/dist/setup-modal/src/types/protocol.d.ts +0 -1
- package/dist/setup-modal/src/types/state.d.ts +0 -1
- package/dist/setup-modal/src/types/type-guards.d.ts +0 -1
- package/package.json +10 -6
package/dist/bodhi-react.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { Logger as
|
|
3
|
-
import { createApiError as
|
|
4
|
-
import { useMemo as
|
|
1
|
+
import { jsxs as F, jsx as H } from "react/jsx-runtime";
|
|
2
|
+
import { Logger as B, BodhiClientUserPrefsManager as G, createStoragePrefixWithBasePath as K, detectBrowser as V, detectOS as W, getServerUrl as j, isDirectServerReady as Y, isExtensionServerReady as q, OS_CONFIGS as X, BROWSER_CONFIGS as J, OnboardingModal as Z, BACKEND_SERVER_NOT_CONNECTED as P, isExtensionState as Q, INITIAL_AUTH_STATE as $, NOOP_STATE_CALLBACK as ee, isWebUIClient as te } from "@bodhiapp/bodhi-js-core";
|
|
3
|
+
import { createApiError as Ae, createOperationError as Oe, isApiResultError as Le, isApiResultOperationError as he, isApiResultSuccess as we, isAuthError as xe, isAuthLoading as Ie, isAuthenticated as _e, isClientReady as Re, isDirectState as De, isExtensionState as Me, isOperationError as Ne, isWebUIClient as Te } from "@bodhiapp/bodhi-js-core";
|
|
4
|
+
import { useMemo as _, useRef as T, useCallback as d, useEffect as b, createContext as re, useState as N, useContext as ne } from "react";
|
|
5
5
|
const m = {
|
|
6
6
|
// Modal lifecycle
|
|
7
7
|
MODAL_READY: "modal:ready",
|
|
@@ -16,22 +16,22 @@ const m = {
|
|
|
16
16
|
// Connection selection
|
|
17
17
|
MODAL_SELECT_CONNECTION: "modal:select-connection"
|
|
18
18
|
};
|
|
19
|
-
function
|
|
19
|
+
function se({
|
|
20
20
|
client: e,
|
|
21
|
-
modalHtmlPath:
|
|
22
|
-
hideSetup:
|
|
23
|
-
onSetupReady:
|
|
24
|
-
setupState:
|
|
25
|
-
basePath:
|
|
26
|
-
logLevel:
|
|
21
|
+
modalHtmlPath: o,
|
|
22
|
+
hideSetup: w,
|
|
23
|
+
onSetupReady: x,
|
|
24
|
+
setupState: R,
|
|
25
|
+
basePath: g = "/",
|
|
26
|
+
logLevel: A = "warn"
|
|
27
27
|
}) {
|
|
28
|
-
const
|
|
29
|
-
() => new
|
|
30
|
-
[
|
|
31
|
-
), f =
|
|
28
|
+
const p = R !== "ready", E = _(() => new B("SetupModalProcessor", A), [A]), u = T(null), a = _(
|
|
29
|
+
() => new G(K(g, "bodhijs:")),
|
|
30
|
+
[g]
|
|
31
|
+
), f = T(null), v = d(
|
|
32
32
|
(t) => t === "direct" ? "lna" : t === "extension" ? "extension" : null,
|
|
33
33
|
[]
|
|
34
|
-
),
|
|
34
|
+
), y = d((t) => t.extension === "ready" ? {
|
|
35
35
|
status: "ready",
|
|
36
36
|
version: "unknown",
|
|
37
37
|
// TODO: have ExtensionState also get extension version
|
|
@@ -42,7 +42,7 @@ function ae({
|
|
|
42
42
|
} : {
|
|
43
43
|
status: "unreachable",
|
|
44
44
|
error: { message: "Client not initialized", code: "ext-connection-failed" }
|
|
45
|
-
}, []),
|
|
45
|
+
}, []), O = d((t) => {
|
|
46
46
|
if (t.server.status === "pending-extension-ready")
|
|
47
47
|
return {
|
|
48
48
|
status: "pending-extension-ready",
|
|
@@ -51,46 +51,74 @@ function ae({
|
|
|
51
51
|
const r = t.server;
|
|
52
52
|
switch (r.status) {
|
|
53
53
|
case "ready":
|
|
54
|
-
return { status: "ready", version: r.version };
|
|
54
|
+
return { status: "ready", version: r.version || "unknown" };
|
|
55
55
|
case "setup":
|
|
56
56
|
return {
|
|
57
57
|
status: "setup",
|
|
58
|
-
version: r.version,
|
|
59
|
-
error: {
|
|
58
|
+
version: r.version || "unknown",
|
|
59
|
+
error: {
|
|
60
|
+
message: r.error?.message || "Setup required",
|
|
61
|
+
code: "server-in-setup-status"
|
|
62
|
+
}
|
|
60
63
|
};
|
|
61
64
|
case "resource-admin":
|
|
62
65
|
return {
|
|
63
66
|
status: "resource-admin",
|
|
64
|
-
version: r.version,
|
|
65
|
-
error: {
|
|
67
|
+
version: r.version || "unknown",
|
|
68
|
+
error: {
|
|
69
|
+
message: r.error?.message || "Resource admin required",
|
|
70
|
+
code: "server-in-admin-status"
|
|
71
|
+
}
|
|
66
72
|
};
|
|
67
73
|
case "error":
|
|
68
74
|
return {
|
|
69
75
|
status: "error",
|
|
70
|
-
error: {
|
|
76
|
+
error: {
|
|
77
|
+
message: r.error?.message || "Unknown error",
|
|
78
|
+
code: "server-unexpected-error"
|
|
79
|
+
}
|
|
71
80
|
};
|
|
72
81
|
case "not-reachable":
|
|
73
82
|
return {
|
|
74
83
|
status: "unreachable",
|
|
75
|
-
error: {
|
|
84
|
+
error: {
|
|
85
|
+
message: r.error?.message || "Server not reachable",
|
|
86
|
+
code: "server-conn-refused"
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
default:
|
|
90
|
+
return {
|
|
91
|
+
status: "unreachable",
|
|
92
|
+
error: {
|
|
93
|
+
message: "Unknown server status",
|
|
94
|
+
code: "server-unexpected-error"
|
|
95
|
+
}
|
|
76
96
|
};
|
|
77
97
|
}
|
|
78
|
-
}, []),
|
|
98
|
+
}, []), C = d((t) => {
|
|
79
99
|
if (t.server.status === "not-connected")
|
|
80
100
|
return { status: "pending-lna-ready" };
|
|
81
101
|
const r = t.server;
|
|
82
102
|
switch (r.status) {
|
|
83
103
|
case "ready":
|
|
84
|
-
return { status: "ready", version: r.version };
|
|
104
|
+
return { status: "ready", version: r.version || "unknown" };
|
|
85
105
|
case "setup":
|
|
86
|
-
return { status: "setup", version: r.version };
|
|
106
|
+
return { status: "setup", version: r.version || "unknown" };
|
|
87
107
|
case "resource-admin":
|
|
88
|
-
return { status: "resource-admin", version: r.version };
|
|
108
|
+
return { status: "resource-admin", version: r.version || "unknown" };
|
|
89
109
|
case "error":
|
|
90
110
|
case "not-reachable":
|
|
91
|
-
return {
|
|
111
|
+
return {
|
|
112
|
+
status: "error",
|
|
113
|
+
error: { message: r.error?.message || "Connection error" }
|
|
114
|
+
};
|
|
115
|
+
default:
|
|
116
|
+
return {
|
|
117
|
+
status: "error",
|
|
118
|
+
error: { message: "Unknown server status" }
|
|
119
|
+
};
|
|
92
120
|
}
|
|
93
|
-
}, []),
|
|
121
|
+
}, []), L = d(
|
|
94
122
|
(t, r) => {
|
|
95
123
|
if (t.server.status !== "pending-extension-ready") {
|
|
96
124
|
const s = t.server.status;
|
|
@@ -105,330 +133,341 @@ function ae({
|
|
|
105
133
|
return !1;
|
|
106
134
|
},
|
|
107
135
|
[]
|
|
108
|
-
),
|
|
136
|
+
), h = d(
|
|
109
137
|
(t, r, s) => {
|
|
110
138
|
if (r === "skipped")
|
|
111
139
|
return { status: "skipped", serverUrl: s };
|
|
112
140
|
if (t.server.status !== "not-connected") {
|
|
113
|
-
const
|
|
114
|
-
return
|
|
141
|
+
const c = t.server;
|
|
142
|
+
return c.status === "ready" || c.status === "setup" || c.status === "resource-admin" ? { status: "granted", serverUrl: s } : {
|
|
115
143
|
status: "unreachable",
|
|
116
144
|
serverUrl: s,
|
|
117
|
-
error: {
|
|
145
|
+
error: {
|
|
146
|
+
message: c.error?.message || "Server unreachable",
|
|
147
|
+
code: "lna-unreachable"
|
|
148
|
+
}
|
|
118
149
|
};
|
|
119
150
|
}
|
|
120
151
|
return r === "granted" ? { status: "granted", serverUrl: s } : { status: "prompt", serverUrl: s };
|
|
121
152
|
},
|
|
122
153
|
[]
|
|
123
|
-
),
|
|
154
|
+
), S = d(
|
|
124
155
|
async (t = !1) => {
|
|
125
|
-
const r =
|
|
126
|
-
let
|
|
127
|
-
(
|
|
128
|
-
let
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
return e.getConnectionMode() === null && (
|
|
133
|
-
extension:
|
|
134
|
-
server:
|
|
135
|
-
lna:
|
|
136
|
-
lnaServer:
|
|
156
|
+
const r = V().type, s = W().type;
|
|
157
|
+
let c = await e.getExtensionState();
|
|
158
|
+
(c.extension === "not-initialized" || t) && (c = await e.testExtensionConnectivity());
|
|
159
|
+
let n = await e.getDirectState();
|
|
160
|
+
const i = a.getDirectStatus();
|
|
161
|
+
i === "granted" && (n.server.status === "not-connected" || t) && (n = await e.testDirectConnectivity());
|
|
162
|
+
const M = j(n) || "http://localhost:1135", I = h(n, i, M);
|
|
163
|
+
return e.getConnectionMode() === null && (Y(n) ? await e.setConnectionMode("direct") : q(c) && await e.setConnectionMode("extension")), a.isServerInstallConfirmed() || L(c, n) && a.setServerInstallConfirmed(!0), {
|
|
164
|
+
extension: y(c),
|
|
165
|
+
server: O(c),
|
|
166
|
+
lna: I,
|
|
167
|
+
lnaServer: C(n),
|
|
137
168
|
env: { browser: r, os: s },
|
|
138
|
-
browsers:
|
|
139
|
-
os:
|
|
140
|
-
userConfirmations: { serverInstall:
|
|
141
|
-
selectedConnection:
|
|
169
|
+
browsers: J,
|
|
170
|
+
os: X,
|
|
171
|
+
userConfirmations: { serverInstall: a.isServerInstallConfirmed() },
|
|
172
|
+
selectedConnection: v(e.getConnectionMode())
|
|
142
173
|
};
|
|
143
174
|
},
|
|
144
175
|
[
|
|
145
176
|
e,
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
177
|
+
a,
|
|
178
|
+
y,
|
|
179
|
+
O,
|
|
180
|
+
C,
|
|
181
|
+
v,
|
|
182
|
+
h,
|
|
183
|
+
L
|
|
153
184
|
]
|
|
154
|
-
), l =
|
|
185
|
+
), l = d(() => {
|
|
155
186
|
if (!f.current)
|
|
156
187
|
throw new Error("Cannot get state: currentStateRef is null");
|
|
157
188
|
return {
|
|
158
189
|
...f.current,
|
|
159
190
|
// Override userConfirmations from storage (in case updated outside buildSetupState)
|
|
160
191
|
userConfirmations: {
|
|
161
|
-
serverInstall:
|
|
192
|
+
serverInstall: a.isServerInstallConfirmed()
|
|
162
193
|
},
|
|
163
194
|
// Override selectedConnection from client (in case changed via handler)
|
|
164
|
-
selectedConnection:
|
|
195
|
+
selectedConnection: v(e.getConnectionMode())
|
|
165
196
|
};
|
|
166
|
-
}, [
|
|
197
|
+
}, [a, e, v]), D = _(
|
|
167
198
|
() => ({
|
|
168
|
-
[m.MODAL_READY]: async () => (
|
|
199
|
+
[m.MODAL_READY]: async () => (E.info("MODAL_READY: building initial state"), { setupState: l() }),
|
|
169
200
|
[m.MODAL_REFRESH]: async () => {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const t = await d(!0);
|
|
201
|
+
E.info("MODAL_REFRESH: refreshing state");
|
|
202
|
+
const t = await S(!0);
|
|
173
203
|
f.current = t;
|
|
174
204
|
const r = l();
|
|
175
|
-
return
|
|
176
|
-
`, JSON.stringify(r, null, 2)),
|
|
205
|
+
return E.info(`MODAL_REFRESH: state refreshed
|
|
206
|
+
`, JSON.stringify(r, null, 2)), u.current?.updateState(l()), { setupState: r };
|
|
177
207
|
},
|
|
178
208
|
[m.MODAL_LNA_CONNECT]: async (t) => {
|
|
179
|
-
var o, C;
|
|
180
209
|
const r = t.payload.serverUrl;
|
|
181
210
|
console.log("[SetupModalProcessor] LNA connect:", r);
|
|
182
211
|
const s = await e.testDirectConnectivity(r);
|
|
183
212
|
if (s.server.status !== "not-connected") {
|
|
184
|
-
const
|
|
185
|
-
if (
|
|
186
|
-
|
|
187
|
-
const
|
|
188
|
-
return f.current =
|
|
213
|
+
const n = s.server.status;
|
|
214
|
+
if (n === "ready" || n === "setup" || n === "resource-admin") {
|
|
215
|
+
a.setDirectStatus("granted"), e.getConnectionMode() === null && await e.setConnectionMode("direct");
|
|
216
|
+
const i = await S();
|
|
217
|
+
return f.current = i, u.current?.updateState(l()), { success: !0 };
|
|
189
218
|
}
|
|
190
219
|
}
|
|
191
|
-
const
|
|
192
|
-
return f.current =
|
|
220
|
+
const c = await S();
|
|
221
|
+
return f.current = c, u.current?.updateState(l()), { success: !1 };
|
|
193
222
|
},
|
|
194
223
|
[m.MODAL_LNA_SKIP]: async () => {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
return f.current = t, (r = i.current) == null || r.updateState(l()), { success: !0 };
|
|
224
|
+
a.setDirectStatus("skipped");
|
|
225
|
+
const t = await S();
|
|
226
|
+
return f.current = t, u.current?.updateState(l()), { success: !0 };
|
|
199
227
|
},
|
|
200
228
|
[m.MODAL_CLOSE]: () => {
|
|
201
|
-
|
|
229
|
+
w();
|
|
202
230
|
},
|
|
203
231
|
[m.MODAL_COMPLETE]: () => {
|
|
204
|
-
|
|
205
|
-
},
|
|
206
|
-
[m.MODAL_CONFIRM_SERVER_INSTALL]: (t) => {
|
|
207
|
-
var r;
|
|
208
|
-
return u.setServerInstallConfirmed(t.payload.confirmed), (r = i.current) == null || r.updateState(l()), { success: !0 };
|
|
232
|
+
w();
|
|
209
233
|
},
|
|
234
|
+
[m.MODAL_CONFIRM_SERVER_INSTALL]: (t) => (a.setServerInstallConfirmed(t.payload.confirmed), u.current?.updateState(l()), { success: !0 }),
|
|
210
235
|
[m.MODAL_SELECT_CONNECTION]: async (t) => {
|
|
211
|
-
var n;
|
|
212
236
|
const s = t.payload.connection === "lna" ? "direct" : "extension";
|
|
213
|
-
return await e.setConnectionMode(s),
|
|
237
|
+
return await e.setConnectionMode(s), u.current?.updateState(l()), { success: !0 };
|
|
214
238
|
}
|
|
215
239
|
}),
|
|
216
|
-
[
|
|
240
|
+
[E, e, a, S, l, C, w]
|
|
217
241
|
);
|
|
218
|
-
return
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
var r;
|
|
224
|
-
f.current = t, (r = i.current) == null || r.show(t), S == null || S();
|
|
242
|
+
return b(() => (u.current = new Z({ modalHtmlPath: o, handlers: D }), () => {
|
|
243
|
+
u.current?.destroy(), u.current = null;
|
|
244
|
+
}), [o, D]), b(() => {
|
|
245
|
+
p && u.current ? S(!0).then((t) => {
|
|
246
|
+
f.current = t, u.current?.show(t), x?.();
|
|
225
247
|
}).catch((t) => {
|
|
226
248
|
console.error("[SetupModalProcessor] buildSetupState failed:", t);
|
|
227
|
-
}) : !
|
|
228
|
-
}, [
|
|
249
|
+
}) : !p && u.current && u.current.destroy();
|
|
250
|
+
}, [p, S, x]), null;
|
|
251
|
+
}
|
|
252
|
+
const oe = {
|
|
253
|
+
status: "not-initialized",
|
|
254
|
+
mode: null,
|
|
255
|
+
extensionId: null,
|
|
256
|
+
url: null,
|
|
257
|
+
server: P,
|
|
258
|
+
error: null
|
|
259
|
+
}, ae = {
|
|
260
|
+
status: "initializing",
|
|
261
|
+
mode: null,
|
|
262
|
+
extensionId: null,
|
|
263
|
+
url: null,
|
|
264
|
+
server: P,
|
|
265
|
+
error: null
|
|
266
|
+
};
|
|
267
|
+
function ie(e) {
|
|
268
|
+
return e.status === "not-initialized";
|
|
269
|
+
}
|
|
270
|
+
function ue(e) {
|
|
271
|
+
return e.status === "initializing";
|
|
272
|
+
}
|
|
273
|
+
function ce(e) {
|
|
274
|
+
return e.status !== "not-initialized" && e.status !== "initializing";
|
|
275
|
+
}
|
|
276
|
+
function U(e) {
|
|
277
|
+
return e.status === "ready";
|
|
229
278
|
}
|
|
230
|
-
|
|
279
|
+
function de(e) {
|
|
280
|
+
return U(e) && e.server.status === "ready";
|
|
281
|
+
}
|
|
282
|
+
function le(e) {
|
|
283
|
+
return Q(e) ? {
|
|
284
|
+
status: e.extension === "not-initialized" ? "initializing" : e.extension === "not-found" ? "extension-not-found" : "ready",
|
|
285
|
+
mode: "extension",
|
|
286
|
+
extensionId: e.extensionId,
|
|
287
|
+
url: null,
|
|
288
|
+
server: e.server,
|
|
289
|
+
error: e.server.error
|
|
290
|
+
} : {
|
|
291
|
+
status: e.url === null ? "direct-not-connected" : "ready",
|
|
292
|
+
mode: "direct",
|
|
293
|
+
extensionId: null,
|
|
294
|
+
url: e.url,
|
|
295
|
+
server: e.server,
|
|
296
|
+
error: e.server.error
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
const ve = {
|
|
300
|
+
isNotInitialized: ie,
|
|
301
|
+
isInitializing: ue,
|
|
302
|
+
isInitialized: ce,
|
|
303
|
+
isReady: U,
|
|
304
|
+
isOverallReady: de
|
|
305
|
+
}, z = re(null);
|
|
231
306
|
z.displayName = "BodhiContext";
|
|
232
|
-
function
|
|
307
|
+
function me({
|
|
233
308
|
children: e,
|
|
234
|
-
client:
|
|
235
|
-
modalHtmlPath:
|
|
236
|
-
handleCallback:
|
|
237
|
-
callbackPath:
|
|
238
|
-
basePath:
|
|
239
|
-
logLevel:
|
|
309
|
+
client: o,
|
|
310
|
+
modalHtmlPath: w,
|
|
311
|
+
handleCallback: x = !0,
|
|
312
|
+
callbackPath: R = "/callback",
|
|
313
|
+
basePath: g = "/",
|
|
314
|
+
logLevel: A = "warn"
|
|
240
315
|
}) {
|
|
241
|
-
const A =
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
T(() => {
|
|
246
|
-
const n = (o) => {
|
|
247
|
-
switch (o.type) {
|
|
316
|
+
const p = _(() => new B("BodhiProvider", A), [A]), E = T(!1), u = T(!1), [a, f] = N(oe), [v, y] = N($), [O, C] = N(!1), [L, h] = N("ready");
|
|
317
|
+
b(() => {
|
|
318
|
+
const n = (i) => {
|
|
319
|
+
switch (i.type) {
|
|
248
320
|
case "client-state":
|
|
249
|
-
|
|
321
|
+
f(le(i.state));
|
|
250
322
|
break;
|
|
251
323
|
case "auth-state":
|
|
252
|
-
|
|
324
|
+
y(i.state), C(!1);
|
|
253
325
|
break;
|
|
254
326
|
}
|
|
255
327
|
};
|
|
256
|
-
return
|
|
257
|
-
|
|
328
|
+
return o.setStateCallback(n), () => {
|
|
329
|
+
o.setStateCallback(ee);
|
|
258
330
|
};
|
|
259
|
-
}, [
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
}, []),
|
|
263
|
-
|
|
264
|
-
}, []),
|
|
265
|
-
|
|
266
|
-
}, []),
|
|
331
|
+
}, [o]);
|
|
332
|
+
const S = d(async () => {
|
|
333
|
+
h("loading");
|
|
334
|
+
}, []), l = d(() => {
|
|
335
|
+
h("ready");
|
|
336
|
+
}, []), D = d(() => {
|
|
337
|
+
h("loaded");
|
|
338
|
+
}, []), t = d(
|
|
267
339
|
async (n) => {
|
|
268
|
-
|
|
340
|
+
f(ae);
|
|
269
341
|
try {
|
|
270
|
-
await
|
|
271
|
-
} catch (
|
|
272
|
-
|
|
342
|
+
await o.init(n || {});
|
|
343
|
+
} catch (i) {
|
|
344
|
+
p.error("Init failed:", i);
|
|
273
345
|
}
|
|
274
346
|
},
|
|
275
|
-
[
|
|
347
|
+
[o, p]
|
|
276
348
|
);
|
|
277
|
-
|
|
278
|
-
if (
|
|
279
|
-
|
|
280
|
-
if (await
|
|
281
|
-
const
|
|
282
|
-
if (
|
|
283
|
-
const
|
|
284
|
-
!
|
|
285
|
-
window.history.replaceState({}, "",
|
|
286
|
-
}).catch((
|
|
287
|
-
|
|
288
|
-
|
|
349
|
+
b(() => {
|
|
350
|
+
if (u.current) return;
|
|
351
|
+
u.current = !0, (async () => {
|
|
352
|
+
if (await t(), !x) return;
|
|
353
|
+
const i = new URL(window.location.href);
|
|
354
|
+
if (i.pathname !== R) return;
|
|
355
|
+
const k = i.searchParams.get("code"), M = i.searchParams.get("state");
|
|
356
|
+
!k || !M || E.current || (E.current = !0, te(o) && (C(!0), o.handleOAuthCallback(k, M).then(() => {
|
|
357
|
+
window.history.replaceState({}, "", g);
|
|
358
|
+
}).catch((I) => {
|
|
359
|
+
p.error("OAuth callback failed:", I), y({
|
|
360
|
+
status: "error",
|
|
361
|
+
user: null,
|
|
362
|
+
accessToken: null,
|
|
289
363
|
error: {
|
|
290
|
-
message:
|
|
364
|
+
message: I instanceof Error ? I.message : "OAuth callback failed",
|
|
291
365
|
code: "OAUTH_CALLBACK_FAILED"
|
|
292
366
|
}
|
|
293
|
-
}),
|
|
367
|
+
}), C(!1), window.history.replaceState({}, "", g);
|
|
294
368
|
})));
|
|
295
369
|
})();
|
|
296
|
-
}, [
|
|
297
|
-
const
|
|
298
|
-
|
|
370
|
+
}, [t, o, x, R, g]);
|
|
371
|
+
const r = d(async () => {
|
|
372
|
+
C(!0);
|
|
299
373
|
try {
|
|
300
|
-
await
|
|
374
|
+
await o.login();
|
|
301
375
|
} catch (n) {
|
|
302
|
-
|
|
303
|
-
|
|
376
|
+
y({
|
|
377
|
+
status: "error",
|
|
378
|
+
user: null,
|
|
379
|
+
accessToken: null,
|
|
304
380
|
error: {
|
|
305
381
|
message: n instanceof Error ? n.message : "Login failed",
|
|
306
382
|
code: "LOGIN_FAILED"
|
|
307
383
|
}
|
|
308
|
-
}),
|
|
384
|
+
}), C(!1);
|
|
309
385
|
}
|
|
310
|
-
}, [
|
|
386
|
+
}, [o]), s = d(async () => {
|
|
311
387
|
try {
|
|
312
|
-
await
|
|
388
|
+
await o.logout();
|
|
313
389
|
} catch (n) {
|
|
314
|
-
|
|
315
|
-
|
|
390
|
+
y({
|
|
391
|
+
status: "error",
|
|
392
|
+
user: null,
|
|
393
|
+
accessToken: null,
|
|
316
394
|
error: {
|
|
317
395
|
message: n instanceof Error ? n.message : "Logout failed",
|
|
318
396
|
code: "LOGOUT_FAILED"
|
|
319
397
|
}
|
|
320
398
|
});
|
|
321
399
|
}
|
|
322
|
-
}, [
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
400
|
+
}, [o]), c = _(() => {
|
|
401
|
+
const n = a.status === "ready", i = a.server.status === "ready";
|
|
402
|
+
return {
|
|
403
|
+
client: o,
|
|
404
|
+
clientState: a,
|
|
405
|
+
auth: v,
|
|
406
|
+
isAuthLoading: O,
|
|
407
|
+
login: r,
|
|
408
|
+
logout: s,
|
|
409
|
+
showSetup: S,
|
|
410
|
+
hideSetup: l,
|
|
411
|
+
setupState: L,
|
|
412
|
+
// Computed auth properties
|
|
413
|
+
isAuthenticated: v.status === "authenticated",
|
|
414
|
+
canLogin: n && !O,
|
|
415
|
+
// Computed connection properties
|
|
416
|
+
isReady: n,
|
|
417
|
+
isServerReady: i,
|
|
418
|
+
isOverallReady: n && i,
|
|
419
|
+
isInitializing: a.status === "initializing",
|
|
420
|
+
isExtension: a.mode === "extension",
|
|
421
|
+
isDirect: a.mode === "direct"
|
|
422
|
+
};
|
|
423
|
+
}, [o, a, v, O, L, r, s, S, l]);
|
|
424
|
+
return /* @__PURE__ */ F(z.Provider, { value: c, children: [
|
|
425
|
+
/* @__PURE__ */ H(
|
|
426
|
+
se,
|
|
339
427
|
{
|
|
340
|
-
client:
|
|
341
|
-
modalHtmlPath:
|
|
342
|
-
hideSetup:
|
|
343
|
-
onSetupReady:
|
|
428
|
+
client: o,
|
|
429
|
+
modalHtmlPath: w,
|
|
430
|
+
hideSetup: l,
|
|
431
|
+
onSetupReady: D,
|
|
344
432
|
setupState: L,
|
|
345
|
-
basePath:
|
|
346
|
-
logLevel:
|
|
433
|
+
basePath: g,
|
|
434
|
+
logLevel: A
|
|
347
435
|
}
|
|
348
436
|
),
|
|
349
437
|
e
|
|
350
438
|
] });
|
|
351
439
|
}
|
|
352
440
|
function ge() {
|
|
353
|
-
const e =
|
|
441
|
+
const e = ne(z);
|
|
354
442
|
if (!e) throw new Error("useBodhi must be used within BodhiProvider");
|
|
355
|
-
return
|
|
356
|
-
client: e.client,
|
|
357
|
-
clientState: e.clientState,
|
|
358
|
-
setupState: e.setupState,
|
|
359
|
-
auth: e.auth,
|
|
360
|
-
authLoading: e.authLoading,
|
|
361
|
-
login: e.login,
|
|
362
|
-
logout: e.logout,
|
|
363
|
-
showSetup: e.showSetup,
|
|
364
|
-
hideSetup: e.hideSetup
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
function P(e) {
|
|
368
|
-
return e.type === "not-initialized";
|
|
369
|
-
}
|
|
370
|
-
function F(e) {
|
|
371
|
-
return e.type === "initializing";
|
|
372
|
-
}
|
|
373
|
-
function k(e) {
|
|
374
|
-
return !(P(e) || F(e));
|
|
375
|
-
}
|
|
376
|
-
function oe(e) {
|
|
377
|
-
return k(e) ? B(e) : !1;
|
|
378
|
-
}
|
|
379
|
-
function ie(e) {
|
|
380
|
-
if (P(e))
|
|
381
|
-
return { ready: !1, actualState: "not-initialized", mode: null };
|
|
382
|
-
if (F(e))
|
|
383
|
-
return { ready: !1, actualState: "initializing", mode: null };
|
|
384
|
-
const a = U(e) ? "extension" : "direct", v = B(e), S = U(e) ? e.extension : e.server.status === "not-connected" ? "not-connected" : "ready";
|
|
385
|
-
return { ready: v, actualState: S, mode: a };
|
|
386
|
-
}
|
|
387
|
-
function ue(e) {
|
|
388
|
-
if (!k(e))
|
|
389
|
-
return { ready: !1, actualState: "n/a" };
|
|
390
|
-
const a = e.server;
|
|
391
|
-
return {
|
|
392
|
-
ready: a.status === "ready",
|
|
393
|
-
actualState: a.status
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
function ce(e) {
|
|
397
|
-
return k(e) ? B(e) && e.server.status === "ready" : !1;
|
|
443
|
+
return e;
|
|
398
444
|
}
|
|
399
|
-
const pe =
|
|
400
|
-
// Type guards
|
|
401
|
-
isNotInitialized: P,
|
|
402
|
-
isInitializing: F,
|
|
403
|
-
isInitialized: k,
|
|
404
|
-
isReady: oe,
|
|
405
|
-
// Derived state
|
|
406
|
-
getClientInitState: ie,
|
|
407
|
-
getServerState: ue,
|
|
408
|
-
isOverallReady: ce
|
|
409
|
-
}, Ce = "production";
|
|
445
|
+
const pe = "production";
|
|
410
446
|
export {
|
|
411
|
-
|
|
447
|
+
me as BodhiProvider,
|
|
412
448
|
z as BodhiReactContext,
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
449
|
+
ve as ClientCtxState,
|
|
450
|
+
ae as INITIALIZING_CLIENT_CONTEXT_STATE,
|
|
451
|
+
oe as INITIAL_CLIENT_CONTEXT_STATE,
|
|
452
|
+
pe as REACT_BUILD_MODE,
|
|
453
|
+
le as clientStateToContextState,
|
|
454
|
+
Ae as createApiError,
|
|
455
|
+
Oe as createOperationError,
|
|
419
456
|
Le as isApiResultError,
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
457
|
+
he as isApiResultOperationError,
|
|
458
|
+
we as isApiResultSuccess,
|
|
459
|
+
xe as isAuthError,
|
|
460
|
+
Ie as isAuthLoading,
|
|
461
|
+
_e as isAuthenticated,
|
|
462
|
+
ce as isClientCtxInitialized,
|
|
463
|
+
ue as isClientCtxInitializing,
|
|
464
|
+
ie as isClientCtxNotInitialized,
|
|
465
|
+
U as isClientCtxReady,
|
|
466
|
+
Re as isClientReady,
|
|
467
|
+
De as isDirectState,
|
|
468
|
+
Me as isExtensionState,
|
|
469
|
+
Ne as isOperationError,
|
|
470
|
+
de as isOverallReady,
|
|
471
|
+
Te as isWebUIClient,
|
|
433
472
|
ge as useBodhi
|
|
434
473
|
};
|