@rebasepro/studio 0.17.2 → 0.17.3-canary.g6aa77f5
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/ApiKeysView-DiCurTEU.js +1224 -0
- package/dist/ApiKeysView-DiCurTEU.js.map +1 -0
- package/dist/components/ApiKeys/CreateApiKeyDialog.d.ts +6 -0
- package/dist/components/ApiKeys/permissions.d.ts +66 -0
- package/dist/index.es.js +1 -1
- package/package.json +9 -9
- package/src/components/ApiKeys/ApiKeysView.tsx +69 -211
- package/src/components/ApiKeys/CreateApiKeyDialog.tsx +711 -0
- package/src/components/ApiKeys/permissions.ts +145 -0
- package/dist/ApiKeysView-C_UoUPuR.js +0 -728
- package/dist/ApiKeysView-C_UoUPuR.js.map +0 -1
|
@@ -1,728 +0,0 @@
|
|
|
1
|
-
import { useRebaseClient, useSnackbarController } from "@rebasepro/app";
|
|
2
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
-
import { AlertCircleIcon, Button, CheckCircleIcon, Checkbox, Chip, CircularProgress, CopyIcon, Dialog, DialogActions, DialogContent, DialogTitle, IconButton, KeyRoundIcon, PlusIcon, RefreshCwIcon, Select, SelectItem, TextField, Tooltip, Trash2Icon, Typography, cls, defaultBorderMixin, iconSize } from "@rebasepro/ui";
|
|
4
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
-
//#region src/components/ApiKeys/ApiKeysView.tsx
|
|
6
|
-
function formatRelative(iso) {
|
|
7
|
-
if (!iso) return "—";
|
|
8
|
-
const d = new Date(iso);
|
|
9
|
-
const now = Date.now();
|
|
10
|
-
const diff = d.getTime() - now;
|
|
11
|
-
const abs = Math.abs(diff);
|
|
12
|
-
if (abs < 6e4) return diff > 0 ? "in <1m" : "<1m ago";
|
|
13
|
-
if (abs < 36e5) {
|
|
14
|
-
const m = Math.round(abs / 6e4);
|
|
15
|
-
return diff > 0 ? `in ${m}m` : `${m}m ago`;
|
|
16
|
-
}
|
|
17
|
-
if (abs < 864e5) {
|
|
18
|
-
const h = Math.round(abs / 36e5);
|
|
19
|
-
return diff > 0 ? `in ${h}h` : `${h}h ago`;
|
|
20
|
-
}
|
|
21
|
-
return d.toLocaleDateString();
|
|
22
|
-
}
|
|
23
|
-
function permissionSummary(perms) {
|
|
24
|
-
if (perms.length === 0) return "No permissions";
|
|
25
|
-
const wildcard = perms.find((p) => p.collection === "*");
|
|
26
|
-
if (wildcard) return `All collections (${wildcard.operations.join(", ")})`;
|
|
27
|
-
if (perms.length === 1) return `${perms[0].collection} (${perms[0].operations.join(", ")})`;
|
|
28
|
-
return `${perms.length} collections`;
|
|
29
|
-
}
|
|
30
|
-
function isExpired(key) {
|
|
31
|
-
return !!(key.expires_at && new Date(key.expires_at) < /* @__PURE__ */ new Date());
|
|
32
|
-
}
|
|
33
|
-
function keyStatus(key) {
|
|
34
|
-
if (key.revoked_at) return {
|
|
35
|
-
label: "Revoked",
|
|
36
|
-
color: "text-red-500"
|
|
37
|
-
};
|
|
38
|
-
if (isExpired(key)) return {
|
|
39
|
-
label: "Expired",
|
|
40
|
-
color: "text-amber-500"
|
|
41
|
-
};
|
|
42
|
-
return {
|
|
43
|
-
label: "Active",
|
|
44
|
-
color: "text-emerald-500"
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
function ApiKeysView() {
|
|
48
|
-
const client = useRebaseClient();
|
|
49
|
-
const snackbar = useSnackbarController();
|
|
50
|
-
const [keys, setKeys] = useState([]);
|
|
51
|
-
const [loading, setLoading] = useState(true);
|
|
52
|
-
const [selectedId, setSelectedId] = useState(null);
|
|
53
|
-
const [showCreate, setShowCreate] = useState(false);
|
|
54
|
-
const [showSecret, setShowSecret] = useState(null);
|
|
55
|
-
const [revoking, setRevoking] = useState(null);
|
|
56
|
-
const [confirmRevoke, setConfirmRevoke] = useState(null);
|
|
57
|
-
const clientRef = useRef(client);
|
|
58
|
-
clientRef.current = client;
|
|
59
|
-
const snackbarRef = useRef(snackbar);
|
|
60
|
-
snackbarRef.current = snackbar;
|
|
61
|
-
const loadKeys = useCallback(async () => {
|
|
62
|
-
const c = clientRef.current;
|
|
63
|
-
if (!c?.apiKeys) {
|
|
64
|
-
setLoading(false);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
try {
|
|
68
|
-
const res = await c.apiKeys.listKeys();
|
|
69
|
-
setKeys(res.keys);
|
|
70
|
-
} catch (e) {
|
|
71
|
-
snackbarRef.current.open({
|
|
72
|
-
type: "error",
|
|
73
|
-
message: e instanceof Error ? e.message : String(e)
|
|
74
|
-
});
|
|
75
|
-
} finally {
|
|
76
|
-
setLoading(false);
|
|
77
|
-
}
|
|
78
|
-
}, []);
|
|
79
|
-
useEffect(() => {
|
|
80
|
-
loadKeys();
|
|
81
|
-
}, [loadKeys]);
|
|
82
|
-
const handleRevoke = async (id) => {
|
|
83
|
-
const c = clientRef.current;
|
|
84
|
-
if (!c?.apiKeys) return;
|
|
85
|
-
setRevoking(id);
|
|
86
|
-
try {
|
|
87
|
-
await c.apiKeys.revokeKey(id);
|
|
88
|
-
snackbarRef.current.open({
|
|
89
|
-
type: "success",
|
|
90
|
-
message: "API key revoked"
|
|
91
|
-
});
|
|
92
|
-
await loadKeys();
|
|
93
|
-
if (selectedId === id) setSelectedId(null);
|
|
94
|
-
} catch (e) {
|
|
95
|
-
snackbarRef.current.open({
|
|
96
|
-
type: "error",
|
|
97
|
-
message: e instanceof Error ? e.message : String(e)
|
|
98
|
-
});
|
|
99
|
-
} finally {
|
|
100
|
-
setRevoking(null);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
const handleCreated = (keyWithSecret) => {
|
|
104
|
-
setShowCreate(false);
|
|
105
|
-
setShowSecret(keyWithSecret);
|
|
106
|
-
loadKeys();
|
|
107
|
-
};
|
|
108
|
-
const selectedKey = keys.find((k) => k.id === selectedId);
|
|
109
|
-
const activeKeys = keys.filter((k) => !k.revoked_at && !isExpired(k));
|
|
110
|
-
const inactiveKeys = keys.filter((k) => k.revoked_at || isExpired(k));
|
|
111
|
-
if (loading) return /* @__PURE__ */ jsx("div", {
|
|
112
|
-
className: "flex items-center justify-center h-full",
|
|
113
|
-
children: /* @__PURE__ */ jsx(CircularProgress, {})
|
|
114
|
-
});
|
|
115
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
116
|
-
/* @__PURE__ */ jsxs("div", {
|
|
117
|
-
className: "flex h-full w-full overflow-hidden bg-white dark:bg-surface-950",
|
|
118
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
119
|
-
className: cls("flex flex-col w-[340px] min-w-[280px] border-r h-full", defaultBorderMixin),
|
|
120
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
121
|
-
className: cls("flex items-center justify-between px-4 py-2.5 border-b bg-surface-50 dark:bg-surface-900 min-h-[48px]", defaultBorderMixin),
|
|
122
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
123
|
-
className: "flex items-center gap-2",
|
|
124
|
-
children: [
|
|
125
|
-
/* @__PURE__ */ jsx(KeyRoundIcon, {
|
|
126
|
-
size: iconSize.smallest,
|
|
127
|
-
className: "text-primary"
|
|
128
|
-
}),
|
|
129
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
130
|
-
variant: "subtitle2",
|
|
131
|
-
className: "font-semibold",
|
|
132
|
-
children: "API Keys"
|
|
133
|
-
}),
|
|
134
|
-
/* @__PURE__ */ jsx(Chip, {
|
|
135
|
-
size: "smallest",
|
|
136
|
-
className: "bg-surface-200 dark:bg-surface-700 text-surface-600 dark:text-surface-300",
|
|
137
|
-
children: activeKeys.length
|
|
138
|
-
})
|
|
139
|
-
]
|
|
140
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
141
|
-
className: "flex items-center gap-1",
|
|
142
|
-
children: [/* @__PURE__ */ jsx(IconButton, {
|
|
143
|
-
size: "small",
|
|
144
|
-
onClick: loadKeys,
|
|
145
|
-
title: "Refresh",
|
|
146
|
-
children: /* @__PURE__ */ jsx(RefreshCwIcon, { size: iconSize.smallest })
|
|
147
|
-
}), /* @__PURE__ */ jsx(Button, {
|
|
148
|
-
size: "small",
|
|
149
|
-
color: "primary",
|
|
150
|
-
onClick: () => setShowCreate(true),
|
|
151
|
-
startIcon: /* @__PURE__ */ jsx(PlusIcon, { size: iconSize.smallest }),
|
|
152
|
-
children: "New"
|
|
153
|
-
})]
|
|
154
|
-
})]
|
|
155
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
156
|
-
className: "flex-1 overflow-y-auto p-2 space-y-1",
|
|
157
|
-
children: [
|
|
158
|
-
activeKeys.length === 0 && inactiveKeys.length === 0 && /* @__PURE__ */ jsxs("div", {
|
|
159
|
-
className: "flex flex-col items-center justify-center h-full gap-3 text-center p-6",
|
|
160
|
-
children: [
|
|
161
|
-
/* @__PURE__ */ jsx(KeyRoundIcon, {
|
|
162
|
-
size: iconSize.medium,
|
|
163
|
-
className: "text-surface-300 dark:text-surface-600"
|
|
164
|
-
}),
|
|
165
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
166
|
-
variant: "body2",
|
|
167
|
-
color: "secondary",
|
|
168
|
-
children: "No API keys yet"
|
|
169
|
-
}),
|
|
170
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
171
|
-
variant: "caption",
|
|
172
|
-
color: "disabled",
|
|
173
|
-
children: "Create a key to enable machine-to-machine authentication"
|
|
174
|
-
})
|
|
175
|
-
]
|
|
176
|
-
}),
|
|
177
|
-
activeKeys.map((key) => /* @__PURE__ */ jsx(KeyListItem, {
|
|
178
|
-
apiKey: key,
|
|
179
|
-
selected: selectedId === key.id,
|
|
180
|
-
onClick: () => setSelectedId(key.id)
|
|
181
|
-
}, key.id)),
|
|
182
|
-
inactiveKeys.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
183
|
-
className: "px-2 pt-3 pb-1",
|
|
184
|
-
children: /* @__PURE__ */ jsx(Typography, {
|
|
185
|
-
variant: "caption",
|
|
186
|
-
color: "disabled",
|
|
187
|
-
className: "text-[10px] uppercase tracking-wider font-medium",
|
|
188
|
-
children: "Revoked / Expired"
|
|
189
|
-
})
|
|
190
|
-
}), inactiveKeys.map((key) => /* @__PURE__ */ jsx(KeyListItem, {
|
|
191
|
-
apiKey: key,
|
|
192
|
-
selected: selectedId === key.id,
|
|
193
|
-
onClick: () => setSelectedId(key.id)
|
|
194
|
-
}, key.id))] })
|
|
195
|
-
]
|
|
196
|
-
})]
|
|
197
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
198
|
-
className: "flex-1 flex flex-col min-w-0 h-full overflow-hidden",
|
|
199
|
-
children: !selectedKey ? /* @__PURE__ */ jsx("div", {
|
|
200
|
-
className: "flex items-center justify-center h-full",
|
|
201
|
-
children: /* @__PURE__ */ jsx(Typography, {
|
|
202
|
-
variant: "body2",
|
|
203
|
-
color: "disabled",
|
|
204
|
-
children: "Select an API key to view details"
|
|
205
|
-
})
|
|
206
|
-
}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
207
|
-
/* @__PURE__ */ jsxs("div", {
|
|
208
|
-
className: cls("flex items-center justify-between px-5 py-3 border-b bg-white dark:bg-surface-950 min-h-[56px]", defaultBorderMixin),
|
|
209
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
210
|
-
className: "flex items-center gap-3 min-w-0",
|
|
211
|
-
children: [/* @__PURE__ */ jsx(KeyRoundIcon, {
|
|
212
|
-
size: iconSize.small,
|
|
213
|
-
className: "text-primary shrink-0"
|
|
214
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
215
|
-
className: "min-w-0",
|
|
216
|
-
children: [/* @__PURE__ */ jsx(Typography, {
|
|
217
|
-
variant: "subtitle1",
|
|
218
|
-
className: "font-semibold truncate",
|
|
219
|
-
children: selectedKey.name
|
|
220
|
-
}), /* @__PURE__ */ jsxs(Typography, {
|
|
221
|
-
variant: "caption",
|
|
222
|
-
color: "secondary",
|
|
223
|
-
className: "font-mono text-[11px]",
|
|
224
|
-
children: [selectedKey.key_prefix, "•••"]
|
|
225
|
-
})]
|
|
226
|
-
})]
|
|
227
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
228
|
-
className: "flex items-center gap-2 shrink-0",
|
|
229
|
-
children: !selectedKey.revoked_at && /* @__PURE__ */ jsx(Button, {
|
|
230
|
-
size: "small",
|
|
231
|
-
color: "error",
|
|
232
|
-
variant: "outlined",
|
|
233
|
-
onClick: () => setConfirmRevoke(selectedKey),
|
|
234
|
-
disabled: revoking === selectedKey.id,
|
|
235
|
-
startIcon: revoking === selectedKey.id ? /* @__PURE__ */ jsx(CircularProgress, { size: "smallest" }) : /* @__PURE__ */ jsx(Trash2Icon, { size: iconSize.smallest }),
|
|
236
|
-
children: "Revoke"
|
|
237
|
-
})
|
|
238
|
-
})]
|
|
239
|
-
}),
|
|
240
|
-
/* @__PURE__ */ jsxs("div", {
|
|
241
|
-
className: "px-5 py-4 bg-surface-50 dark:bg-surface-900/50",
|
|
242
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
243
|
-
className: "grid grid-cols-2 md:grid-cols-4 gap-3",
|
|
244
|
-
children: [
|
|
245
|
-
/* @__PURE__ */ jsx(StatCard, {
|
|
246
|
-
label: "Status",
|
|
247
|
-
value: keyStatus(selectedKey).label,
|
|
248
|
-
className: keyStatus(selectedKey).color
|
|
249
|
-
}),
|
|
250
|
-
/* @__PURE__ */ jsx(StatCard, {
|
|
251
|
-
label: "Created",
|
|
252
|
-
value: formatRelative(selectedKey.created_at)
|
|
253
|
-
}),
|
|
254
|
-
/* @__PURE__ */ jsx(StatCard, {
|
|
255
|
-
label: "Last Used",
|
|
256
|
-
value: formatRelative(selectedKey.last_used_at)
|
|
257
|
-
}),
|
|
258
|
-
/* @__PURE__ */ jsx(StatCard, {
|
|
259
|
-
label: "Expires",
|
|
260
|
-
value: selectedKey.expires_at ? formatRelative(selectedKey.expires_at) : "Never"
|
|
261
|
-
})
|
|
262
|
-
]
|
|
263
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
264
|
-
className: "grid grid-cols-2 gap-3 mt-3",
|
|
265
|
-
children: [/* @__PURE__ */ jsx(StatCard, {
|
|
266
|
-
label: "Rate Limit",
|
|
267
|
-
value: selectedKey.rate_limit ? `${selectedKey.rate_limit}/15min` : "Default (1000/15min)"
|
|
268
|
-
}), /* @__PURE__ */ jsx(StatCard, {
|
|
269
|
-
label: "Created By",
|
|
270
|
-
value: selectedKey.created_by,
|
|
271
|
-
mono: true
|
|
272
|
-
})]
|
|
273
|
-
})]
|
|
274
|
-
}),
|
|
275
|
-
/* @__PURE__ */ jsxs("div", {
|
|
276
|
-
className: cls("flex items-center gap-2 px-5 py-2 border-y bg-white dark:bg-surface-950", defaultBorderMixin),
|
|
277
|
-
children: [/* @__PURE__ */ jsx(Typography, {
|
|
278
|
-
variant: "subtitle2",
|
|
279
|
-
className: "font-semibold text-[13px]",
|
|
280
|
-
children: "Permissions"
|
|
281
|
-
}), /* @__PURE__ */ jsx(Chip, {
|
|
282
|
-
size: "smallest",
|
|
283
|
-
className: "bg-surface-200 dark:bg-surface-700 text-surface-600 dark:text-surface-300",
|
|
284
|
-
children: selectedKey.permissions.length
|
|
285
|
-
})]
|
|
286
|
-
}),
|
|
287
|
-
/* @__PURE__ */ jsx("div", {
|
|
288
|
-
className: "flex-1 overflow-y-auto px-5 py-3",
|
|
289
|
-
children: selectedKey.permissions.length === 0 ? /* @__PURE__ */ jsx(Typography, {
|
|
290
|
-
variant: "body2",
|
|
291
|
-
color: "disabled",
|
|
292
|
-
children: "No permissions configured"
|
|
293
|
-
}) : /* @__PURE__ */ jsx("div", {
|
|
294
|
-
className: "space-y-2",
|
|
295
|
-
children: selectedKey.permissions.map((perm, idx) => /* @__PURE__ */ jsxs("div", {
|
|
296
|
-
className: cls("flex items-center gap-3 px-3 py-2 rounded-lg border", defaultBorderMixin),
|
|
297
|
-
children: [/* @__PURE__ */ jsx(Typography, {
|
|
298
|
-
variant: "body2",
|
|
299
|
-
className: "font-mono text-[13px] font-medium flex-1",
|
|
300
|
-
children: perm.collection === "*" ? "* (all collections)" : perm.collection
|
|
301
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
302
|
-
className: "flex items-center gap-1",
|
|
303
|
-
children: perm.operations.map((op) => /* @__PURE__ */ jsx(Chip, {
|
|
304
|
-
size: "smallest",
|
|
305
|
-
className: cls(op === "read" && "bg-emerald-100 dark:bg-emerald-900/30 text-emerald-700 dark:text-emerald-300", op === "write" && "bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300", op === "delete" && "bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300"),
|
|
306
|
-
children: op
|
|
307
|
-
}, op))
|
|
308
|
-
})]
|
|
309
|
-
}, idx))
|
|
310
|
-
})
|
|
311
|
-
})
|
|
312
|
-
] })
|
|
313
|
-
})]
|
|
314
|
-
}),
|
|
315
|
-
/* @__PURE__ */ jsxs(Dialog, {
|
|
316
|
-
open: confirmRevoke !== null,
|
|
317
|
-
onOpenChange: (open) => {
|
|
318
|
-
if (!open && !revoking) setConfirmRevoke(null);
|
|
319
|
-
},
|
|
320
|
-
children: [
|
|
321
|
-
/* @__PURE__ */ jsx(DialogTitle, {
|
|
322
|
-
hidden: true,
|
|
323
|
-
children: "Revoke Confirmation"
|
|
324
|
-
}),
|
|
325
|
-
/* @__PURE__ */ jsxs(DialogContent, { children: [/* @__PURE__ */ jsxs(Typography, {
|
|
326
|
-
variant: "subtitle1",
|
|
327
|
-
className: "font-semibold mb-2",
|
|
328
|
-
children: [
|
|
329
|
-
"Revoke \"",
|
|
330
|
-
confirmRevoke?.name,
|
|
331
|
-
"\"?"
|
|
332
|
-
]
|
|
333
|
-
}), /* @__PURE__ */ jsx(Typography, {
|
|
334
|
-
variant: "body2",
|
|
335
|
-
color: "secondary",
|
|
336
|
-
children: "Requests authenticated with this key will stop working immediately. This action cannot be undone."
|
|
337
|
-
})] }),
|
|
338
|
-
/* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
|
|
339
|
-
variant: "text",
|
|
340
|
-
onClick: () => setConfirmRevoke(null),
|
|
341
|
-
disabled: revoking !== null,
|
|
342
|
-
children: "Cancel"
|
|
343
|
-
}), /* @__PURE__ */ jsx(Button, {
|
|
344
|
-
color: "error",
|
|
345
|
-
disabled: revoking !== null,
|
|
346
|
-
startIcon: revoking !== null ? /* @__PURE__ */ jsx(CircularProgress, { size: "smallest" }) : /* @__PURE__ */ jsx(Trash2Icon, { size: iconSize.smallest }),
|
|
347
|
-
onClick: async () => {
|
|
348
|
-
if (!confirmRevoke) return;
|
|
349
|
-
await handleRevoke(confirmRevoke.id);
|
|
350
|
-
setConfirmRevoke(null);
|
|
351
|
-
},
|
|
352
|
-
children: "Revoke"
|
|
353
|
-
})] })
|
|
354
|
-
]
|
|
355
|
-
}),
|
|
356
|
-
showCreate && /* @__PURE__ */ jsx(CreateApiKeyDialog, {
|
|
357
|
-
onClose: () => setShowCreate(false),
|
|
358
|
-
onCreated: handleCreated
|
|
359
|
-
}),
|
|
360
|
-
showSecret && /* @__PURE__ */ jsx(SecretDisplayDialog, {
|
|
361
|
-
keyWithSecret: showSecret,
|
|
362
|
-
onClose: () => setShowSecret(null)
|
|
363
|
-
})
|
|
364
|
-
] });
|
|
365
|
-
}
|
|
366
|
-
function KeyListItem({ apiKey, selected, onClick }) {
|
|
367
|
-
const status = keyStatus(apiKey);
|
|
368
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
369
|
-
onClick,
|
|
370
|
-
className: cls("flex items-center gap-3 px-3 py-2.5 rounded-lg cursor-pointer transition-all", selected ? "bg-primary/10 dark:bg-primary/15 ring-1 ring-primary/30" : "hover:bg-surface-100 dark:hover:bg-surface-950"),
|
|
371
|
-
children: [
|
|
372
|
-
/* @__PURE__ */ jsx("div", { className: cls("w-2 h-2 rounded-full shrink-0", status.label === "Active" ? "bg-emerald-400" : status.label === "Expired" ? "bg-amber-400" : "bg-red-400") }),
|
|
373
|
-
/* @__PURE__ */ jsxs("div", {
|
|
374
|
-
className: "flex-1 min-w-0",
|
|
375
|
-
children: [/* @__PURE__ */ jsx(Typography, {
|
|
376
|
-
variant: "body2",
|
|
377
|
-
className: "truncate font-medium text-[13px]",
|
|
378
|
-
children: apiKey.name
|
|
379
|
-
}), /* @__PURE__ */ jsxs(Typography, {
|
|
380
|
-
variant: "caption",
|
|
381
|
-
color: "secondary",
|
|
382
|
-
className: "truncate text-[11px] font-mono",
|
|
383
|
-
children: [apiKey.key_prefix, "•••"]
|
|
384
|
-
})]
|
|
385
|
-
}),
|
|
386
|
-
/* @__PURE__ */ jsx("div", {
|
|
387
|
-
className: "shrink-0",
|
|
388
|
-
children: /* @__PURE__ */ jsx(Typography, {
|
|
389
|
-
variant: "caption",
|
|
390
|
-
color: "disabled",
|
|
391
|
-
className: "text-[10px]",
|
|
392
|
-
children: permissionSummary(apiKey.permissions)
|
|
393
|
-
})
|
|
394
|
-
})
|
|
395
|
-
]
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
function StatCard({ label, value, mono, className }) {
|
|
399
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
400
|
-
className: cls("px-3 py-2 rounded-lg border bg-white dark:bg-surface-900", defaultBorderMixin),
|
|
401
|
-
children: [/* @__PURE__ */ jsx(Typography, {
|
|
402
|
-
variant: "caption",
|
|
403
|
-
color: "secondary",
|
|
404
|
-
className: "text-[10px] uppercase tracking-wider font-medium",
|
|
405
|
-
children: label
|
|
406
|
-
}), /* @__PURE__ */ jsx(Typography, {
|
|
407
|
-
variant: "body2",
|
|
408
|
-
className: cls("mt-0.5 font-semibold text-[13px]", mono && "font-mono", className),
|
|
409
|
-
children: value
|
|
410
|
-
})]
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
function CreateApiKeyDialog({ onClose, onCreated }) {
|
|
414
|
-
const client = useRebaseClient();
|
|
415
|
-
const snackbar = useSnackbarController();
|
|
416
|
-
const [name, setName] = useState("");
|
|
417
|
-
const [permissions, setPermissions] = useState([{
|
|
418
|
-
collection: "*",
|
|
419
|
-
read: true,
|
|
420
|
-
write: false,
|
|
421
|
-
delete: false
|
|
422
|
-
}]);
|
|
423
|
-
const [rateLimit, setRateLimit] = useState("");
|
|
424
|
-
const [expiresIn, setExpiresIn] = useState("never");
|
|
425
|
-
const [creating, setCreating] = useState(false);
|
|
426
|
-
const addRow = () => setPermissions([...permissions, {
|
|
427
|
-
collection: "",
|
|
428
|
-
read: true,
|
|
429
|
-
write: false,
|
|
430
|
-
delete: false
|
|
431
|
-
}]);
|
|
432
|
-
const removeRow = (idx) => setPermissions(permissions.filter((_, i) => i !== idx));
|
|
433
|
-
const updateRow = (idx, field, value) => {
|
|
434
|
-
setPermissions(permissions.map((row, i) => i === idx ? {
|
|
435
|
-
...row,
|
|
436
|
-
[field]: value
|
|
437
|
-
} : row));
|
|
438
|
-
};
|
|
439
|
-
const handleCreate = async () => {
|
|
440
|
-
if (!client?.apiKeys || !name.trim()) return;
|
|
441
|
-
const apiPerms = permissions.filter((r) => r.collection.trim()).map((r) => ({
|
|
442
|
-
collection: r.collection.trim(),
|
|
443
|
-
operations: [
|
|
444
|
-
...r.read ? ["read"] : [],
|
|
445
|
-
...r.write ? ["write"] : [],
|
|
446
|
-
...r.delete ? ["delete"] : []
|
|
447
|
-
]
|
|
448
|
-
})).filter((p) => p.operations.length > 0);
|
|
449
|
-
if (apiPerms.length === 0) {
|
|
450
|
-
snackbar.open({
|
|
451
|
-
type: "error",
|
|
452
|
-
message: "At least one permission is required"
|
|
453
|
-
});
|
|
454
|
-
return;
|
|
455
|
-
}
|
|
456
|
-
let expires_at = null;
|
|
457
|
-
if (expiresIn === "7d") expires_at = new Date(Date.now() + 7 * 864e5).toISOString();
|
|
458
|
-
else if (expiresIn === "30d") expires_at = new Date(Date.now() + 30 * 864e5).toISOString();
|
|
459
|
-
else if (expiresIn === "90d") expires_at = new Date(Date.now() + 90 * 864e5).toISOString();
|
|
460
|
-
else if (expiresIn === "1y") expires_at = new Date(Date.now() + 365 * 864e5).toISOString();
|
|
461
|
-
setCreating(true);
|
|
462
|
-
try {
|
|
463
|
-
onCreated((await client.apiKeys.createKey({
|
|
464
|
-
name: name.trim(),
|
|
465
|
-
permissions: apiPerms,
|
|
466
|
-
rate_limit: rateLimit ? parseInt(rateLimit, 10) : null,
|
|
467
|
-
expires_at
|
|
468
|
-
})).key);
|
|
469
|
-
} catch (e) {
|
|
470
|
-
snackbar.open({
|
|
471
|
-
type: "error",
|
|
472
|
-
message: e instanceof Error ? e.message : String(e)
|
|
473
|
-
});
|
|
474
|
-
} finally {
|
|
475
|
-
setCreating(false);
|
|
476
|
-
}
|
|
477
|
-
};
|
|
478
|
-
return /* @__PURE__ */ jsxs(Dialog, {
|
|
479
|
-
open: true,
|
|
480
|
-
onOpenChange: (open) => {
|
|
481
|
-
if (!open) onClose();
|
|
482
|
-
},
|
|
483
|
-
maxWidth: "lg",
|
|
484
|
-
children: [
|
|
485
|
-
/* @__PURE__ */ jsx(DialogTitle, { children: "Create API Key" }),
|
|
486
|
-
/* @__PURE__ */ jsxs(DialogContent, {
|
|
487
|
-
className: "space-y-4",
|
|
488
|
-
children: [
|
|
489
|
-
/* @__PURE__ */ jsx(TextField, {
|
|
490
|
-
label: "Name",
|
|
491
|
-
value: name,
|
|
492
|
-
onChange: (e) => setName(e.target.value),
|
|
493
|
-
placeholder: "e.g. Analytics Pipeline",
|
|
494
|
-
size: "small",
|
|
495
|
-
autoFocus: true
|
|
496
|
-
}),
|
|
497
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
498
|
-
/* @__PURE__ */ jsx(Typography, {
|
|
499
|
-
variant: "caption",
|
|
500
|
-
color: "secondary",
|
|
501
|
-
className: "text-[11px] uppercase tracking-wider font-medium mb-2 block",
|
|
502
|
-
children: "Permissions"
|
|
503
|
-
}),
|
|
504
|
-
/* @__PURE__ */ jsx("div", {
|
|
505
|
-
className: "space-y-2",
|
|
506
|
-
children: permissions.map((row, idx) => /* @__PURE__ */ jsxs("div", {
|
|
507
|
-
className: cls("flex items-center gap-2 p-2 rounded-lg border", defaultBorderMixin),
|
|
508
|
-
children: [
|
|
509
|
-
/* @__PURE__ */ jsx(TextField, {
|
|
510
|
-
size: "small",
|
|
511
|
-
"aria-label": `Permission ${idx + 1} collection`,
|
|
512
|
-
value: row.collection,
|
|
513
|
-
onChange: (e) => updateRow(idx, "collection", e.target.value),
|
|
514
|
-
placeholder: "Collection slug or *",
|
|
515
|
-
className: "flex-1"
|
|
516
|
-
}),
|
|
517
|
-
/* @__PURE__ */ jsxs("label", {
|
|
518
|
-
className: "flex items-center gap-1 text-xs cursor-pointer",
|
|
519
|
-
children: [/* @__PURE__ */ jsx(Checkbox, {
|
|
520
|
-
size: "small",
|
|
521
|
-
checked: row.read,
|
|
522
|
-
onCheckedChange: (v) => updateRow(idx, "read", !!v)
|
|
523
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
524
|
-
className: "text-emerald-600 dark:text-emerald-400",
|
|
525
|
-
children: "read"
|
|
526
|
-
})]
|
|
527
|
-
}),
|
|
528
|
-
/* @__PURE__ */ jsxs("label", {
|
|
529
|
-
className: "flex items-center gap-1 text-xs cursor-pointer",
|
|
530
|
-
children: [/* @__PURE__ */ jsx(Checkbox, {
|
|
531
|
-
size: "small",
|
|
532
|
-
checked: row.write,
|
|
533
|
-
onCheckedChange: (v) => updateRow(idx, "write", !!v)
|
|
534
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
535
|
-
className: "text-blue-600 dark:text-blue-400",
|
|
536
|
-
children: "write"
|
|
537
|
-
})]
|
|
538
|
-
}),
|
|
539
|
-
/* @__PURE__ */ jsxs("label", {
|
|
540
|
-
className: "flex items-center gap-1 text-xs cursor-pointer",
|
|
541
|
-
children: [/* @__PURE__ */ jsx(Checkbox, {
|
|
542
|
-
size: "small",
|
|
543
|
-
checked: row.delete,
|
|
544
|
-
onCheckedChange: (v) => updateRow(idx, "delete", !!v)
|
|
545
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
546
|
-
className: "text-red-600 dark:text-red-400",
|
|
547
|
-
children: "delete"
|
|
548
|
-
})]
|
|
549
|
-
}),
|
|
550
|
-
permissions.length > 1 && /* @__PURE__ */ jsx(IconButton, {
|
|
551
|
-
size: "small",
|
|
552
|
-
onClick: () => removeRow(idx),
|
|
553
|
-
children: /* @__PURE__ */ jsx(Trash2Icon, { size: iconSize.smallest })
|
|
554
|
-
})
|
|
555
|
-
]
|
|
556
|
-
}, idx))
|
|
557
|
-
}),
|
|
558
|
-
/* @__PURE__ */ jsx(Button, {
|
|
559
|
-
size: "small",
|
|
560
|
-
variant: "text",
|
|
561
|
-
onClick: addRow,
|
|
562
|
-
className: "mt-1",
|
|
563
|
-
startIcon: /* @__PURE__ */ jsx(PlusIcon, { size: iconSize.smallest }),
|
|
564
|
-
children: "Add collection"
|
|
565
|
-
})
|
|
566
|
-
] }),
|
|
567
|
-
/* @__PURE__ */ jsxs("div", {
|
|
568
|
-
className: "flex gap-4",
|
|
569
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
570
|
-
className: "flex-1",
|
|
571
|
-
children: /* @__PURE__ */ jsxs(Select, {
|
|
572
|
-
label: "Expires",
|
|
573
|
-
value: expiresIn,
|
|
574
|
-
onValueChange: setExpiresIn,
|
|
575
|
-
size: "small",
|
|
576
|
-
renderValue: (v) => v === "never" ? "Never" : v === "7d" ? "7 days" : v === "30d" ? "30 days" : v === "90d" ? "90 days" : "1 year",
|
|
577
|
-
children: [
|
|
578
|
-
/* @__PURE__ */ jsx(SelectItem, {
|
|
579
|
-
value: "never",
|
|
580
|
-
children: "Never"
|
|
581
|
-
}),
|
|
582
|
-
/* @__PURE__ */ jsx(SelectItem, {
|
|
583
|
-
value: "7d",
|
|
584
|
-
children: "7 days"
|
|
585
|
-
}),
|
|
586
|
-
/* @__PURE__ */ jsx(SelectItem, {
|
|
587
|
-
value: "30d",
|
|
588
|
-
children: "30 days"
|
|
589
|
-
}),
|
|
590
|
-
/* @__PURE__ */ jsx(SelectItem, {
|
|
591
|
-
value: "90d",
|
|
592
|
-
children: "90 days"
|
|
593
|
-
}),
|
|
594
|
-
/* @__PURE__ */ jsx(SelectItem, {
|
|
595
|
-
value: "1y",
|
|
596
|
-
children: "1 year"
|
|
597
|
-
})
|
|
598
|
-
]
|
|
599
|
-
})
|
|
600
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
601
|
-
className: "flex-1",
|
|
602
|
-
children: /* @__PURE__ */ jsx(TextField, {
|
|
603
|
-
label: "Rate Limit (per 15 min)",
|
|
604
|
-
value: rateLimit,
|
|
605
|
-
onChange: (e) => setRateLimit(e.target.value.replace(/\D/g, "")),
|
|
606
|
-
placeholder: "Default: 1000",
|
|
607
|
-
size: "small"
|
|
608
|
-
})
|
|
609
|
-
})]
|
|
610
|
-
})
|
|
611
|
-
]
|
|
612
|
-
}),
|
|
613
|
-
/* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
|
|
614
|
-
variant: "text",
|
|
615
|
-
onClick: onClose,
|
|
616
|
-
children: "Cancel"
|
|
617
|
-
}), /* @__PURE__ */ jsx(Button, {
|
|
618
|
-
color: "primary",
|
|
619
|
-
onClick: handleCreate,
|
|
620
|
-
disabled: creating || !name.trim(),
|
|
621
|
-
startIcon: creating ? /* @__PURE__ */ jsx(CircularProgress, { size: "smallest" }) : void 0,
|
|
622
|
-
children: "Create Key"
|
|
623
|
-
})] })
|
|
624
|
-
]
|
|
625
|
-
});
|
|
626
|
-
}
|
|
627
|
-
function SecretDisplayDialog({ keyWithSecret, onClose }) {
|
|
628
|
-
const snackbar = useSnackbarController();
|
|
629
|
-
const [copied, setCopied] = useState(false);
|
|
630
|
-
const handleCopy = async () => {
|
|
631
|
-
try {
|
|
632
|
-
await navigator.clipboard.writeText(keyWithSecret.key);
|
|
633
|
-
setCopied(true);
|
|
634
|
-
snackbar.open({
|
|
635
|
-
type: "success",
|
|
636
|
-
message: "API key copied to clipboard"
|
|
637
|
-
});
|
|
638
|
-
setTimeout(() => setCopied(false), 2e3);
|
|
639
|
-
} catch {
|
|
640
|
-
snackbar.open({
|
|
641
|
-
type: "error",
|
|
642
|
-
message: "Failed to copy"
|
|
643
|
-
});
|
|
644
|
-
}
|
|
645
|
-
};
|
|
646
|
-
return /* @__PURE__ */ jsxs(Dialog, {
|
|
647
|
-
open: true,
|
|
648
|
-
onOpenChange: (open) => {
|
|
649
|
-
if (!open) onClose();
|
|
650
|
-
},
|
|
651
|
-
maxWidth: "md",
|
|
652
|
-
children: [
|
|
653
|
-
/* @__PURE__ */ jsx(DialogTitle, { children: /* @__PURE__ */ jsxs("div", {
|
|
654
|
-
className: "flex items-center gap-2",
|
|
655
|
-
children: [/* @__PURE__ */ jsx(CheckCircleIcon, {
|
|
656
|
-
size: iconSize.small,
|
|
657
|
-
className: "text-emerald-500"
|
|
658
|
-
}), "API Key Created"]
|
|
659
|
-
}) }),
|
|
660
|
-
/* @__PURE__ */ jsxs(DialogContent, { children: [
|
|
661
|
-
/* @__PURE__ */ jsxs("div", {
|
|
662
|
-
className: "p-3 rounded-lg bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800/50 mb-4",
|
|
663
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
664
|
-
className: "flex items-center gap-2 mb-1",
|
|
665
|
-
children: [/* @__PURE__ */ jsx(AlertCircleIcon, {
|
|
666
|
-
size: iconSize.smallest,
|
|
667
|
-
className: "text-amber-600 dark:text-amber-400"
|
|
668
|
-
}), /* @__PURE__ */ jsx(Typography, {
|
|
669
|
-
variant: "caption",
|
|
670
|
-
className: "font-semibold text-amber-700 dark:text-amber-400",
|
|
671
|
-
children: "Copy your key now — it won't be shown again"
|
|
672
|
-
})]
|
|
673
|
-
}), /* @__PURE__ */ jsx(Typography, {
|
|
674
|
-
variant: "caption",
|
|
675
|
-
className: "text-amber-600 dark:text-amber-300",
|
|
676
|
-
children: "This is the only time the full API key will be displayed. Store it securely."
|
|
677
|
-
})]
|
|
678
|
-
}),
|
|
679
|
-
/* @__PURE__ */ jsxs("div", {
|
|
680
|
-
className: cls("flex items-center gap-2 p-3 rounded-lg border bg-surface-50 dark:bg-surface-900", defaultBorderMixin),
|
|
681
|
-
children: [/* @__PURE__ */ jsx("code", {
|
|
682
|
-
className: "flex-1 text-[12px] font-mono break-all text-surface-700 dark:text-surface-300 select-all",
|
|
683
|
-
children: keyWithSecret.key
|
|
684
|
-
}), /* @__PURE__ */ jsx(Tooltip, {
|
|
685
|
-
title: copied ? "Copied!" : "Copy",
|
|
686
|
-
children: /* @__PURE__ */ jsx(IconButton, {
|
|
687
|
-
size: "small",
|
|
688
|
-
onClick: handleCopy,
|
|
689
|
-
children: copied ? /* @__PURE__ */ jsx(CheckCircleIcon, {
|
|
690
|
-
size: iconSize.smallest,
|
|
691
|
-
className: "text-emerald-500"
|
|
692
|
-
}) : /* @__PURE__ */ jsx(CopyIcon, { size: iconSize.smallest })
|
|
693
|
-
})
|
|
694
|
-
})]
|
|
695
|
-
}),
|
|
696
|
-
/* @__PURE__ */ jsxs("div", {
|
|
697
|
-
className: "mt-4 space-y-1",
|
|
698
|
-
children: [/* @__PURE__ */ jsxs(Typography, {
|
|
699
|
-
variant: "caption",
|
|
700
|
-
color: "secondary",
|
|
701
|
-
children: [
|
|
702
|
-
/* @__PURE__ */ jsx("strong", { children: "Name:" }),
|
|
703
|
-
" ",
|
|
704
|
-
keyWithSecret.name
|
|
705
|
-
]
|
|
706
|
-
}), /* @__PURE__ */ jsxs(Typography, {
|
|
707
|
-
variant: "caption",
|
|
708
|
-
color: "secondary",
|
|
709
|
-
children: [
|
|
710
|
-
/* @__PURE__ */ jsx("strong", { children: "Permissions:" }),
|
|
711
|
-
" ",
|
|
712
|
-
permissionSummary(keyWithSecret.permissions)
|
|
713
|
-
]
|
|
714
|
-
})]
|
|
715
|
-
})
|
|
716
|
-
] }),
|
|
717
|
-
/* @__PURE__ */ jsx(DialogActions, { children: /* @__PURE__ */ jsx(Button, {
|
|
718
|
-
color: "primary",
|
|
719
|
-
onClick: onClose,
|
|
720
|
-
children: "Done"
|
|
721
|
-
}) })
|
|
722
|
-
]
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
//#endregion
|
|
726
|
-
export { ApiKeysView };
|
|
727
|
-
|
|
728
|
-
//# sourceMappingURL=ApiKeysView-C_UoUPuR.js.map
|