bwh-auth 0.4.0 → 0.6.0

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/index.js CHANGED
@@ -944,29 +944,318 @@ function relyingApplicationsFrom(value) {
944
944
  }
945
945
 
946
946
  // src/api-credentials-section.tsx
947
+ import * as React6 from "react";
948
+
949
+ // src/scope-picker.tsx
950
+ import { ChevronRight, TriangleAlert } from "lucide-react";
947
951
  import * as React5 from "react";
952
+
953
+ // src/scope-selection.ts
954
+ function closeImplications(implications) {
955
+ const closed = {};
956
+ for (const key of Object.keys(implications)) {
957
+ const seen = /* @__PURE__ */ new Set();
958
+ const walk = (id) => {
959
+ for (const needed of implications[id] ?? []) {
960
+ if (needed !== key && !seen.has(needed)) {
961
+ seen.add(needed);
962
+ walk(needed);
963
+ }
964
+ }
965
+ };
966
+ walk(key);
967
+ if (seen.size > 0) {
968
+ closed[key] = [...seen];
969
+ }
970
+ }
971
+ return closed;
972
+ }
973
+ function restrictImplications(implications, offered) {
974
+ const result = {};
975
+ for (const [key, needed] of Object.entries(implications ?? {})) {
976
+ if (!offered.has(key) || !Array.isArray(needed)) {
977
+ continue;
978
+ }
979
+ const kept = needed.filter((id) => offered.has(id));
980
+ if (kept.length > 0) {
981
+ result[key] = kept;
982
+ }
983
+ }
984
+ return result;
985
+ }
986
+ function inCatalogOrder(ids, catalog) {
987
+ const wanted = new Set(ids);
988
+ return catalog.filter((id) => wanted.has(id));
989
+ }
990
+ function withScopes(selected, ids, closed) {
991
+ const next = new Set(selected);
992
+ for (const id of ids) {
993
+ next.add(id);
994
+ for (const needed of closed[id] ?? []) {
995
+ next.add(needed);
996
+ }
997
+ }
998
+ return next;
999
+ }
1000
+ function withoutScopes(selected, ids, closed) {
1001
+ const removed = new Set(ids);
1002
+ const next = new Set(selected);
1003
+ for (const id of ids) {
1004
+ next.delete(id);
1005
+ }
1006
+ for (const [scope, needed] of Object.entries(closed)) {
1007
+ if (needed.some((id) => removed.has(id))) {
1008
+ next.delete(scope);
1009
+ }
1010
+ }
1011
+ return next;
1012
+ }
1013
+ function neededBy(id, selected, closed) {
1014
+ return selected.filter((scope) => scope !== id && (closed[scope] ?? []).includes(id));
1015
+ }
1016
+ function sameSelection(a, b) {
1017
+ if (a.length !== b.length) {
1018
+ return false;
1019
+ }
1020
+ const set = new Set(a);
1021
+ return b.every((id) => set.has(id));
1022
+ }
1023
+
1024
+ // src/scope-picker.tsx
948
1025
  import { Fragment, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
949
- function ApiCredentialsSection({ indexUrl, components, links = [], csrfToken, onSuccess, onError }) {
1026
+ function resolveGroups(scopes, groups) {
1027
+ if (!Array.isArray(groups) || groups.length === 0) {
1028
+ return null;
1029
+ }
1030
+ const byId = new Map(scopes.map((scope) => [scope.id, scope]));
1031
+ const placed = /* @__PURE__ */ new Set();
1032
+ const resolved = [];
1033
+ for (const group of groups) {
1034
+ const members = [];
1035
+ for (const id of group.scopes ?? []) {
1036
+ const scope = byId.get(id);
1037
+ if (scope && !placed.has(id)) {
1038
+ placed.add(id);
1039
+ members.push(scope);
1040
+ }
1041
+ }
1042
+ if (members.length > 0) {
1043
+ resolved.push({ id: group.id, label: group.label, description: group.description ?? null, sensitive: group.sensitive === true, scopes: members });
1044
+ }
1045
+ }
1046
+ const rest = scopes.filter((scope) => !placed.has(scope.id));
1047
+ if (rest.length > 0) {
1048
+ resolved.push({ id: "other", label: "Other permissions", description: null, sensitive: false, scopes: rest });
1049
+ }
1050
+ return resolved.length > 0 ? resolved : null;
1051
+ }
1052
+ function DefaultBadge(props) {
1053
+ return /* @__PURE__ */ jsx4("span", { ...props });
1054
+ }
1055
+ var touchRow = {
1056
+ display: "flex",
1057
+ gap: "0.625rem",
1058
+ alignItems: "flex-start",
1059
+ minHeight: 44,
1060
+ padding: "0.5rem 0",
1061
+ boxSizing: "border-box",
1062
+ overflowWrap: "anywhere"
1063
+ };
1064
+ var mutedStyle = { opacity: 0.7 };
1065
+ var gridStyle = {
1066
+ display: "grid",
1067
+ gridTemplateColumns: "repeat(auto-fill, minmax(min(100%, 300px), 1fr))",
1068
+ gap: "1rem",
1069
+ alignItems: "start"
1070
+ };
1071
+ var boxStyle = { margin: 0, minWidth: 0, border: "1px solid rgba(128, 128, 128, 0.35)", borderRadius: 10, padding: "0.25rem 1rem 0.75rem" };
1072
+ function ScopePicker({ idPrefix, scopes, groups, presets, implications, selected, onChange, components }) {
1073
+ const { Checkbox, Button, Badge, Alert } = resolveAuthComponents(components);
1074
+ const [open, setOpen] = React5.useState({});
1075
+ const catalog = React5.useMemo(() => scopes.map((scope) => scope.id), [scopes]);
1076
+ const closed = React5.useMemo(() => closeImplications(restrictImplications(implications, new Set(catalog))), [implications, catalog]);
1077
+ const layout = React5.useMemo(() => resolveGroups(scopes, groups), [scopes, groups]);
1078
+ const offeredPresets = React5.useMemo(
1079
+ () => (presets ?? []).filter((preset) => preset.scopes.length > 0 && preset.scopes.every((id) => catalog.includes(id))),
1080
+ [presets, catalog]
1081
+ );
1082
+ const cascades = Object.keys(closed).length > 0;
1083
+ const chosen = new Set(selected);
1084
+ const commit = (next) => onChange(inCatalogOrder(next, catalog));
1085
+ const toggle = (id, checked) => {
1086
+ if (layout === null && !cascades) {
1087
+ onChange(checked ? [...selected, id] : selected.filter((value) => value !== id));
1088
+ return;
1089
+ }
1090
+ commit(checked ? withScopes(selected, [id], closed) : withoutScopes(selected, [id], closed));
1091
+ };
1092
+ const renderRow = (scope, grouped) => {
1093
+ const id = `${idPrefix}-${scope.id}`;
1094
+ const needers = neededBy(scope.id, selected, closed);
1095
+ const noteId = `${id}-needed`;
1096
+ const row = /* @__PURE__ */ jsxs4("label", { htmlFor: id, style: grouped ? { ...touchRow, cursor: "pointer" } : { overflowWrap: "anywhere" }, children: [
1097
+ Checkbox ? /* @__PURE__ */ jsx4(Checkbox, { id, checked: chosen.has(scope.id), onCheckedChange: (checked) => toggle(scope.id, checked) }) : /* @__PURE__ */ jsx4(
1098
+ "input",
1099
+ {
1100
+ id,
1101
+ type: "checkbox",
1102
+ checked: chosen.has(scope.id),
1103
+ "aria-describedby": needers.length > 0 ? noteId : void 0,
1104
+ onChange: (event) => toggle(scope.id, event.target.checked),
1105
+ style: grouped ? { flex: "none", width: 16, height: 16, margin: "2px 0 0" } : void 0
1106
+ }
1107
+ ),
1108
+ " ",
1109
+ /* @__PURE__ */ jsxs4("span", { style: { minWidth: 0, overflowWrap: "anywhere" }, children: [
1110
+ /* @__PURE__ */ jsx4("code", { children: scope.id }),
1111
+ " ",
1112
+ /* @__PURE__ */ jsx4("span", { style: mutedStyle, children: scope.description })
1113
+ ] })
1114
+ ] }, scope.id);
1115
+ if (needers.length === 0) {
1116
+ return row;
1117
+ }
1118
+ return /* @__PURE__ */ jsxs4("div", { style: { minWidth: 0 }, children: [
1119
+ row,
1120
+ /* @__PURE__ */ jsxs4("small", { id: noteId, style: { ...mutedStyle, display: "block", paddingLeft: grouped ? 26 : 0, overflowWrap: "anywhere" }, children: [
1121
+ "needed by ",
1122
+ needers.join(", ")
1123
+ ] })
1124
+ ] }, scope.id);
1125
+ };
1126
+ if (layout === null) {
1127
+ return /* @__PURE__ */ jsxs4("fieldset", { style: { display: "grid", gap: "0.25rem", border: 0, padding: 0, minWidth: 0 }, children: [
1128
+ /* @__PURE__ */ jsx4("legend", { children: "Permissions" }),
1129
+ scopes.map((scope) => renderRow(scope, false))
1130
+ ] });
1131
+ }
1132
+ const pressed = offeredPresets.find((preset) => sameSelection(selected, preset.scopes));
1133
+ const plain = layout.filter((group) => !group.sensitive);
1134
+ const sensitive = layout.filter((group) => group.sensitive);
1135
+ const Chip = Badge ?? DefaultBadge;
1136
+ return /* @__PURE__ */ jsxs4("div", { style: { display: "grid", gap: "1rem", minWidth: 0 }, children: [
1137
+ /* @__PURE__ */ jsxs4("div", { style: { display: "grid", gap: "0.25rem" }, children: [
1138
+ /* @__PURE__ */ jsx4("strong", { children: "Permissions" }),
1139
+ offeredPresets.length > 0 && /* @__PURE__ */ jsx4("span", { style: mutedStyle, children: "Start from a preset, then adjust any permission below. The credential stores exactly the permissions you tick." })
1140
+ ] }),
1141
+ offeredPresets.length > 0 && /* @__PURE__ */ jsxs4("div", { style: { display: "grid", gap: "0.625rem" }, children: [
1142
+ /* @__PURE__ */ jsx4("div", { role: "group", "aria-label": "Presets", style: { display: "flex", flexWrap: "wrap", gap: "0.5rem" }, children: offeredPresets.map((preset) => {
1143
+ const isPressed = pressed?.id === preset.id;
1144
+ return /* @__PURE__ */ jsx4(
1145
+ Button,
1146
+ {
1147
+ type: "button",
1148
+ variant: isPressed ? "default" : "outline",
1149
+ "aria-pressed": isPressed,
1150
+ style: { minHeight: 44, maxWidth: "100%", overflowWrap: "anywhere", whiteSpace: "normal", textAlign: "left" },
1151
+ onClick: () => commit(withScopes([], preset.scopes, closed)),
1152
+ children: preset.label
1153
+ },
1154
+ preset.id
1155
+ );
1156
+ }) }),
1157
+ /* @__PURE__ */ jsx4("p", { "aria-live": "polite", style: { margin: 0, ...mutedStyle, overflowWrap: "anywhere" }, children: pressed ? pressed.description : "Custom selection. Pick a preset to replace it, or keep adjusting below." })
1158
+ ] }),
1159
+ plain.length > 0 && /* @__PURE__ */ jsx4("div", { style: gridStyle, children: plain.map((group) => /* @__PURE__ */ jsxs4("fieldset", { style: { ...boxStyle, display: "grid", gridTemplateColumns: "minmax(0, 1fr)" }, children: [
1160
+ /* @__PURE__ */ jsx4("legend", { style: { padding: "0 0.375rem", fontWeight: 600, overflowWrap: "anywhere" }, children: group.label }),
1161
+ group.scopes.map((scope) => renderRow(scope, true))
1162
+ ] }, group.id)) }),
1163
+ sensitive.map((group) => {
1164
+ const ids = group.scopes.map((scope) => scope.id);
1165
+ const count = ids.filter((id) => chosen.has(id)).length;
1166
+ const state = count === 0 ? "none" : count === ids.length ? "all" : "some";
1167
+ const parentId = `${idPrefix}-group-${group.id}`;
1168
+ const listId = `${parentId}-scopes`;
1169
+ const isOpen = open[group.id] === true;
1170
+ const warning = group.description !== null && group.description !== "" ? group.description : null;
1171
+ return /* @__PURE__ */ jsxs4("fieldset", { style: { ...boxStyle, display: "grid", gap: "0.375rem", paddingBottom: "0.875rem" }, children: [
1172
+ /* @__PURE__ */ jsxs4("legend", { style: { padding: "0 0.375rem", fontWeight: 600, display: "flex", alignItems: "center", gap: "0.5rem" }, children: [
1173
+ /* @__PURE__ */ jsx4("span", { style: { overflowWrap: "anywhere" }, children: group.label }),
1174
+ /* @__PURE__ */ jsx4(Chip, { style: { fontSize: 12, fontWeight: 500, border: "1px solid currentColor", borderRadius: 999, padding: "3px 8px", lineHeight: 1 }, children: "Sensitive" })
1175
+ ] }),
1176
+ warning !== null && (() => {
1177
+ const content = /* @__PURE__ */ jsxs4(Fragment, { children: [
1178
+ /* @__PURE__ */ jsx4(TriangleAlert, { "aria-hidden": "true", size: 16, style: { flex: "none", marginTop: 2 } }),
1179
+ /* @__PURE__ */ jsx4("span", { style: { minWidth: 0, overflowWrap: "anywhere" }, children: warning })
1180
+ ] });
1181
+ const style = { margin: "0.25rem 0 0", display: "flex", gap: "0.5rem", alignItems: "flex-start" };
1182
+ return Alert ? /* @__PURE__ */ jsx4(Alert, { style, children: content }) : /* @__PURE__ */ jsx4("p", { style: { ...style, color: "#b45309" }, children: content });
1183
+ })(),
1184
+ /* @__PURE__ */ jsxs4("label", { htmlFor: parentId, style: { ...touchRow, cursor: "pointer" }, children: [
1185
+ /* @__PURE__ */ jsx4(
1186
+ "input",
1187
+ {
1188
+ id: parentId,
1189
+ type: "checkbox",
1190
+ checked: state === "all",
1191
+ "aria-checked": state === "some" ? "mixed" : state === "all",
1192
+ ref: (element) => {
1193
+ if (element) {
1194
+ element.indeterminate = state === "some";
1195
+ }
1196
+ },
1197
+ onChange: () => commit(state === "all" ? withoutScopes(selected, ids, closed) : withScopes(selected, ids, closed)),
1198
+ style: { flex: "none", width: 16, height: 16, margin: "2px 0 0" }
1199
+ }
1200
+ ),
1201
+ " ",
1202
+ /* @__PURE__ */ jsxs4("span", { style: { minWidth: 0, overflowWrap: "anywhere" }, children: [
1203
+ /* @__PURE__ */ jsx4("strong", { children: group.label }),
1204
+ " ",
1205
+ /* @__PURE__ */ jsx4("span", { style: mutedStyle, children: state === "all" ? `All ${ids.length} ${group.label} permissions are selected.` : state === "some" ? `${count} of ${ids.length} ${group.label} permissions are selected.` : `Selects all ${ids.length} ${group.label} permissions.` })
1206
+ ] })
1207
+ ] }),
1208
+ /* @__PURE__ */ jsx4("div", { children: /* @__PURE__ */ jsxs4(
1209
+ Button,
1210
+ {
1211
+ type: "button",
1212
+ variant: "ghost",
1213
+ "aria-expanded": isOpen,
1214
+ "aria-controls": listId,
1215
+ style: { minHeight: 44, whiteSpace: "normal", textAlign: "left" },
1216
+ onClick: () => setOpen((current) => ({ ...current, [group.id]: !isOpen })),
1217
+ children: [
1218
+ /* @__PURE__ */ jsx4(ChevronRight, { "aria-hidden": "true", size: 16, style: { flex: "none", transition: "transform 120ms", transform: isOpen ? "rotate(90deg)" : "none" } }),
1219
+ isOpen ? "Hide" : "Adjust",
1220
+ " individual ",
1221
+ group.label,
1222
+ " permissions"
1223
+ ]
1224
+ }
1225
+ ) }),
1226
+ isOpen && /* @__PURE__ */ jsx4("div", { id: listId, style: { ...gridStyle, columnGap: "1.5rem", gap: "0 1.5rem", paddingLeft: "1.5rem", marginLeft: 7, borderLeft: "2px solid rgba(128, 128, 128, 0.35)" }, children: group.scopes.map((scope) => renderRow(scope, true)) })
1227
+ ] }, group.id);
1228
+ }),
1229
+ /* @__PURE__ */ jsxs4("div", { style: { borderTop: "1px solid rgba(128, 128, 128, 0.35)", paddingTop: "0.875rem", display: "grid", gap: "0.5rem" }, children: [
1230
+ /* @__PURE__ */ jsx4("p", { style: { margin: 0, fontWeight: 500 }, role: "status", children: selected.length === 0 ? "No permissions selected." : `This credential will request ${selected.length} ${selected.length === 1 ? "permission" : "permissions"}:` }),
1231
+ selected.length > 0 && /* @__PURE__ */ jsx4("p", { style: { margin: 0, display: "flex", flexWrap: "wrap", gap: "0.375rem" }, children: selected.map((id) => /* @__PURE__ */ jsx4("code", { style: { overflowWrap: "anywhere" }, children: id }, id)) })
1232
+ ] })
1233
+ ] });
1234
+ }
1235
+
1236
+ // src/api-credentials-section.tsx
1237
+ import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
1238
+ function ApiCredentialsSection({ indexUrl, components, links = [], csrfToken, request, onSuccess, onError }) {
950
1239
  const { Card, CardContent, CardDescription, CardHeader, CardTitle } = resolveAuthComponents(components);
951
- const [index, setIndex] = React5.useState(null);
952
- const [issued, setIssued] = React5.useState([]);
953
- const issuedKey = React5.useRef(0);
954
- const addIssued = React5.useCallback((credential) => {
1240
+ const [index, setIndex] = React6.useState(null);
1241
+ const [issued, setIssued] = React6.useState([]);
1242
+ const issuedKey = React6.useRef(0);
1243
+ const addIssued = React6.useCallback((credential) => {
955
1244
  issuedKey.current += 1;
956
1245
  const key = issuedKey.current;
957
1246
  setIssued((current) => [...current, { key, credential }]);
958
1247
  }, []);
959
- const [loadError, setLoadError] = React5.useState(null);
960
- const onErrorRef = React5.useRef(onError);
1248
+ const [loadError, setLoadError] = React6.useState(null);
1249
+ const onErrorRef = React6.useRef(onError);
961
1250
  onErrorRef.current = onError;
962
- const generation = React5.useRef(0);
963
- const context = React5.useRef({ indexUrl, csrfToken });
964
- context.current = { indexUrl, csrfToken };
965
- const reload = React5.useCallback(async () => {
1251
+ const generation = React6.useRef(0);
1252
+ const context = React6.useRef({ indexUrl, csrfToken, request });
1253
+ context.current = { indexUrl, csrfToken, request };
1254
+ const reload = React6.useCallback(async () => {
966
1255
  generation.current += 1;
967
1256
  const mine = generation.current;
968
- const { indexUrl: url, csrfToken: token } = context.current;
969
- const result = await credentialRequest("GET", url, void 0, token);
1257
+ const { indexUrl: url, csrfToken: token, request: send } = context.current;
1258
+ const result = await credentialRequest("GET", url, void 0, token, send);
970
1259
  if (mine !== generation.current) {
971
1260
  return;
972
1261
  }
@@ -978,31 +1267,31 @@ function ApiCredentialsSection({ indexUrl, components, links = [], csrfToken, on
978
1267
  onErrorRef.current?.("api-credentials", result.message);
979
1268
  }
980
1269
  }, []);
981
- React5.useEffect(() => {
1270
+ React6.useEffect(() => {
982
1271
  setIndex(null);
983
1272
  void reload();
984
1273
  }, [indexUrl, csrfToken, reload]);
985
- const removeLocally = React5.useCallback((list, id) => {
1274
+ const removeLocally = React6.useCallback((list, id) => {
986
1275
  setIndex(
987
1276
  (current) => current === null ? current : list === "tokens" ? { ...current, tokens: current.tokens.filter((token) => token.id !== id) } : { ...current, apps: current.apps.filter((app) => app.id !== id) }
988
1277
  );
989
1278
  }, []);
990
- const shared = { components, csrfToken, onError, onSuccess, removeLocally };
991
- return /* @__PURE__ */ jsxs4(Card, { children: [
992
- /* @__PURE__ */ jsxs4(CardHeader, { children: [
993
- /* @__PURE__ */ jsx4(CardTitle, { children: "API access" }),
994
- /* @__PURE__ */ jsx4(CardDescription, { children: "Connect apps that use the API. Register an OAuth app for apps that sign you in, or create an API token for apps that ask for a key. Each carries only the permissions you choose, and never more than your own access." })
1279
+ const shared = { components, csrfToken, request, onError, onSuccess, removeLocally };
1280
+ return /* @__PURE__ */ jsxs5(Card, { children: [
1281
+ /* @__PURE__ */ jsxs5(CardHeader, { children: [
1282
+ /* @__PURE__ */ jsx5(CardTitle, { children: "API access" }),
1283
+ /* @__PURE__ */ jsx5(CardDescription, { children: "Connect apps that use the API. Register an OAuth app for apps that sign you in, or create an API token for apps that ask for a key. Each carries only the permissions you choose, and never more than your own access." })
995
1284
  ] }),
996
- /* @__PURE__ */ jsx4(CardContent, { children: /* @__PURE__ */ jsxs4("div", { style: { display: "grid", gap: "1.5rem", minWidth: 0 }, children: [
997
- links.length > 0 && /* @__PURE__ */ jsx4("dl", { style: { display: "grid", gap: "0.5rem", minWidth: 0 }, children: links.map((link) => /* @__PURE__ */ jsxs4("div", { style: { minWidth: 0 }, children: [
998
- /* @__PURE__ */ jsx4("dt", { children: link.label }),
999
- /* @__PURE__ */ jsxs4("dd", { style: { margin: 0, overflowWrap: "anywhere" }, children: [
1000
- /* @__PURE__ */ jsx4("code", { children: link.url }),
1285
+ /* @__PURE__ */ jsx5(CardContent, { children: /* @__PURE__ */ jsxs5("div", { style: { display: "grid", gap: "1.5rem", minWidth: 0 }, children: [
1286
+ links.length > 0 && /* @__PURE__ */ jsx5("dl", { style: { display: "grid", gap: "0.5rem", minWidth: 0 }, children: links.map((link) => /* @__PURE__ */ jsxs5("div", { style: { minWidth: 0 }, children: [
1287
+ /* @__PURE__ */ jsx5("dt", { children: link.label }),
1288
+ /* @__PURE__ */ jsxs5("dd", { style: { margin: 0, overflowWrap: "anywhere" }, children: [
1289
+ /* @__PURE__ */ jsx5("code", { children: link.url }),
1001
1290
  " ",
1002
- /* @__PURE__ */ jsx4(CopyButton, { text: link.url, label: link.label, components })
1291
+ /* @__PURE__ */ jsx5(CopyButton, { text: link.url, label: link.label, components })
1003
1292
  ] })
1004
1293
  ] }, link.label)) }),
1005
- issued.map(({ key, credential }) => /* @__PURE__ */ jsx4(
1294
+ issued.map(({ key, credential }) => /* @__PURE__ */ jsx5(
1006
1295
  IssuedNotice,
1007
1296
  {
1008
1297
  issued: credential,
@@ -1011,29 +1300,36 @@ function ApiCredentialsSection({ indexUrl, components, links = [], csrfToken, on
1011
1300
  },
1012
1301
  key
1013
1302
  )),
1014
- loadError !== null && /* @__PURE__ */ jsx4("p", { role: "alert", children: loadError }),
1015
- index !== null && /* @__PURE__ */ jsxs4(Fragment, { children: [
1016
- (index.issue_token_href === null || index.register_app_href === null) && /* @__PURE__ */ jsx4("p", { role: "status", children: "Creating new credentials is unavailable right now. You can still revoke existing ones." }),
1017
- /* @__PURE__ */ jsx4(TokenSection, { index, ...shared, onIssued: addIssued, reload }),
1018
- /* @__PURE__ */ jsx4(AppSection, { index, ...shared, onIssued: addIssued, reload })
1303
+ loadError !== null && /* @__PURE__ */ jsx5("p", { role: "alert", children: loadError }),
1304
+ index !== null && /* @__PURE__ */ jsxs5(Fragment2, { children: [
1305
+ (index.issue_token_href === null || index.register_app_href === null) && /* @__PURE__ */ jsx5("p", { role: "status", children: "Creating new credentials is unavailable right now. You can still revoke existing ones." }),
1306
+ /* @__PURE__ */ jsx5(TokenSection, { index, ...shared, onIssued: addIssued, reload }),
1307
+ /* @__PURE__ */ jsx5(AppSection, { index, ...shared, onIssued: addIssued, reload })
1019
1308
  ] })
1020
1309
  ] }) })
1021
1310
  ] });
1022
1311
  }
1023
- function TokenSection({ index, components, csrfToken, onIssued, reload, onSuccess, onError, removeLocally }) {
1024
- const { Button, Input, Label } = resolveAuthComponents(components);
1025
- const [name, setName] = React5.useState("");
1026
- const [scopes, setScopes] = React5.useState([]);
1027
- const [lifetime, setLifetime] = React5.useState(index.token_lifetimes[0] ?? "");
1028
- const [busy, setBusy] = React5.useState(false);
1029
- const [error, setError] = React5.useState(null);
1312
+ function TokenSection({ index, components, csrfToken, request, onIssued, reload, onSuccess, onError, removeLocally }) {
1313
+ const { Button, Input, Label, RadioGroup } = resolveAuthComponents(components);
1314
+ const [name, setName] = React6.useState("");
1315
+ const [scopes, setScopes] = React6.useState([]);
1316
+ const [lifetime, setLifetime] = React6.useState(index.token_lifetimes[0] ?? "");
1317
+ const tokenScopes = React6.useMemo(
1318
+ () => [...index.token_scopes ?? index.scopes, ...index.token_connection_scopes ?? []],
1319
+ [index.token_scopes, index.scopes, index.token_connection_scopes]
1320
+ );
1321
+ const connectionIds = new Set((index.token_connection_scopes ?? []).map((scope) => scope.id));
1322
+ const lifetimes = index.connection_token_lifetimes && index.connection_token_lifetimes.length > 0 && scopes.some((id) => connectionIds.has(id)) ? index.connection_token_lifetimes : index.token_lifetimes;
1323
+ const effectiveLifetime = lifetimes.includes(lifetime) ? lifetime : lifetimes[0] ?? "";
1324
+ const [busy, setBusy] = React6.useState(false);
1325
+ const [error, setError] = React6.useState(null);
1030
1326
  async function create(event) {
1031
1327
  event.preventDefault();
1032
1328
  if (index.issue_token_href === null) {
1033
1329
  return;
1034
1330
  }
1035
1331
  setBusy(true);
1036
- const result = await credentialRequest("POST", index.issue_token_href, { name, scopes, lifetime }, csrfToken);
1332
+ const result = await credentialRequest("POST", index.issue_token_href, { name, scopes, lifetime: effectiveLifetime }, csrfToken, request);
1037
1333
  setBusy(false);
1038
1334
  if (!result.ok) {
1039
1335
  setError(result.message);
@@ -1047,13 +1343,13 @@ function TokenSection({ index, components, csrfToken, onIssued, reload, onSucces
1047
1343
  onSuccess?.("API token created.");
1048
1344
  await reload();
1049
1345
  }
1050
- const [pending, setPending] = React5.useState([]);
1346
+ const [pending, setPending] = React6.useState([]);
1051
1347
  async function revoke(token) {
1052
1348
  if (pending.includes(token.id)) {
1053
1349
  return;
1054
1350
  }
1055
1351
  setPending((current) => [...current, token.id]);
1056
- const result = await credentialRequest("DELETE", token.revoke_href, void 0, csrfToken);
1352
+ const result = await credentialRequest("DELETE", token.revoke_href, void 0, csrfToken, request);
1057
1353
  if (!result.ok) {
1058
1354
  setPending((current) => current.filter((id) => id !== token.id));
1059
1355
  setError(result.message);
@@ -1066,46 +1362,67 @@ function TokenSection({ index, components, csrfToken, onIssued, reload, onSucces
1066
1362
  await reload();
1067
1363
  setPending((current) => current.filter((id) => id !== token.id));
1068
1364
  }
1069
- return /* @__PURE__ */ jsxs4("section", { style: { display: "grid", gap: "0.75rem", minWidth: 0 }, children: [
1070
- /* @__PURE__ */ jsx4("h3", { children: "API tokens" }),
1071
- index.issue_token_href !== null && /* @__PURE__ */ jsxs4("form", { onSubmit: create, style: { display: "grid", gap: "0.75rem" }, children: [
1072
- /* @__PURE__ */ jsxs4("div", { style: { display: "grid", gap: "0.25rem" }, children: [
1073
- /* @__PURE__ */ jsx4(Label, { htmlFor: "api-token-name", children: "Token name" }),
1074
- /* @__PURE__ */ jsx4(Input, { id: "api-token-name", value: name, maxLength: 120, onChange: (event) => setName(event.target.value) })
1365
+ return /* @__PURE__ */ jsxs5("section", { style: { display: "grid", gap: "0.75rem", minWidth: 0 }, children: [
1366
+ /* @__PURE__ */ jsx5("h3", { children: "API tokens" }),
1367
+ index.issue_token_href !== null && /* @__PURE__ */ jsxs5("form", { onSubmit: create, style: { display: "grid", gap: "0.75rem" }, children: [
1368
+ /* @__PURE__ */ jsxs5("div", { style: { display: "grid", gap: "0.25rem" }, children: [
1369
+ /* @__PURE__ */ jsx5(Label, { htmlFor: "api-token-name", children: "Token name" }),
1370
+ /* @__PURE__ */ jsx5(Input, { id: "api-token-name", value: name, maxLength: 120, onChange: (event) => setName(event.target.value) })
1075
1371
  ] }),
1076
- /* @__PURE__ */ jsx4(ScopePicker, { idPrefix: "api-token-scope", scopes: index.scopes, selected: scopes, onChange: setScopes }),
1077
- /* @__PURE__ */ jsxs4("fieldset", { style: { display: "grid", gap: "0.25rem", border: 0, padding: 0 }, children: [
1078
- /* @__PURE__ */ jsx4("legend", { children: "Expires after" }),
1079
- index.token_lifetimes.map((spec) => /* @__PURE__ */ jsxs4("label", { children: [
1080
- /* @__PURE__ */ jsx4("input", { type: "radio", name: "api-token-lifetime", checked: lifetime === spec, onChange: () => setLifetime(spec) }),
1372
+ /* @__PURE__ */ jsx5(
1373
+ ScopePicker,
1374
+ {
1375
+ idPrefix: "api-token-scope",
1376
+ scopes: tokenScopes,
1377
+ groups: index.token_scope_groups ?? index.scope_groups,
1378
+ presets: index.token_scope_presets ?? index.scope_presets,
1379
+ implications: index.token_scope_implications ?? index.scope_implications,
1380
+ selected: scopes,
1381
+ onChange: setScopes,
1382
+ components
1383
+ }
1384
+ ),
1385
+ /* @__PURE__ */ jsxs5("fieldset", { style: { display: "grid", gap: "0.25rem", border: 0, padding: 0 }, children: [
1386
+ /* @__PURE__ */ jsx5("legend", { children: "Expires after" }),
1387
+ RadioGroup ? /* @__PURE__ */ jsx5(
1388
+ RadioGroup,
1389
+ {
1390
+ name: "api-token-lifetime",
1391
+ value: effectiveLifetime,
1392
+ onValueChange: setLifetime,
1393
+ options: lifetimes.map((spec) => ({ value: spec, label: describeDuration(spec) }))
1394
+ }
1395
+ ) : lifetimes.map((spec) => /* @__PURE__ */ jsxs5("label", { children: [
1396
+ /* @__PURE__ */ jsx5("input", { type: "radio", name: "api-token-lifetime", checked: effectiveLifetime === spec, onChange: () => setLifetime(spec) }),
1081
1397
  " ",
1082
1398
  describeDuration(spec)
1083
1399
  ] }, spec))
1084
1400
  ] }),
1085
- /* @__PURE__ */ jsx4("div", { children: /* @__PURE__ */ jsx4(Button, { type: "submit", disabled: busy || name.trim() === "" || scopes.length === 0 || lifetime === "", children: "Create API token" }) })
1401
+ /* @__PURE__ */ jsx5("div", { children: /* @__PURE__ */ jsx5(Button, { type: "submit", disabled: busy || name.trim() === "" || scopes.length === 0 || effectiveLifetime === "", children: "Create API token" }) })
1086
1402
  ] }),
1087
- error !== null && /* @__PURE__ */ jsx4("p", { role: "alert", children: error }),
1088
- /* @__PURE__ */ jsx4("ul", { style: { display: "grid", gap: "0.5rem", listStyle: "none", padding: 0, margin: 0, minWidth: 0 }, children: index.tokens.map((token) => /* @__PURE__ */ jsxs4("li", { style: { minWidth: 0, overflowWrap: "anywhere" }, children: [
1089
- /* @__PURE__ */ jsx4("strong", { children: token.name }),
1403
+ error !== null && /* @__PURE__ */ jsx5("p", { role: "alert", children: error }),
1404
+ /* @__PURE__ */ jsx5("ul", { style: { display: "grid", gap: "0.5rem", listStyle: "none", padding: 0, margin: 0, minWidth: 0 }, children: index.tokens.map((token) => /* @__PURE__ */ jsxs5("li", { style: { minWidth: 0, overflowWrap: "anywhere" }, children: [
1405
+ /* @__PURE__ */ jsx5("strong", { children: token.name }),
1090
1406
  " \xB7 ",
1091
1407
  token.scopes.join(", "),
1092
- token.expires_at !== null && /* @__PURE__ */ jsxs4(Fragment, { children: [
1408
+ token.connection === true && /* @__PURE__ */ jsx5(Fragment2, { children: " \xB7 MCP connection" }),
1409
+ token.expires_at !== null && /* @__PURE__ */ jsxs5(Fragment2, { children: [
1093
1410
  " \xB7 expires ",
1094
1411
  new Date(token.expires_at).toLocaleString()
1095
1412
  ] }),
1096
1413
  " ",
1097
- /* @__PURE__ */ jsx4(Button, { type: "button", disabled: pending.includes(token.id), onClick: () => void revoke(token), children: "Revoke" })
1414
+ /* @__PURE__ */ jsx5(Button, { type: "button", disabled: pending.includes(token.id), onClick: () => void revoke(token), children: "Revoke" })
1098
1415
  ] }, token.id)) })
1099
1416
  ] });
1100
1417
  }
1101
- function AppSection({ index, components, csrfToken, onIssued, reload, onSuccess, onError, removeLocally }) {
1102
- const { Button, Input, Label } = resolveAuthComponents(components);
1103
- const [name, setName] = React5.useState("");
1104
- const [redirects, setRedirects] = React5.useState("");
1105
- const [confidential, setConfidential] = React5.useState(true);
1106
- const [scopes, setScopes] = React5.useState([]);
1107
- const [busy, setBusy] = React5.useState(false);
1108
- const [error, setError] = React5.useState(null);
1418
+ function AppSection({ index, components, csrfToken, request, onIssued, reload, onSuccess, onError, removeLocally }) {
1419
+ const { Button, Input, Label, Textarea, RadioGroup } = resolveAuthComponents(components);
1420
+ const [name, setName] = React6.useState("");
1421
+ const [redirects, setRedirects] = React6.useState("");
1422
+ const [confidential, setConfidential] = React6.useState(true);
1423
+ const [scopes, setScopes] = React6.useState([]);
1424
+ const [busy, setBusy] = React6.useState(false);
1425
+ const [error, setError] = React6.useState(null);
1109
1426
  const redirectUris = redirects.split("\n").map((line) => line.trim()).filter((line) => line !== "");
1110
1427
  async function register(event) {
1111
1428
  event.preventDefault();
@@ -1117,7 +1434,8 @@ function AppSection({ index, components, csrfToken, onIssued, reload, onSuccess,
1117
1434
  "POST",
1118
1435
  index.register_app_href,
1119
1436
  { name, redirect_uris: redirectUris, confidential, scopes },
1120
- csrfToken
1437
+ csrfToken,
1438
+ request
1121
1439
  );
1122
1440
  setBusy(false);
1123
1441
  if (!result.ok) {
@@ -1133,13 +1451,13 @@ function AppSection({ index, components, csrfToken, onIssued, reload, onSuccess,
1133
1451
  onSuccess?.("OAuth app registered.");
1134
1452
  await reload();
1135
1453
  }
1136
- const [pending, setPending] = React5.useState([]);
1454
+ const [pending, setPending] = React6.useState([]);
1137
1455
  async function remove(app) {
1138
1456
  if (pending.includes(app.id)) {
1139
1457
  return;
1140
1458
  }
1141
1459
  setPending((current) => [...current, app.id]);
1142
- const result = await credentialRequest("DELETE", app.delete_href, void 0, csrfToken);
1460
+ const result = await credentialRequest("DELETE", app.delete_href, void 0, csrfToken, request);
1143
1461
  if (!result.ok) {
1144
1462
  setPending((current) => current.filter((id) => id !== app.id));
1145
1463
  setError(result.message);
@@ -1152,76 +1470,73 @@ function AppSection({ index, components, csrfToken, onIssued, reload, onSuccess,
1152
1470
  await reload();
1153
1471
  setPending((current) => current.filter((id) => id !== app.id));
1154
1472
  }
1155
- return /* @__PURE__ */ jsxs4("section", { style: { display: "grid", gap: "0.75rem", minWidth: 0 }, children: [
1156
- /* @__PURE__ */ jsx4("h3", { children: "OAuth apps" }),
1157
- index.register_app_href !== null && /* @__PURE__ */ jsxs4("form", { onSubmit: register, style: { display: "grid", gap: "0.75rem" }, children: [
1158
- /* @__PURE__ */ jsxs4("div", { style: { display: "grid", gap: "0.25rem" }, children: [
1159
- /* @__PURE__ */ jsx4(Label, { htmlFor: "oauth-app-name", children: "App name" }),
1160
- /* @__PURE__ */ jsx4(Input, { id: "oauth-app-name", value: name, maxLength: 120, onChange: (event) => setName(event.target.value) })
1473
+ return /* @__PURE__ */ jsxs5("section", { style: { display: "grid", gap: "0.75rem", minWidth: 0 }, children: [
1474
+ /* @__PURE__ */ jsx5("h3", { children: "OAuth apps" }),
1475
+ index.register_app_href !== null && /* @__PURE__ */ jsxs5("form", { onSubmit: register, style: { display: "grid", gap: "0.75rem" }, children: [
1476
+ /* @__PURE__ */ jsxs5("div", { style: { display: "grid", gap: "0.25rem" }, children: [
1477
+ /* @__PURE__ */ jsx5(Label, { htmlFor: "oauth-app-name", children: "App name" }),
1478
+ /* @__PURE__ */ jsx5(Input, { id: "oauth-app-name", value: name, maxLength: 120, onChange: (event) => setName(event.target.value) })
1161
1479
  ] }),
1162
- /* @__PURE__ */ jsxs4("div", { style: { display: "grid", gap: "0.25rem" }, children: [
1163
- /* @__PURE__ */ jsx4(Label, { htmlFor: "oauth-app-redirects", children: "Redirect URIs (one per line)" }),
1164
- /* @__PURE__ */ jsx4("textarea", { id: "oauth-app-redirects", rows: 3, value: redirects, onChange: (event) => setRedirects(event.target.value) })
1480
+ /* @__PURE__ */ jsxs5("div", { style: { display: "grid", gap: "0.25rem" }, children: [
1481
+ /* @__PURE__ */ jsx5(Label, { htmlFor: "oauth-app-redirects", children: "Redirect URIs (one per line)" }),
1482
+ Textarea ? /* @__PURE__ */ jsx5(Textarea, { id: "oauth-app-redirects", rows: 3, value: redirects, onChange: (event) => setRedirects(event.target.value) }) : /* @__PURE__ */ jsx5("textarea", { id: "oauth-app-redirects", rows: 3, value: redirects, onChange: (event) => setRedirects(event.target.value) })
1165
1483
  ] }),
1166
- /* @__PURE__ */ jsxs4("fieldset", { style: { display: "grid", gap: "0.25rem", border: 0, padding: 0 }, children: [
1167
- /* @__PURE__ */ jsx4("legend", { children: "Client type" }),
1168
- /* @__PURE__ */ jsxs4("label", { children: [
1169
- /* @__PURE__ */ jsx4("input", { type: "radio", name: "oauth-app-type", checked: confidential, onChange: () => setConfidential(true) }),
1170
- " Confidential: the app keeps a client secret on its server"
1171
- ] }),
1172
- /* @__PURE__ */ jsxs4("label", { children: [
1173
- /* @__PURE__ */ jsx4("input", { type: "radio", name: "oauth-app-type", checked: !confidential, onChange: () => setConfidential(false) }),
1174
- " Public: no secret, PKCE only"
1484
+ /* @__PURE__ */ jsxs5("fieldset", { style: { display: "grid", gap: "0.25rem", border: 0, padding: 0 }, children: [
1485
+ /* @__PURE__ */ jsx5("legend", { children: "Client type" }),
1486
+ RadioGroup ? /* @__PURE__ */ jsx5(
1487
+ RadioGroup,
1488
+ {
1489
+ name: "oauth-app-type",
1490
+ value: confidential ? "confidential" : "public",
1491
+ onValueChange: (value) => setConfidential(value === "confidential"),
1492
+ options: [
1493
+ { value: "confidential", label: "Confidential: the app keeps a client secret on its server" },
1494
+ { value: "public", label: "Public: no secret, PKCE only" }
1495
+ ]
1496
+ }
1497
+ ) : /* @__PURE__ */ jsxs5(Fragment2, { children: [
1498
+ /* @__PURE__ */ jsxs5("label", { children: [
1499
+ /* @__PURE__ */ jsx5("input", { type: "radio", name: "oauth-app-type", checked: confidential, onChange: () => setConfidential(true) }),
1500
+ " Confidential: the app keeps a client secret on its server"
1501
+ ] }),
1502
+ /* @__PURE__ */ jsxs5("label", { children: [
1503
+ /* @__PURE__ */ jsx5("input", { type: "radio", name: "oauth-app-type", checked: !confidential, onChange: () => setConfidential(false) }),
1504
+ " Public: no secret, PKCE only"
1505
+ ] })
1175
1506
  ] })
1176
1507
  ] }),
1177
- /* @__PURE__ */ jsx4(ScopePicker, { idPrefix: "oauth-app-scope", scopes: index.scopes, selected: scopes, onChange: setScopes }),
1178
- /* @__PURE__ */ jsx4("div", { children: /* @__PURE__ */ jsx4(Button, { type: "submit", disabled: busy || name.trim() === "" || redirectUris.length === 0 || scopes.length === 0, children: "Register OAuth app" }) })
1508
+ /* @__PURE__ */ jsx5(
1509
+ ScopePicker,
1510
+ {
1511
+ idPrefix: "oauth-app-scope",
1512
+ scopes: index.scopes,
1513
+ groups: index.scope_groups,
1514
+ presets: index.scope_presets,
1515
+ implications: index.scope_implications,
1516
+ selected: scopes,
1517
+ onChange: setScopes,
1518
+ components
1519
+ }
1520
+ ),
1521
+ /* @__PURE__ */ jsx5("div", { children: /* @__PURE__ */ jsx5(Button, { type: "submit", disabled: busy || name.trim() === "" || redirectUris.length === 0 || scopes.length === 0, children: "Register OAuth app" }) })
1179
1522
  ] }),
1180
- error !== null && /* @__PURE__ */ jsx4("p", { role: "alert", children: error }),
1181
- /* @__PURE__ */ jsx4("ul", { style: { display: "grid", gap: "0.5rem", listStyle: "none", padding: 0, margin: 0, minWidth: 0 }, children: index.apps.map((app) => /* @__PURE__ */ jsxs4("li", { style: { minWidth: 0, overflowWrap: "anywhere" }, children: [
1182
- /* @__PURE__ */ jsx4("strong", { children: app.name }),
1523
+ error !== null && /* @__PURE__ */ jsx5("p", { role: "alert", children: error }),
1524
+ /* @__PURE__ */ jsx5("ul", { style: { display: "grid", gap: "0.5rem", listStyle: "none", padding: 0, margin: 0, minWidth: 0 }, children: index.apps.map((app) => /* @__PURE__ */ jsxs5("li", { style: { minWidth: 0, overflowWrap: "anywhere" }, children: [
1525
+ /* @__PURE__ */ jsx5("strong", { children: app.name }),
1183
1526
  " \xB7 client ID ",
1184
- /* @__PURE__ */ jsx4("code", { children: app.id }),
1527
+ /* @__PURE__ */ jsx5("code", { children: app.id }),
1185
1528
  " \xB7 ",
1186
1529
  app.confidential ? "confidential" : "public",
1187
- /* @__PURE__ */ jsx4("br", {}),
1530
+ /* @__PURE__ */ jsx5("br", {}),
1188
1531
  app.redirect_uris.join(", "),
1189
- /* @__PURE__ */ jsx4("br", {}),
1532
+ /* @__PURE__ */ jsx5("br", {}),
1190
1533
  "May request: ",
1191
1534
  app.scopes.join(", "),
1192
1535
  " ",
1193
- /* @__PURE__ */ jsx4(Button, { type: "button", disabled: pending.includes(app.id), onClick: () => void remove(app), children: "Delete" })
1536
+ /* @__PURE__ */ jsx5(Button, { type: "button", disabled: pending.includes(app.id), onClick: () => void remove(app), children: "Delete" })
1194
1537
  ] }, app.id)) })
1195
1538
  ] });
1196
1539
  }
1197
- function ScopePicker({
1198
- idPrefix,
1199
- scopes,
1200
- selected,
1201
- onChange
1202
- }) {
1203
- return /* @__PURE__ */ jsxs4("fieldset", { style: { display: "grid", gap: "0.25rem", border: 0, padding: 0, minWidth: 0 }, children: [
1204
- /* @__PURE__ */ jsx4("legend", { children: "Permissions" }),
1205
- scopes.map((scope) => {
1206
- const id = `${idPrefix}-${scope.id}`;
1207
- return /* @__PURE__ */ jsxs4("label", { htmlFor: id, style: { overflowWrap: "anywhere" }, children: [
1208
- /* @__PURE__ */ jsx4(
1209
- "input",
1210
- {
1211
- id,
1212
- type: "checkbox",
1213
- checked: selected.includes(scope.id),
1214
- onChange: (event) => onChange(event.target.checked ? [...selected, scope.id] : selected.filter((value) => value !== scope.id))
1215
- }
1216
- ),
1217
- " ",
1218
- /* @__PURE__ */ jsx4("code", { children: scope.id }),
1219
- " ",
1220
- scope.description
1221
- ] }, scope.id);
1222
- })
1223
- ] });
1224
- }
1225
1540
  function IssuedNotice({
1226
1541
  issued,
1227
1542
  components,
@@ -1232,26 +1547,26 @@ function IssuedNotice({
1232
1547
  { label: "Client ID", url: issued.client_id },
1233
1548
  ...issued.client_secret !== null ? [{ label: "Client secret", url: issued.client_secret }] : []
1234
1549
  ];
1235
- return /* @__PURE__ */ jsxs4("div", { role: "status", style: { display: "grid", gap: "0.5rem", minWidth: 0 }, children: [
1236
- /* @__PURE__ */ jsxs4("p", { style: { overflowWrap: "anywhere" }, children: [
1550
+ return /* @__PURE__ */ jsxs5("div", { role: "status", style: { display: "grid", gap: "0.5rem", minWidth: 0 }, children: [
1551
+ /* @__PURE__ */ jsxs5("p", { style: { overflowWrap: "anywhere" }, children: [
1237
1552
  issued.kind === "token" ? `API token \u201C${issued.name}\u201D created.` : `OAuth app \u201C${issued.name}\u201D registered.`,
1238
1553
  " Copy it now: it will not be shown again."
1239
1554
  ] }),
1240
- values.map((value) => /* @__PURE__ */ jsxs4("div", { style: { minWidth: 0, overflowWrap: "anywhere" }, children: [
1555
+ values.map((value) => /* @__PURE__ */ jsxs5("div", { style: { minWidth: 0, overflowWrap: "anywhere" }, children: [
1241
1556
  value.label,
1242
1557
  ": ",
1243
- /* @__PURE__ */ jsx4("code", { children: value.url }),
1558
+ /* @__PURE__ */ jsx5("code", { children: value.url }),
1244
1559
  " ",
1245
- /* @__PURE__ */ jsx4(CopyButton, { text: value.url, label: value.label, components })
1560
+ /* @__PURE__ */ jsx5(CopyButton, { text: value.url, label: value.label, components })
1246
1561
  ] }, value.label)),
1247
- /* @__PURE__ */ jsx4("div", { children: /* @__PURE__ */ jsx4(Button, { type: "button", onClick: onDismiss, children: "Done" }) })
1562
+ /* @__PURE__ */ jsx5("div", { children: /* @__PURE__ */ jsx5(Button, { type: "button", onClick: onDismiss, children: "Done" }) })
1248
1563
  ] });
1249
1564
  }
1250
1565
  function CopyButton({ text, label, components }) {
1251
1566
  const { Button } = resolveAuthComponents(components);
1252
- const [state, setState] = React5.useState("idle");
1253
- return /* @__PURE__ */ jsxs4(Fragment, { children: [
1254
- /* @__PURE__ */ jsx4(
1567
+ const [state, setState] = React6.useState("idle");
1568
+ return /* @__PURE__ */ jsxs5(Fragment2, { children: [
1569
+ /* @__PURE__ */ jsx5(
1255
1570
  Button,
1256
1571
  {
1257
1572
  type: "button",
@@ -1271,7 +1586,7 @@ function CopyButton({ text, label, components }) {
1271
1586
  children: state === "copied" ? "Copied" : "Copy"
1272
1587
  }
1273
1588
  ),
1274
- state === "failed" && /* @__PURE__ */ jsx4("span", { role: "status", children: " Copying is unavailable here; select the text and copy it manually." })
1589
+ state === "failed" && /* @__PURE__ */ jsx5("span", { role: "status", children: " Copying is unavailable here; select the text and copy it manually." })
1275
1590
  ] });
1276
1591
  }
1277
1592
  function describeDuration(spec) {
@@ -1283,7 +1598,16 @@ function describeDuration(spec) {
1283
1598
  const parts = match.slice(1).map((value, position) => value ? `${Number(value)} ${units[position]}${Number(value) === 1 ? "" : "s"}` : null).filter((part) => part !== null);
1284
1599
  return parts.length > 0 ? parts.join(" ") : spec;
1285
1600
  }
1286
- async function credentialRequest(method, url, body, csrfToken) {
1601
+ async function credentialRequest(method, url, body, csrfToken, request) {
1602
+ if (request !== void 0) {
1603
+ let result;
1604
+ try {
1605
+ result = await request(method, url, body);
1606
+ } catch {
1607
+ return { ok: false, status: 0, message: "The server could not be reached. Check the connection and try again." };
1608
+ }
1609
+ return result.ok ? { ok: true, status: result.status, data: unwrapData(result.payload) } : result;
1610
+ }
1287
1611
  let response;
1288
1612
  try {
1289
1613
  response = await fetch(url, {
@@ -1301,11 +1625,13 @@ async function credentialRequest(method, url, body, csrfToken) {
1301
1625
  }
1302
1626
  const payload = await response.json().catch(() => null);
1303
1627
  if (response.ok) {
1304
- const data = typeof payload === "object" && payload !== null && "data" in payload ? payload.data : payload;
1305
- return { ok: true, status: response.status, data };
1628
+ return { ok: true, status: response.status, data: unwrapData(payload) };
1306
1629
  }
1307
1630
  return { ok: false, status: response.status, message: refusalMessage(response.status, payload) };
1308
1631
  }
1632
+ function unwrapData(payload) {
1633
+ return typeof payload === "object" && payload !== null && "data" in payload ? payload.data : payload;
1634
+ }
1309
1635
  function refusalMessage(status, payload) {
1310
1636
  if (status === 401 || status === 419) {
1311
1637
  return "Your session has expired. Reload the page and sign in again.";
@@ -1339,17 +1665,25 @@ export {
1339
1665
  PasskeySection,
1340
1666
  PasswordResetRequestForm,
1341
1667
  ResetPasswordForm,
1668
+ ScopePicker,
1342
1669
  SignupForm,
1343
1670
  TwoFactorForm,
1344
1671
  arrayBufferToBase64url,
1345
1672
  authenticateWithPasskey,
1346
1673
  base64urlToArrayBuffer,
1674
+ closeImplications,
1347
1675
  describeDuration,
1348
1676
  getCsrfToken,
1349
1677
  getDefaultPasskeyName,
1678
+ inCatalogOrder,
1350
1679
  isAbortError,
1351
1680
  isConditionalMediationAvailable,
1681
+ neededBy,
1352
1682
  registerPasskey,
1353
1683
  relyingApplicationsFrom,
1354
- safeApplicationHref
1684
+ restrictImplications,
1685
+ safeApplicationHref,
1686
+ sameSelection,
1687
+ withScopes,
1688
+ withoutScopes
1355
1689
  };