@luxfi/ui 7.4.6 → 7.4.8
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/alert.cjs +3 -7
- package/dist/alert.js +3 -7
- package/dist/auth.cjs +481 -0
- package/dist/auth.d.cts +80 -0
- package/dist/auth.d.ts +80 -0
- package/dist/auth.js +456 -0
- package/dist/badge.cjs +4 -8
- package/dist/badge.js +4 -8
- package/dist/button.cjs +3 -7
- package/dist/button.js +3 -7
- package/dist/collapsible.cjs +3 -7
- package/dist/collapsible.js +3 -7
- package/dist/icon-button.cjs +3 -7
- package/dist/icon-button.js +3 -7
- package/dist/icons.cjs +0 -1
- package/dist/icons.js +0 -1
- package/dist/image.cjs +3 -7
- package/dist/image.js +3 -7
- package/dist/index.cjs +9 -8
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -9
- package/dist/link.cjs +3 -7
- package/dist/link.js +3 -7
- package/dist/next.cjs +20 -1
- package/dist/next.js +20 -1
- package/dist/select.cjs +3 -7
- package/dist/select.js +3 -7
- package/dist/skeleton.cjs +8 -7
- package/dist/skeleton.d.cts +17 -1
- package/dist/skeleton.d.ts +17 -1
- package/dist/skeleton.js +8 -8
- package/dist/table.cjs +3 -7
- package/dist/table.js +3 -7
- package/dist/tag.cjs +4 -8
- package/dist/tag.js +4 -8
- package/dist/tooltip.cjs +1 -1
- package/dist/tooltip.js +1 -1
- package/dist/vite.cjs +4 -3
- package/dist/vite.js +4 -3
- package/package.json +12 -2
- package/src/auth.tsx +198 -0
- package/src/engine.ts +40 -3
- package/src/index.ts +1 -1
- package/src/next.ts +23 -0
- package/src/skeleton.tsx +36 -7
- package/src/tooltip.tsx +13 -5
- package/src/vite.ts +4 -9
- package/tokens.css +217 -0
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { WhiteLabel } from './white-label.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The ONE callback route. Registered as `https://<host>/auth/callback` for
|
|
6
|
+
* every browser client in the fleet — never under `/api/`, never per app.
|
|
7
|
+
*/
|
|
8
|
+
declare const CALLBACK_PATH = "/auth/callback";
|
|
9
|
+
/** What `handleCallback` hands back. Structural, so the SDK's types stay its own. */
|
|
10
|
+
interface AuthResult {
|
|
11
|
+
readonly token: {
|
|
12
|
+
readonly accessToken: string;
|
|
13
|
+
};
|
|
14
|
+
readonly redirect: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Point `@hanzo/iam` at the issuer and client this HOST resolves to.
|
|
18
|
+
*
|
|
19
|
+
* Idempotent per config, browser-only, and safe to call from anywhere — which
|
|
20
|
+
* is the point: no ordering rule between a provider's effect and a child's.
|
|
21
|
+
*/
|
|
22
|
+
declare function configureAuth(wl: WhiteLabel): void;
|
|
23
|
+
interface Auth {
|
|
24
|
+
/** Start the PKCE login. `redirect` is where to land afterwards. */
|
|
25
|
+
readonly signIn: (redirect?: string) => void;
|
|
26
|
+
/** RP-initiated logout + local token clear. */
|
|
27
|
+
readonly signOut: () => void;
|
|
28
|
+
/** Finish the login on the callback route. */
|
|
29
|
+
readonly complete: () => Promise<AuthResult>;
|
|
30
|
+
/** The host-resolved brand, issuer and client these verbs are bound to. */
|
|
31
|
+
readonly whiteLabel: WhiteLabel;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The three auth verbs, bound to the current host.
|
|
35
|
+
*
|
|
36
|
+
* Configuration happens during render, before any caller can use a verb, so a
|
|
37
|
+
* callback route works whether or not it sits under an `<AuthProvider>`.
|
|
38
|
+
*/
|
|
39
|
+
declare function useAuth(defaultRedirect?: string): Auth;
|
|
40
|
+
interface AuthProviderProps {
|
|
41
|
+
readonly children: React.ReactNode;
|
|
42
|
+
/** Where a successful sign-in lands. Default `/`. */
|
|
43
|
+
readonly redirect?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Anything the surface must tear down alongside the IAM session — the mirror
|
|
46
|
+
* of {@link AuthCallbackProps.onSignedIn}. A surface that mints its own
|
|
47
|
+
* downstream credential from the IAM token drops it here; the IAM session
|
|
48
|
+
* itself is never the app's to manage.
|
|
49
|
+
*/
|
|
50
|
+
readonly onSignOut?: () => void;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* `IdentityProvider` with the credential half filled in.
|
|
54
|
+
*
|
|
55
|
+
* A surface's root becomes `<AppProvider><AuthProvider>…` and nothing else —
|
|
56
|
+
* no `configureIam`, no `startLogin`, no per-app token keys.
|
|
57
|
+
*/
|
|
58
|
+
declare const AuthProvider: ({ children, redirect, onSignOut }: AuthProviderProps) => React.ReactElement;
|
|
59
|
+
interface AuthCallbackProps {
|
|
60
|
+
/**
|
|
61
|
+
* Anything the surface must do with the fresh session before it navigates —
|
|
62
|
+
* e.g. the MPC dashboard mints its own API JWT from the IAM token. Throwing
|
|
63
|
+
* here does NOT fail the sign-in: the user is signed in, and a downstream
|
|
64
|
+
* service being unreachable is that service's problem to report.
|
|
65
|
+
*/
|
|
66
|
+
readonly onSignedIn?: (result: AuthResult) => void | Promise<void>;
|
|
67
|
+
/** Router hop. Defaults to a full replace, which needs no router. */
|
|
68
|
+
readonly navigate?: (to: string) => void;
|
|
69
|
+
/** Where to go when the callback carried no stashed redirect. */
|
|
70
|
+
readonly fallback?: string;
|
|
71
|
+
/** Sign-in entry point offered after a failure. */
|
|
72
|
+
readonly retryPath?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The ONE callback page body: verify state, exchange the code, go where the
|
|
76
|
+
* user was headed. Mount it at {@link CALLBACK_PATH}.
|
|
77
|
+
*/
|
|
78
|
+
declare const AuthCallback: ({ onSignedIn, navigate, fallback, retryPath, }: AuthCallbackProps) => React.ReactElement;
|
|
79
|
+
|
|
80
|
+
export { type Auth, AuthCallback, type AuthCallbackProps, AuthProvider, type AuthProviderProps, type AuthResult, CALLBACK_PATH, configureAuth, useAuth };
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { configureIam, handleCallback, logout, startLogin } from '@hanzo/iam/browser';
|
|
3
|
+
import * as React2 from 'react';
|
|
4
|
+
import React2__default from 'react';
|
|
5
|
+
import '@hanzo/gui';
|
|
6
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
7
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
8
|
+
|
|
9
|
+
// src/white-label.ts
|
|
10
|
+
var LUX_BRAND = {
|
|
11
|
+
lux: "#7000FF",
|
|
12
|
+
zoo: "#6C5EFB",
|
|
13
|
+
hanzo: "#EA580C",
|
|
14
|
+
pars: "#1C3879"};
|
|
15
|
+
var PARS_GOLD = "#C8A45C";
|
|
16
|
+
var ORGS = {
|
|
17
|
+
lux: {
|
|
18
|
+
org: "lux",
|
|
19
|
+
name: "Lux",
|
|
20
|
+
domain: "lux.network",
|
|
21
|
+
iamDomain: "lux.id",
|
|
22
|
+
accent: LUX_BRAND.lux,
|
|
23
|
+
accentForeground: "#FFFFFF"
|
|
24
|
+
},
|
|
25
|
+
zoo: {
|
|
26
|
+
org: "zoo",
|
|
27
|
+
name: "Zoo",
|
|
28
|
+
domain: "zoo.ngo",
|
|
29
|
+
// Zoo's issuer is `zoolabs.id` — the one row where it is not `<org>.id`,
|
|
30
|
+
// and the one every hand-rolled branding map gets wrong. `id.zoo.network`
|
|
31
|
+
// ANSWERS, which is why it keeps being copied around, but it is an alias:
|
|
32
|
+
// its own discovery document advertises
|
|
33
|
+
// issuer https://zoolabs.id
|
|
34
|
+
// authorization_endpoint https://zoolabs.id/v1/iam/oauth/authorize
|
|
35
|
+
// jwks_uri https://zoolabs.id/v1/iam/.well-known/jwks
|
|
36
|
+
// so a client configured on the alias validates `iss` against a string the
|
|
37
|
+
// IdP never emits and rejects every token it is given — the exact shape of
|
|
38
|
+
// the lux.id outage. `zoo.id` is not an IdP at all (no discovery document).
|
|
39
|
+
iamDomain: "zoolabs.id",
|
|
40
|
+
accent: LUX_BRAND.zoo,
|
|
41
|
+
accentForeground: "#FFFFFF"
|
|
42
|
+
},
|
|
43
|
+
bootnode: {
|
|
44
|
+
org: "bootnode",
|
|
45
|
+
name: "Bootnode",
|
|
46
|
+
domain: "bootno.de",
|
|
47
|
+
iamDomain: "id.bootno.de",
|
|
48
|
+
accent: LUX_BRAND.lux,
|
|
49
|
+
accentForeground: "#FFFFFF"
|
|
50
|
+
},
|
|
51
|
+
hanzo: {
|
|
52
|
+
org: "hanzo",
|
|
53
|
+
name: "Hanzo",
|
|
54
|
+
domain: "hanzo.ai",
|
|
55
|
+
iamDomain: "hanzo.id",
|
|
56
|
+
accent: LUX_BRAND.hanzo,
|
|
57
|
+
accentForeground: "#FFFFFF"
|
|
58
|
+
},
|
|
59
|
+
pars: {
|
|
60
|
+
org: "pars",
|
|
61
|
+
name: "Pars",
|
|
62
|
+
domain: "pars.id",
|
|
63
|
+
iamDomain: "pars.id",
|
|
64
|
+
accent: LUX_BRAND.pars,
|
|
65
|
+
accentForeground: PARS_GOLD
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var DOMAIN_ORG = [
|
|
69
|
+
["lux.network", "lux"],
|
|
70
|
+
["lux.cloud", "lux"],
|
|
71
|
+
["lux.id", "lux"],
|
|
72
|
+
["lux.finance", "lux"],
|
|
73
|
+
["lux.market", "lux"],
|
|
74
|
+
["lux.exchange", "lux"],
|
|
75
|
+
["zoo.ngo", "zoo"],
|
|
76
|
+
["zoo.network", "zoo"],
|
|
77
|
+
["zoo.cloud", "zoo"],
|
|
78
|
+
["zoolabs.id", "zoo"],
|
|
79
|
+
["hanzo.ai", "hanzo"],
|
|
80
|
+
["hanzo.cloud", "hanzo"],
|
|
81
|
+
["hanzo.id", "hanzo"],
|
|
82
|
+
["pars.id", "pars", "app"],
|
|
83
|
+
["pars.network", "pars", "app"],
|
|
84
|
+
["parsdao.org", "pars", "app"],
|
|
85
|
+
["bootno.de", "bootnode", "platform"]
|
|
86
|
+
];
|
|
87
|
+
var DEFAULT_ORG = "lux";
|
|
88
|
+
function normalizeHost(host) {
|
|
89
|
+
const noPort = host.trim().toLowerCase().split(":")[0] ?? "";
|
|
90
|
+
return noPort.replace(/\.$/, "");
|
|
91
|
+
}
|
|
92
|
+
function isUnder(host, domain) {
|
|
93
|
+
return host === domain || host.endsWith(`.${domain}`);
|
|
94
|
+
}
|
|
95
|
+
function matchDomain(host) {
|
|
96
|
+
let best;
|
|
97
|
+
for (const entry of DOMAIN_ORG) {
|
|
98
|
+
if (isUnder(host, entry[0]) && (!best || entry[0].length > best[0].length)) {
|
|
99
|
+
best = entry;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return best;
|
|
103
|
+
}
|
|
104
|
+
function appSlug(host, domain, pinned) {
|
|
105
|
+
if (pinned) return pinned;
|
|
106
|
+
const sub = host === domain ? "" : host.slice(0, -(domain.length + 1));
|
|
107
|
+
const leftmost = sub.split(".")[0] ?? "";
|
|
108
|
+
if (leftmost && leftmost !== "www") return leftmost;
|
|
109
|
+
const label = domain.split(".")[0] ?? "";
|
|
110
|
+
const tld = domain.split(".").slice(1).join(".");
|
|
111
|
+
return tld.split(".")[0] || label;
|
|
112
|
+
}
|
|
113
|
+
function isLocal(host) {
|
|
114
|
+
return host === "localhost" || host.endsWith(".localhost") || host === "127.0.0.1" || host === "0.0.0.0" || host === "[::1]" || host.endsWith(".local");
|
|
115
|
+
}
|
|
116
|
+
function resolveWhiteLabel(host) {
|
|
117
|
+
const h = normalizeHost(host ?? "");
|
|
118
|
+
const match = h ? matchDomain(h) : void 0;
|
|
119
|
+
const org = match ? match[1] : DEFAULT_ORG;
|
|
120
|
+
const identity = ORGS[org];
|
|
121
|
+
const app = match ? appSlug(h, match[0], match[2]) : h && isLocal(h) ? "local" : "app";
|
|
122
|
+
return {
|
|
123
|
+
...identity,
|
|
124
|
+
host: h,
|
|
125
|
+
app,
|
|
126
|
+
theme: `dark_${org}`,
|
|
127
|
+
issuer: `https://${identity.iamDomain}`,
|
|
128
|
+
clientId: `${org}-${app}`
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/iam.ts
|
|
133
|
+
var IamError = class extends Error {
|
|
134
|
+
constructor(message, status, unauthenticated) {
|
|
135
|
+
super(message);
|
|
136
|
+
this.name = "IamError";
|
|
137
|
+
this.status = status;
|
|
138
|
+
this.unauthenticated = unauthenticated;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
var SIGNED_OUT = /please sign in|authentication required|unauthorized/i;
|
|
142
|
+
function isSignedOut(status, msg) {
|
|
143
|
+
return status === 401 || SIGNED_OUT.test(msg);
|
|
144
|
+
}
|
|
145
|
+
function iamBase(host) {
|
|
146
|
+
const wl = typeof host === "object" && host !== null ? host : resolveWhiteLabel(host);
|
|
147
|
+
return `${wl.issuer}/v1/iam`;
|
|
148
|
+
}
|
|
149
|
+
async function read(call, verb, params) {
|
|
150
|
+
const url = new URL(`${call.base}/${verb}`);
|
|
151
|
+
for (const [k, v] of Object.entries(params)) url.searchParams.set(k, String(v));
|
|
152
|
+
let res;
|
|
153
|
+
try {
|
|
154
|
+
res = await fetch(url.toString(), {
|
|
155
|
+
method: "GET",
|
|
156
|
+
// The bearer is the whole credential. IAM does not allow credentialed
|
|
157
|
+
// CORS, so sending cookies would only get the response blocked.
|
|
158
|
+
headers: call.token ? { Authorization: `Bearer ${call.token}` } : {},
|
|
159
|
+
signal: call.signal
|
|
160
|
+
});
|
|
161
|
+
} catch (e) {
|
|
162
|
+
throw new IamError(e instanceof Error ? e.message : "IAM unreachable", 0, false);
|
|
163
|
+
}
|
|
164
|
+
const body = await res.json().catch(() => ({}));
|
|
165
|
+
const msg = typeof body.msg === "string" ? body.msg : "";
|
|
166
|
+
if (!res.ok || body.status === "error") {
|
|
167
|
+
throw new IamError(msg || `IAM ${verb} failed (${res.status})`, res.status, isSignedOut(res.status, msg));
|
|
168
|
+
}
|
|
169
|
+
return body.data;
|
|
170
|
+
}
|
|
171
|
+
var IAM_PAGE_SIZE = 20;
|
|
172
|
+
var iam = {
|
|
173
|
+
/** The signed-in principal, or null when there is no session. */
|
|
174
|
+
async account(call) {
|
|
175
|
+
try {
|
|
176
|
+
const data = await read(call, "get-account", {});
|
|
177
|
+
return data && data.name ? data : null;
|
|
178
|
+
} catch (e) {
|
|
179
|
+
if (e instanceof IamError && e.unauthenticated) return null;
|
|
180
|
+
throw e;
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
/**
|
|
184
|
+
* One page of the orgs the principal can see. IAM scopes the read to the
|
|
185
|
+
* caller's authority, so a normal member gets their own org and a super
|
|
186
|
+
* admin gets the tenant list — the page never has to decide.
|
|
187
|
+
*/
|
|
188
|
+
async organizations(call, page = 0, query = "", pageSize = IAM_PAGE_SIZE) {
|
|
189
|
+
const params = {
|
|
190
|
+
owner: "admin",
|
|
191
|
+
// IAM orgs live under the reserved `admin` owner
|
|
192
|
+
p: page + 1,
|
|
193
|
+
// the backend page is 1-based
|
|
194
|
+
pageSize,
|
|
195
|
+
sortField: "name",
|
|
196
|
+
sortOrder: "ascending"
|
|
197
|
+
};
|
|
198
|
+
const q = query.trim();
|
|
199
|
+
if (q) {
|
|
200
|
+
params.field = "name";
|
|
201
|
+
params.value = q;
|
|
202
|
+
}
|
|
203
|
+
return await read(call, "get-organizations", params) ?? [];
|
|
204
|
+
},
|
|
205
|
+
/** One organization by name. */
|
|
206
|
+
async organization(call, name) {
|
|
207
|
+
return await read(call, "get-organization", { id: `admin/${name}` }) ?? null;
|
|
208
|
+
},
|
|
209
|
+
/** Members of an organization. */
|
|
210
|
+
async users(call, org) {
|
|
211
|
+
return await read(call, "get-users", { owner: org }) ?? [];
|
|
212
|
+
},
|
|
213
|
+
/** The organization's projects — IAM keys this read by `organization`. */
|
|
214
|
+
async projects(call, org) {
|
|
215
|
+
return await read(call, "get-organization-projects", { organization: org }) ?? [];
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
new QueryClient({
|
|
219
|
+
defaultOptions: { queries: { refetchOnWindowFocus: false, retry: 1, staleTime: 3e4 } }
|
|
220
|
+
});
|
|
221
|
+
var WhiteLabelContext = React2__default.createContext(resolveWhiteLabel(""));
|
|
222
|
+
var useWhiteLabel = () => React2__default.useContext(WhiteLabelContext);
|
|
223
|
+
var IAM_TOKEN_KEY = "hanzo_iam_access_token";
|
|
224
|
+
function storedToken() {
|
|
225
|
+
if (typeof window === "undefined") return null;
|
|
226
|
+
for (const store of [window.sessionStorage, window.localStorage]) {
|
|
227
|
+
try {
|
|
228
|
+
const t = store.getItem(IAM_TOKEN_KEY);
|
|
229
|
+
if (t) return t;
|
|
230
|
+
} catch {
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
function clearStoredTokens() {
|
|
236
|
+
if (typeof window === "undefined") return;
|
|
237
|
+
for (const store of [window.sessionStorage, window.localStorage]) {
|
|
238
|
+
try {
|
|
239
|
+
for (const k of ["access_token", "refresh_token", "id_token", "expires_at"]) {
|
|
240
|
+
store.removeItem(`hanzo_iam_${k}`);
|
|
241
|
+
}
|
|
242
|
+
} catch {
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
var defaultAuth = {};
|
|
247
|
+
var scopeKey = (host, kind) => `lux-ui:${kind}:${host}`;
|
|
248
|
+
function readScope(host, kind) {
|
|
249
|
+
if (typeof window === "undefined") return null;
|
|
250
|
+
try {
|
|
251
|
+
return window.localStorage.getItem(scopeKey(host, kind));
|
|
252
|
+
} catch {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function writeScope(host, kind, value) {
|
|
257
|
+
if (typeof window === "undefined") return;
|
|
258
|
+
try {
|
|
259
|
+
window.localStorage.setItem(scopeKey(host, kind), value);
|
|
260
|
+
} catch {
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
var IdentityContext = React2.createContext(null);
|
|
264
|
+
var IdentityProvider = ({
|
|
265
|
+
children,
|
|
266
|
+
auth = defaultAuth,
|
|
267
|
+
loginPath = "/login"
|
|
268
|
+
}) => {
|
|
269
|
+
const whiteLabel = useWhiteLabel();
|
|
270
|
+
const base = React2.useMemo(() => iamBase(whiteLabel), [whiteLabel]);
|
|
271
|
+
const [status, setStatus] = React2.useState("loading");
|
|
272
|
+
const [account, setAccount] = React2.useState(null);
|
|
273
|
+
const [orgs, setOrgs] = React2.useState([]);
|
|
274
|
+
const [projects, setProjects] = React2.useState([]);
|
|
275
|
+
const [error, setError] = React2.useState(null);
|
|
276
|
+
const [orgName, setOrgName] = React2.useState(null);
|
|
277
|
+
const [projectName, setProjectName] = React2.useState(null);
|
|
278
|
+
const [epoch, setEpoch] = React2.useState(0);
|
|
279
|
+
React2.useEffect(() => {
|
|
280
|
+
const ac = new AbortController();
|
|
281
|
+
let live = true;
|
|
282
|
+
void (async () => {
|
|
283
|
+
const token = await (auth.token ?? storedToken)();
|
|
284
|
+
if (!live) return;
|
|
285
|
+
if (!token) {
|
|
286
|
+
setStatus("anonymous");
|
|
287
|
+
setAccount(null);
|
|
288
|
+
setOrgs([]);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
const call = { base, token, signal: ac.signal };
|
|
292
|
+
try {
|
|
293
|
+
const me = await iam.account(call);
|
|
294
|
+
if (!live) return;
|
|
295
|
+
if (!me) {
|
|
296
|
+
setStatus("anonymous");
|
|
297
|
+
setAccount(null);
|
|
298
|
+
setOrgs([]);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
setAccount(me);
|
|
302
|
+
const rows = await iam.organizations(call).catch((e) => {
|
|
303
|
+
if (e instanceof IamError && !e.unauthenticated) return [{ owner: "admin", name: me.owner }];
|
|
304
|
+
throw e;
|
|
305
|
+
});
|
|
306
|
+
if (!live) return;
|
|
307
|
+
setOrgs(rows);
|
|
308
|
+
setStatus("ready");
|
|
309
|
+
setError(null);
|
|
310
|
+
} catch (e) {
|
|
311
|
+
if (!live || ac.signal.aborted) return;
|
|
312
|
+
if (e instanceof IamError && e.unauthenticated) {
|
|
313
|
+
setStatus("anonymous");
|
|
314
|
+
setAccount(null);
|
|
315
|
+
setOrgs([]);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
setStatus("error");
|
|
319
|
+
setError(e instanceof Error ? e.message : "Could not reach IAM.");
|
|
320
|
+
}
|
|
321
|
+
})();
|
|
322
|
+
return () => {
|
|
323
|
+
live = false;
|
|
324
|
+
ac.abort();
|
|
325
|
+
};
|
|
326
|
+
}, [base, auth, epoch]);
|
|
327
|
+
const org = React2.useMemo(() => {
|
|
328
|
+
if (orgs.length === 0) return null;
|
|
329
|
+
const saved = orgName ?? readScope(whiteLabel.host, "org");
|
|
330
|
+
return orgs.find((o) => o.name === saved) ?? orgs.find((o) => o.name === account?.owner) ?? orgs[0];
|
|
331
|
+
}, [orgs, orgName, account, whiteLabel.host]);
|
|
332
|
+
React2.useEffect(() => {
|
|
333
|
+
if (!org) {
|
|
334
|
+
setProjects([]);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
const ac = new AbortController();
|
|
338
|
+
let live = true;
|
|
339
|
+
void (async () => {
|
|
340
|
+
const token = await (auth.token ?? storedToken)();
|
|
341
|
+
if (!live || !token) return;
|
|
342
|
+
const rows = await iam.projects({ base, token, signal: ac.signal }, org.name).catch(() => []);
|
|
343
|
+
if (live) setProjects(rows);
|
|
344
|
+
})();
|
|
345
|
+
return () => {
|
|
346
|
+
live = false;
|
|
347
|
+
ac.abort();
|
|
348
|
+
};
|
|
349
|
+
}, [base, auth, org, epoch]);
|
|
350
|
+
const project = React2.useMemo(() => {
|
|
351
|
+
if (projects.length === 0) return null;
|
|
352
|
+
const saved = projectName ?? readScope(whiteLabel.host, "project");
|
|
353
|
+
return projects.find((p) => p.name === saved) ?? projects.find((p) => p.isDefault) ?? projects[0];
|
|
354
|
+
}, [projects, projectName, whiteLabel.host]);
|
|
355
|
+
const value = React2.useMemo(() => ({
|
|
356
|
+
status,
|
|
357
|
+
account,
|
|
358
|
+
orgs,
|
|
359
|
+
org,
|
|
360
|
+
projects,
|
|
361
|
+
project,
|
|
362
|
+
error,
|
|
363
|
+
whiteLabel,
|
|
364
|
+
setOrg: (name) => {
|
|
365
|
+
writeScope(whiteLabel.host, "org", name);
|
|
366
|
+
setOrgName(name);
|
|
367
|
+
setProjectName(null);
|
|
368
|
+
},
|
|
369
|
+
setProject: (name) => {
|
|
370
|
+
writeScope(whiteLabel.host, "project", name);
|
|
371
|
+
setProjectName(name);
|
|
372
|
+
},
|
|
373
|
+
signIn: () => {
|
|
374
|
+
if (auth.signIn) return auth.signIn();
|
|
375
|
+
if (typeof window !== "undefined") window.location.assign(loginPath);
|
|
376
|
+
},
|
|
377
|
+
signOut: () => {
|
|
378
|
+
if (auth.signOut) return auth.signOut();
|
|
379
|
+
clearStoredTokens();
|
|
380
|
+
if (typeof window !== "undefined") window.location.assign(loginPath);
|
|
381
|
+
},
|
|
382
|
+
reload: () => setEpoch((n) => n + 1)
|
|
383
|
+
}), [status, account, orgs, org, projects, project, error, whiteLabel, auth, loginPath]);
|
|
384
|
+
return /* @__PURE__ */ jsx(IdentityContext.Provider, { value, children });
|
|
385
|
+
};
|
|
386
|
+
var CALLBACK_PATH = "/auth/callback";
|
|
387
|
+
function configureAuth(wl) {
|
|
388
|
+
if (typeof window === "undefined") return;
|
|
389
|
+
configureIam({
|
|
390
|
+
issuer: wl.issuer,
|
|
391
|
+
clientId: wl.clientId,
|
|
392
|
+
// The SDK already defaults to `${origin}${CALLBACK_PATH}`; naming it here
|
|
393
|
+
// makes the fleet-wide invariant one readable, testable line instead of a
|
|
394
|
+
// default nobody can see.
|
|
395
|
+
redirect: `${window.location.origin}${CALLBACK_PATH}`
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
function useAuth(defaultRedirect = "/") {
|
|
399
|
+
const whiteLabel = useWhiteLabel();
|
|
400
|
+
configureAuth(whiteLabel);
|
|
401
|
+
return React2.useMemo(() => ({
|
|
402
|
+
signIn: (redirect = defaultRedirect) => void startLogin({ redirect }),
|
|
403
|
+
signOut: () => void logout(),
|
|
404
|
+
complete: () => handleCallback(),
|
|
405
|
+
whiteLabel
|
|
406
|
+
}), [whiteLabel, defaultRedirect]);
|
|
407
|
+
}
|
|
408
|
+
var AuthProvider = ({ children, redirect = "/", onSignOut }) => {
|
|
409
|
+
const auth = useAuth(redirect);
|
|
410
|
+
const identityAuth = React2.useMemo(() => ({
|
|
411
|
+
signIn: () => auth.signIn(redirect),
|
|
412
|
+
signOut: () => {
|
|
413
|
+
onSignOut?.();
|
|
414
|
+
auth.signOut();
|
|
415
|
+
}
|
|
416
|
+
}), [auth, redirect, onSignOut]);
|
|
417
|
+
return /* @__PURE__ */ jsx(IdentityProvider, { auth: identityAuth, children });
|
|
418
|
+
};
|
|
419
|
+
var AuthCallback = ({
|
|
420
|
+
onSignedIn,
|
|
421
|
+
navigate,
|
|
422
|
+
fallback = "/",
|
|
423
|
+
retryPath = "/login"
|
|
424
|
+
}) => {
|
|
425
|
+
const auth = useAuth();
|
|
426
|
+
const [error, setError] = React2.useState(null);
|
|
427
|
+
React2.useEffect(() => {
|
|
428
|
+
let live = true;
|
|
429
|
+
void (async () => {
|
|
430
|
+
try {
|
|
431
|
+
const result = await auth.complete();
|
|
432
|
+
if (!live) return;
|
|
433
|
+
try {
|
|
434
|
+
await onSignedIn?.(result);
|
|
435
|
+
} catch {
|
|
436
|
+
}
|
|
437
|
+
if (!live) return;
|
|
438
|
+
const to = result.redirect || fallback;
|
|
439
|
+
if (navigate) navigate(to);
|
|
440
|
+
else window.location.replace(to);
|
|
441
|
+
} catch (e) {
|
|
442
|
+
if (live) setError(e instanceof Error ? e.message : "Authentication failed");
|
|
443
|
+
}
|
|
444
|
+
})();
|
|
445
|
+
return () => {
|
|
446
|
+
live = false;
|
|
447
|
+
};
|
|
448
|
+
}, []);
|
|
449
|
+
return /* @__PURE__ */ jsx("div", { className: "flex min-h-[50vh] items-center justify-center px-4", children: /* @__PURE__ */ jsx("div", { className: "w-full max-w-sm text-center", children: error ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
450
|
+
/* @__PURE__ */ jsx("p", { className: "mb-2 text-lg font-semibold text-[var(--color-text-error)]", children: "Sign-in failed" }),
|
|
451
|
+
/* @__PURE__ */ jsx("p", { className: "mb-6 text-sm text-[var(--color-text-secondary)]", children: error }),
|
|
452
|
+
/* @__PURE__ */ jsx("a", { href: retryPath, className: "text-sm underline underline-offset-4", children: "Try again" })
|
|
453
|
+
] }) : /* @__PURE__ */ jsx("p", { className: "text-sm text-[var(--color-text-secondary)]", children: "Completing sign in\u2026" }) }) });
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
export { AuthCallback, AuthProvider, CALLBACK_PATH, configureAuth, useAuth };
|
package/dist/badge.cjs
CHANGED
|
@@ -146,11 +146,7 @@ function stripShims(props) {
|
|
|
146
146
|
for (const k of SHIM_PROPS) delete out[k];
|
|
147
147
|
return out;
|
|
148
148
|
}
|
|
149
|
-
var SKELETON_CLASSES =
|
|
150
|
-
"animate-skeleton-shimmer rounded-sm",
|
|
151
|
-
"bg-[linear-gradient(90deg,var(--color-skeleton-start)_0%,var(--color-skeleton-end)_50%,var(--color-skeleton-start)_100%)]",
|
|
152
|
-
"bg-[length:200%_100%]"
|
|
153
|
-
].join(" ");
|
|
149
|
+
var SKELETON_CLASSES = "lux-skeleton rounded-sm";
|
|
154
150
|
var HIDE_BELOW_MAP = { lg: "lg:hidden", md: "md:hidden", sm: "sm:hidden" };
|
|
155
151
|
var Skeleton = React3__namespace.forwardRef(
|
|
156
152
|
function Skeleton2(props, ref) {
|
|
@@ -170,7 +166,7 @@ var Skeleton = React3__namespace.forwardRef(
|
|
|
170
166
|
{
|
|
171
167
|
ref,
|
|
172
168
|
"data-loading": true,
|
|
173
|
-
className: cn(SKELETON_CLASSES, "
|
|
169
|
+
className: cn(SKELETON_CLASSES, "[&_*]:invisible", cls),
|
|
174
170
|
style: mergedStyle,
|
|
175
171
|
...htmlRest,
|
|
176
172
|
children
|
|
@@ -182,7 +178,7 @@ var Skeleton = React3__namespace.forwardRef(
|
|
|
182
178
|
{
|
|
183
179
|
ref,
|
|
184
180
|
"data-loading": true,
|
|
185
|
-
className: cn(SKELETON_CLASSES, children ? "
|
|
181
|
+
className: cn(SKELETON_CLASSES, children ? "[&_*]:invisible" : "min-h-5", cls),
|
|
186
182
|
style: mergedStyle,
|
|
187
183
|
...htmlRest,
|
|
188
184
|
children
|
|
@@ -313,7 +309,7 @@ var Tooltip = React3__namespace.forwardRef(
|
|
|
313
309
|
{
|
|
314
310
|
ref: triggerRef,
|
|
315
311
|
asChild: true,
|
|
316
|
-
...isMobile ? {
|
|
312
|
+
...isMobile ? { onClick: handleTriggerClick } : {},
|
|
317
313
|
...triggerProps,
|
|
318
314
|
children
|
|
319
315
|
}
|
package/dist/badge.js
CHANGED
|
@@ -125,11 +125,7 @@ function stripShims(props) {
|
|
|
125
125
|
for (const k of SHIM_PROPS) delete out[k];
|
|
126
126
|
return out;
|
|
127
127
|
}
|
|
128
|
-
var SKELETON_CLASSES =
|
|
129
|
-
"animate-skeleton-shimmer rounded-sm",
|
|
130
|
-
"bg-[linear-gradient(90deg,var(--color-skeleton-start)_0%,var(--color-skeleton-end)_50%,var(--color-skeleton-start)_100%)]",
|
|
131
|
-
"bg-[length:200%_100%]"
|
|
132
|
-
].join(" ");
|
|
128
|
+
var SKELETON_CLASSES = "lux-skeleton rounded-sm";
|
|
133
129
|
var HIDE_BELOW_MAP = { lg: "lg:hidden", md: "md:hidden", sm: "sm:hidden" };
|
|
134
130
|
var Skeleton = React3.forwardRef(
|
|
135
131
|
function Skeleton2(props, ref) {
|
|
@@ -149,7 +145,7 @@ var Skeleton = React3.forwardRef(
|
|
|
149
145
|
{
|
|
150
146
|
ref,
|
|
151
147
|
"data-loading": true,
|
|
152
|
-
className: cn(SKELETON_CLASSES, "
|
|
148
|
+
className: cn(SKELETON_CLASSES, "[&_*]:invisible", cls),
|
|
153
149
|
style: mergedStyle,
|
|
154
150
|
...htmlRest,
|
|
155
151
|
children
|
|
@@ -161,7 +157,7 @@ var Skeleton = React3.forwardRef(
|
|
|
161
157
|
{
|
|
162
158
|
ref,
|
|
163
159
|
"data-loading": true,
|
|
164
|
-
className: cn(SKELETON_CLASSES, children ? "
|
|
160
|
+
className: cn(SKELETON_CLASSES, children ? "[&_*]:invisible" : "min-h-5", cls),
|
|
165
161
|
style: mergedStyle,
|
|
166
162
|
...htmlRest,
|
|
167
163
|
children
|
|
@@ -292,7 +288,7 @@ var Tooltip = React3.forwardRef(
|
|
|
292
288
|
{
|
|
293
289
|
ref: triggerRef,
|
|
294
290
|
asChild: true,
|
|
295
|
-
...isMobile ? {
|
|
291
|
+
...isMobile ? { onClick: handleTriggerClick } : {},
|
|
296
292
|
...triggerProps,
|
|
297
293
|
children
|
|
298
294
|
}
|
package/dist/button.cjs
CHANGED
|
@@ -145,11 +145,7 @@ function stripShims(props) {
|
|
|
145
145
|
for (const k of SHIM_PROPS) delete out[k];
|
|
146
146
|
return out;
|
|
147
147
|
}
|
|
148
|
-
var SKELETON_CLASSES =
|
|
149
|
-
"animate-skeleton-shimmer rounded-sm",
|
|
150
|
-
"bg-[linear-gradient(90deg,var(--color-skeleton-start)_0%,var(--color-skeleton-end)_50%,var(--color-skeleton-start)_100%)]",
|
|
151
|
-
"bg-[length:200%_100%]"
|
|
152
|
-
].join(" ");
|
|
148
|
+
var SKELETON_CLASSES = "lux-skeleton rounded-sm";
|
|
153
149
|
var HIDE_BELOW_MAP = { lg: "lg:hidden", md: "md:hidden", sm: "sm:hidden" };
|
|
154
150
|
var Skeleton = React2__namespace.forwardRef(
|
|
155
151
|
function Skeleton2(props, ref) {
|
|
@@ -169,7 +165,7 @@ var Skeleton = React2__namespace.forwardRef(
|
|
|
169
165
|
{
|
|
170
166
|
ref,
|
|
171
167
|
"data-loading": true,
|
|
172
|
-
className: cn(SKELETON_CLASSES, "
|
|
168
|
+
className: cn(SKELETON_CLASSES, "[&_*]:invisible", cls),
|
|
173
169
|
style: mergedStyle,
|
|
174
170
|
...htmlRest,
|
|
175
171
|
children
|
|
@@ -181,7 +177,7 @@ var Skeleton = React2__namespace.forwardRef(
|
|
|
181
177
|
{
|
|
182
178
|
ref,
|
|
183
179
|
"data-loading": true,
|
|
184
|
-
className: cn(SKELETON_CLASSES, children ? "
|
|
180
|
+
className: cn(SKELETON_CLASSES, children ? "[&_*]:invisible" : "min-h-5", cls),
|
|
185
181
|
style: mergedStyle,
|
|
186
182
|
...htmlRest,
|
|
187
183
|
children
|
package/dist/button.js
CHANGED
|
@@ -123,11 +123,7 @@ function stripShims(props) {
|
|
|
123
123
|
for (const k of SHIM_PROPS) delete out[k];
|
|
124
124
|
return out;
|
|
125
125
|
}
|
|
126
|
-
var SKELETON_CLASSES =
|
|
127
|
-
"animate-skeleton-shimmer rounded-sm",
|
|
128
|
-
"bg-[linear-gradient(90deg,var(--color-skeleton-start)_0%,var(--color-skeleton-end)_50%,var(--color-skeleton-start)_100%)]",
|
|
129
|
-
"bg-[length:200%_100%]"
|
|
130
|
-
].join(" ");
|
|
126
|
+
var SKELETON_CLASSES = "lux-skeleton rounded-sm";
|
|
131
127
|
var HIDE_BELOW_MAP = { lg: "lg:hidden", md: "md:hidden", sm: "sm:hidden" };
|
|
132
128
|
var Skeleton = React2.forwardRef(
|
|
133
129
|
function Skeleton2(props, ref) {
|
|
@@ -147,7 +143,7 @@ var Skeleton = React2.forwardRef(
|
|
|
147
143
|
{
|
|
148
144
|
ref,
|
|
149
145
|
"data-loading": true,
|
|
150
|
-
className: cn(SKELETON_CLASSES, "
|
|
146
|
+
className: cn(SKELETON_CLASSES, "[&_*]:invisible", cls),
|
|
151
147
|
style: mergedStyle,
|
|
152
148
|
...htmlRest,
|
|
153
149
|
children
|
|
@@ -159,7 +155,7 @@ var Skeleton = React2.forwardRef(
|
|
|
159
155
|
{
|
|
160
156
|
ref,
|
|
161
157
|
"data-loading": true,
|
|
162
|
-
className: cn(SKELETON_CLASSES, children ? "
|
|
158
|
+
className: cn(SKELETON_CLASSES, children ? "[&_*]:invisible" : "min-h-5", cls),
|
|
163
159
|
style: mergedStyle,
|
|
164
160
|
...htmlRest,
|
|
165
161
|
children
|