@rebasepro/studio 0.9.1-canary.a57c262 → 0.9.1-canary.a8dbf1c

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.
Files changed (31) hide show
  1. package/dist/{ApiKeysView-Dbe5cXkS.js → ApiKeysView-vQKqt2wl.js} +44 -2
  2. package/dist/ApiKeysView-vQKqt2wl.js.map +1 -0
  3. package/dist/LogsExplorer-BCXoGREr.js +298 -0
  4. package/dist/LogsExplorer-BCXoGREr.js.map +1 -0
  5. package/dist/{RLSEditor-DO_pFwLP.js → RLSEditor-rLlMcZPG.js} +14 -13
  6. package/dist/RLSEditor-rLlMcZPG.js.map +1 -0
  7. package/dist/SQLEditor-_dCqVAN_.js.map +1 -1
  8. package/dist/{SchemaVisualizer-D01DzU-f.js → SchemaVisualizer-C_ErehfH.js} +2 -2
  9. package/dist/{SchemaVisualizer-D01DzU-f.js.map → SchemaVisualizer-C_ErehfH.js.map} +1 -1
  10. package/dist/components/RLSEditor/PolicyEditor.d.ts +1 -1
  11. package/dist/components/SQLEditor/SQLEditor.d.ts +2 -10
  12. package/dist/components/SQLEditor/SQLEditorSidebar.d.ts +1 -1
  13. package/dist/components/SQLEditor/SchemaBrowser.d.ts +1 -1
  14. package/dist/components/SQLEditor/sql_editor_types.d.ts +16 -0
  15. package/dist/index.es.js +4 -4
  16. package/dist/utils/sql_utils.d.ts +1 -1
  17. package/package.json +10 -8
  18. package/src/components/ApiKeys/ApiKeysView.tsx +41 -1
  19. package/src/components/LogsExplorer/LogsExplorer.tsx +143 -45
  20. package/src/components/RLSEditor/PolicyEditor.tsx +15 -13
  21. package/src/components/SQLEditor/SQLEditor.tsx +3 -11
  22. package/src/components/SQLEditor/SQLEditorSidebar.tsx +1 -1
  23. package/src/components/SQLEditor/SchemaBrowser.tsx +1 -1
  24. package/src/components/SQLEditor/sql_editor_types.ts +18 -0
  25. package/src/components/SchemaVisualizer/SchemaVisualizer.tsx +2 -1
  26. package/src/utils/sql_utils.test.ts +1 -1
  27. package/src/utils/sql_utils.ts +1 -1
  28. package/dist/ApiKeysView-Dbe5cXkS.js.map +0 -1
  29. package/dist/LogsExplorer-Bi0bxDRx.js +0 -225
  30. package/dist/LogsExplorer-Bi0bxDRx.js.map +0 -1
  31. package/dist/RLSEditor-DO_pFwLP.js.map +0 -1
@@ -53,6 +53,7 @@ function ApiKeysView() {
53
53
  const [showCreate, setShowCreate] = useState(false);
54
54
  const [showSecret, setShowSecret] = useState(null);
55
55
  const [revoking, setRevoking] = useState(null);
56
+ const [confirmRevoke, setConfirmRevoke] = useState(null);
56
57
  const clientRef = useRef(client);
57
58
  clientRef.current = client;
58
59
  const snackbarRef = useRef(snackbar);
@@ -228,7 +229,7 @@ function ApiKeysView() {
228
229
  size: "small",
229
230
  color: "error",
230
231
  variant: "outlined",
231
- onClick: () => handleRevoke(selectedKey.id),
232
+ onClick: () => setConfirmRevoke(selectedKey),
232
233
  disabled: revoking === selectedKey.id,
233
234
  startIcon: revoking === selectedKey.id ? /* @__PURE__ */ jsx(CircularProgress, { size: "smallest" }) : /* @__PURE__ */ jsx(Trash2Icon, { size: iconSize.smallest }),
234
235
  children: "Revoke"
@@ -310,6 +311,47 @@ function ApiKeysView() {
310
311
  ] })
311
312
  })]
312
313
  }),
314
+ /* @__PURE__ */ jsxs(Dialog, {
315
+ open: confirmRevoke !== null,
316
+ onOpenChange: (open) => {
317
+ if (!open && !revoking) setConfirmRevoke(null);
318
+ },
319
+ children: [
320
+ /* @__PURE__ */ jsx(DialogTitle, {
321
+ hidden: true,
322
+ children: "Revoke Confirmation"
323
+ }),
324
+ /* @__PURE__ */ jsxs(DialogContent, { children: [/* @__PURE__ */ jsxs(Typography, {
325
+ variant: "subtitle1",
326
+ className: "font-semibold mb-2",
327
+ children: [
328
+ "Revoke \"",
329
+ confirmRevoke?.name,
330
+ "\"?"
331
+ ]
332
+ }), /* @__PURE__ */ jsx(Typography, {
333
+ variant: "body2",
334
+ color: "secondary",
335
+ children: "Requests authenticated with this key will stop working immediately. This action cannot be undone."
336
+ })] }),
337
+ /* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
338
+ variant: "text",
339
+ onClick: () => setConfirmRevoke(null),
340
+ disabled: revoking !== null,
341
+ children: "Cancel"
342
+ }), /* @__PURE__ */ jsx(Button, {
343
+ color: "error",
344
+ disabled: revoking !== null,
345
+ startIcon: revoking !== null ? /* @__PURE__ */ jsx(CircularProgress, { size: "smallest" }) : /* @__PURE__ */ jsx(Trash2Icon, { size: iconSize.smallest }),
346
+ onClick: async () => {
347
+ if (!confirmRevoke) return;
348
+ await handleRevoke(confirmRevoke.id);
349
+ setConfirmRevoke(null);
350
+ },
351
+ children: "Revoke"
352
+ })] })
353
+ ]
354
+ }),
313
355
  showCreate && /* @__PURE__ */ jsx(CreateApiKeyDialog, {
314
356
  onClose: () => setShowCreate(false),
315
357
  onCreated: handleCreated
@@ -681,4 +723,4 @@ function SecretDisplayDialog({ keyWithSecret, onClose }) {
681
723
  //#endregion
682
724
  export { ApiKeysView };
683
725
 
684
- //# sourceMappingURL=ApiKeysView-Dbe5cXkS.js.map
726
+ //# sourceMappingURL=ApiKeysView-vQKqt2wl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiKeysView-vQKqt2wl.js","names":[],"sources":["../src/components/ApiKeys/ApiKeysView.tsx"],"sourcesContent":["\nimport React, { useState, useEffect, useRef, useCallback } from \"react\";\nimport {\n Button,\n Card,\n Chip,\n CircularProgress,\n cls,\n defaultBorderMixin,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n IconButton,\n iconSize,\n KeyRoundIcon,\n RefreshCwIcon,\n Tooltip,\n Typography,\n TextField,\n Select,\n SelectItem,\n Checkbox,\n CopyIcon,\n PlusIcon as AddIcon,\n Trash2Icon as DeleteIcon,\n AlertCircleIcon,\n CheckCircleIcon\n} from \"@rebasepro/ui\";\nimport { useRebaseClient, useSnackbarController } from \"@rebasepro/app\";\nimport type { RebaseClient } from \"@rebasepro/types\";\n\n/* ═══════════════════════════════════════════════════════════════\n Types — mirrors server api-key-types.ts\n ═══════════════════════════════════════════════════════════════ */\n\ninterface ApiKeyPermission {\n collection: string;\n operations: (\"read\" | \"write\" | \"delete\")[];\n}\n\ninterface ApiKeyMasked {\n id: string;\n name: string;\n key_prefix: string;\n permissions: ApiKeyPermission[];\n rate_limit: number | null;\n created_by: string;\n created_at: string;\n updated_at: string;\n last_used_at: string | null;\n expires_at: string | null;\n revoked_at: string | null;\n}\n\ninterface ApiKeyWithSecret extends ApiKeyMasked {\n key: string;\n}\n\n/* ═══════════════════════════════════════════════════════════════\n Helpers\n ═══════════════════════════════════════════════════════════════ */\n\nfunction formatRelative(iso: string | null | undefined): string {\n if (!iso) return \"—\";\n const d = new Date(iso);\n const now = Date.now();\n const diff = d.getTime() - now;\n const abs = Math.abs(diff);\n if (abs < 60000) return diff > 0 ? \"in <1m\" : \"<1m ago\";\n if (abs < 3600000) { const m = Math.round(abs / 60000); return diff > 0 ? `in ${m}m` : `${m}m ago`; }\n if (abs < 86400000) { const h = Math.round(abs / 3600000); return diff > 0 ? `in ${h}h` : `${h}h ago`; }\n return d.toLocaleDateString();\n}\n\nfunction permissionSummary(perms: ApiKeyPermission[]): string {\n if (perms.length === 0) return \"No permissions\";\n const wildcard = perms.find(p => p.collection === \"*\");\n if (wildcard) {\n return `All collections (${wildcard.operations.join(\", \")})`;\n }\n if (perms.length === 1) {\n return `${perms[0].collection} (${perms[0].operations.join(\", \")})`;\n }\n return `${perms.length} collections`;\n}\n\nfunction isExpired(key: ApiKeyMasked): boolean {\n return !!(key.expires_at && new Date(key.expires_at) < new Date());\n}\n\nfunction keyStatus(key: ApiKeyMasked): { label: string; color: string } {\n if (key.revoked_at) return { label: \"Revoked\", color: \"text-red-500\" };\n if (isExpired(key)) return { label: \"Expired\", color: \"text-amber-500\" };\n return { label: \"Active\", color: \"text-emerald-500\" };\n}\n\n/* ═══════════════════════════════════════════════════════════════\n Main Component\n ═══════════════════════════════════════════════════════════════ */\n\nexport function ApiKeysView() {\n const client = useRebaseClient<RebaseClient>();\n const snackbar = useSnackbarController();\n const [keys, setKeys] = useState<ApiKeyMasked[]>([]);\n const [loading, setLoading] = useState(true);\n const [selectedId, setSelectedId] = useState<string | null>(null);\n const [showCreate, setShowCreate] = useState(false);\n const [showSecret, setShowSecret] = useState<ApiKeyWithSecret | null>(null);\n const [revoking, setRevoking] = useState<string | null>(null);\n const [confirmRevoke, setConfirmRevoke] = useState<ApiKeyMasked | null>(null);\n\n const clientRef = useRef(client);\n clientRef.current = client;\n const snackbarRef = useRef(snackbar);\n snackbarRef.current = snackbar;\n\n const loadKeys = useCallback(async () => {\n const c = clientRef.current;\n if (!c?.apiKeys) { setLoading(false); return; }\n try {\n const res = await c.apiKeys.listKeys();\n setKeys(res.keys);\n } catch (e: unknown) {\n snackbarRef.current.open({\n type: \"error\",\n message: e instanceof Error ? e.message : String(e)\n });\n } finally {\n setLoading(false);\n }\n }, []);\n\n useEffect(() => { loadKeys(); }, [loadKeys]);\n\n const handleRevoke = async (id: string) => {\n const c = clientRef.current;\n if (!c?.apiKeys) return;\n setRevoking(id);\n try {\n await c.apiKeys.revokeKey(id);\n snackbarRef.current.open({ type: \"success\", message: \"API key revoked\" });\n await loadKeys();\n if (selectedId === id) setSelectedId(null);\n } catch (e: unknown) {\n snackbarRef.current.open({ type: \"error\", message: e instanceof Error ? e.message : String(e) });\n } finally { setRevoking(null); }\n };\n\n const handleCreated = (keyWithSecret: ApiKeyWithSecret) => {\n setShowCreate(false);\n setShowSecret(keyWithSecret);\n loadKeys();\n };\n\n const selectedKey = keys.find(k => k.id === selectedId);\n const activeKeys = keys.filter(k => !k.revoked_at && !isExpired(k));\n const inactiveKeys = keys.filter(k => k.revoked_at || isExpired(k));\n\n if (loading) return <div className=\"flex items-center justify-center h-full\"><CircularProgress/></div>;\n\n return (\n <>\n <div className=\"flex h-full w-full overflow-hidden bg-white dark:bg-surface-950\">\n {/* ── Key List ── */}\n <div className={cls(\"flex flex-col w-[340px] min-w-[280px] border-r h-full\", defaultBorderMixin)}>\n <div 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)}>\n <div className=\"flex items-center gap-2\">\n <KeyRoundIcon size={iconSize.smallest} className=\"text-primary\"/>\n <Typography variant=\"subtitle2\" className=\"font-semibold\">API Keys</Typography>\n <Chip size=\"smallest\" className=\"bg-surface-200 dark:bg-surface-700 text-surface-600 dark:text-surface-300\">{activeKeys.length}</Chip>\n </div>\n <div className=\"flex items-center gap-1\">\n <IconButton size=\"small\" onClick={loadKeys} title=\"Refresh\"><RefreshCwIcon size={iconSize.smallest}/></IconButton>\n <Button size=\"small\" color=\"primary\" onClick={() => setShowCreate(true)} startIcon={<AddIcon size={iconSize.smallest}/>}>\n New\n </Button>\n </div>\n </div>\n <div className=\"flex-1 overflow-y-auto p-2 space-y-1\">\n {activeKeys.length === 0 && inactiveKeys.length === 0 && (\n <div className=\"flex flex-col items-center justify-center h-full gap-3 text-center p-6\">\n <KeyRoundIcon size={iconSize.medium} className=\"text-surface-300 dark:text-surface-600\"/>\n <Typography variant=\"body2\" color=\"secondary\">No API keys yet</Typography>\n <Typography variant=\"caption\" color=\"disabled\">Create a key to enable machine-to-machine authentication</Typography>\n </div>\n )}\n {activeKeys.map(key => (\n <KeyListItem key={key.id} apiKey={key} selected={selectedId === key.id} onClick={() => setSelectedId(key.id)}/>\n ))}\n {inactiveKeys.length > 0 && (\n <>\n <div className=\"px-2 pt-3 pb-1\">\n <Typography variant=\"caption\" color=\"disabled\" className=\"text-[10px] uppercase tracking-wider font-medium\">Revoked / Expired</Typography>\n </div>\n {inactiveKeys.map(key => (\n <KeyListItem key={key.id} apiKey={key} selected={selectedId === key.id} onClick={() => setSelectedId(key.id)}/>\n ))}\n </>\n )}\n </div>\n </div>\n\n {/* ── Detail Panel ── */}\n <div className=\"flex-1 flex flex-col min-w-0 h-full overflow-hidden\">\n {!selectedKey ? (\n <div className=\"flex items-center justify-center h-full\">\n <Typography variant=\"body2\" color=\"disabled\">Select an API key to view details</Typography>\n </div>\n ) : (\n <>\n {/* Header */}\n <div className={cls(\"flex items-center justify-between px-5 py-3 border-b bg-white dark:bg-surface-950 min-h-[56px]\", defaultBorderMixin)}>\n <div className=\"flex items-center gap-3 min-w-0\">\n <KeyRoundIcon size={iconSize.small} className=\"text-primary shrink-0\"/>\n <div className=\"min-w-0\">\n <Typography variant=\"subtitle1\" className=\"font-semibold truncate\">{selectedKey.name}</Typography>\n <Typography variant=\"caption\" color=\"secondary\" className=\"font-mono text-[11px]\">{selectedKey.key_prefix}•••</Typography>\n </div>\n </div>\n <div className=\"flex items-center gap-2 shrink-0\">\n {!selectedKey.revoked_at && (\n <Button\n size=\"small\"\n color=\"error\"\n variant=\"outlined\"\n onClick={() => setConfirmRevoke(selectedKey)}\n disabled={revoking === selectedKey.id}\n startIcon={revoking === selectedKey.id ? <CircularProgress size=\"smallest\"/> : <DeleteIcon size={iconSize.smallest}/>}\n >\n Revoke\n </Button>\n )}\n </div>\n </div>\n\n {/* Stats */}\n <div className=\"px-5 py-4 bg-surface-50 dark:bg-surface-900/50\">\n <div className=\"grid grid-cols-2 md:grid-cols-4 gap-3\">\n <StatCard label=\"Status\" value={keyStatus(selectedKey).label} className={keyStatus(selectedKey).color}/>\n <StatCard label=\"Created\" value={formatRelative(selectedKey.created_at)}/>\n <StatCard label=\"Last Used\" value={formatRelative(selectedKey.last_used_at)}/>\n <StatCard label=\"Expires\" value={selectedKey.expires_at ? formatRelative(selectedKey.expires_at) : \"Never\"}/>\n </div>\n <div className=\"grid grid-cols-2 gap-3 mt-3\">\n <StatCard label=\"Rate Limit\" value={selectedKey.rate_limit ? `${selectedKey.rate_limit}/15min` : \"Default (1000/15min)\"}/>\n <StatCard label=\"Created By\" value={selectedKey.created_by} mono/>\n </div>\n </div>\n\n {/* Permissions */}\n <div className={cls(\"flex items-center gap-2 px-5 py-2 border-y bg-white dark:bg-surface-950\", defaultBorderMixin)}>\n <Typography variant=\"subtitle2\" className=\"font-semibold text-[13px]\">Permissions</Typography>\n <Chip size=\"smallest\" className=\"bg-surface-200 dark:bg-surface-700 text-surface-600 dark:text-surface-300\">\n {selectedKey.permissions.length}\n </Chip>\n </div>\n <div className=\"flex-1 overflow-y-auto px-5 py-3\">\n {selectedKey.permissions.length === 0 ? (\n <Typography variant=\"body2\" color=\"disabled\">No permissions configured</Typography>\n ) : (\n <div className=\"space-y-2\">\n {selectedKey.permissions.map((perm, idx) => (\n <div key={idx} className={cls(\"flex items-center gap-3 px-3 py-2 rounded-lg border\", defaultBorderMixin)}>\n <Typography variant=\"body2\" className=\"font-mono text-[13px] font-medium flex-1\">\n {perm.collection === \"*\" ? \"* (all collections)\" : perm.collection}\n </Typography>\n <div className=\"flex items-center gap-1\">\n {perm.operations.map(op => (\n <Chip key={op} size=\"smallest\" className={cls(\n op === \"read\" && \"bg-emerald-100 dark:bg-emerald-900/30 text-emerald-700 dark:text-emerald-300\",\n op === \"write\" && \"bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300\",\n op === \"delete\" && \"bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300\"\n )}>{op}</Chip>\n ))}\n </div>\n </div>\n ))}\n </div>\n )}\n </div>\n </>\n )}\n </div>\n </div>\n\n {/* Revoke Confirmation Dialog */}\n <Dialog\n open={confirmRevoke !== null}\n onOpenChange={(open) => {\n if (!open && !revoking) setConfirmRevoke(null);\n }}\n >\n <DialogTitle hidden>Revoke Confirmation</DialogTitle>\n <DialogContent>\n <Typography variant=\"subtitle1\" className=\"font-semibold mb-2\">\n Revoke &quot;{confirmRevoke?.name}&quot;?\n </Typography>\n <Typography variant=\"body2\" color=\"secondary\">\n Requests authenticated with this key will stop working immediately. This action cannot be undone.\n </Typography>\n </DialogContent>\n <DialogActions>\n <Button\n variant=\"text\"\n onClick={() => setConfirmRevoke(null)}\n disabled={revoking !== null}\n >\n Cancel\n </Button>\n <Button\n color=\"error\"\n disabled={revoking !== null}\n startIcon={revoking !== null ? <CircularProgress size=\"smallest\"/> : <DeleteIcon size={iconSize.smallest}/>}\n onClick={async () => {\n if (!confirmRevoke) return;\n await handleRevoke(confirmRevoke.id);\n setConfirmRevoke(null);\n }}\n >\n Revoke\n </Button>\n </DialogActions>\n </Dialog>\n\n {/* Create Dialog */}\n {showCreate && (\n <CreateApiKeyDialog\n onClose={() => setShowCreate(false)}\n onCreated={handleCreated}\n />\n )}\n\n {/* Secret Display Dialog */}\n {showSecret && (\n <SecretDisplayDialog\n keyWithSecret={showSecret}\n onClose={() => setShowSecret(null)}\n />\n )}\n </>\n );\n}\n\n/* ═══════════════════════════════════════════════════════════════\n List item\n ═══════════════════════════════════════════════════════════════ */\n\nfunction KeyListItem({ apiKey, selected, onClick }: { apiKey: ApiKeyMasked; selected: boolean; onClick: () => void }) {\n const status = keyStatus(apiKey);\n return (\n <div\n onClick={onClick}\n className={cls(\n \"flex items-center gap-3 px-3 py-2.5 rounded-lg cursor-pointer transition-all\",\n selected\n ? \"bg-primary/10 dark:bg-primary/15 ring-1 ring-primary/30\"\n : \"hover:bg-surface-100 dark:hover:bg-surface-950\"\n )}\n >\n <div className={cls(\"w-2 h-2 rounded-full shrink-0\",\n status.label === \"Active\" ? \"bg-emerald-400\" :\n status.label === \"Expired\" ? \"bg-amber-400\" : \"bg-red-400\"\n )}/>\n <div className=\"flex-1 min-w-0\">\n <Typography variant=\"body2\" className=\"truncate font-medium text-[13px]\">{apiKey.name}</Typography>\n <Typography variant=\"caption\" color=\"secondary\" className=\"truncate text-[11px] font-mono\">{apiKey.key_prefix}•••</Typography>\n </div>\n <div className=\"shrink-0\">\n <Typography variant=\"caption\" color=\"disabled\" className=\"text-[10px]\">{permissionSummary(apiKey.permissions)}</Typography>\n </div>\n </div>\n );\n}\n\n/* ═══════════════════════════════════════════════════════════════\n Stat card\n ═══════════════════════════════════════════════════════════════ */\n\nfunction StatCard({ label, value, mono, className }: { label: string; value: string; mono?: boolean; className?: string }) {\n return (\n <div className={cls(\"px-3 py-2 rounded-lg border bg-white dark:bg-surface-900\", defaultBorderMixin)}>\n <Typography variant=\"caption\" color=\"secondary\" className=\"text-[10px] uppercase tracking-wider font-medium\">{label}</Typography>\n <Typography variant=\"body2\" className={cls(\n \"mt-0.5 font-semibold text-[13px]\",\n mono && \"font-mono\",\n className\n )}>{value}</Typography>\n </div>\n );\n}\n\n/* ═══════════════════════════════════════════════════════════════\n Create API Key Dialog\n ═══════════════════════════════════════════════════════════════ */\n\ninterface PermissionRow {\n collection: string;\n read: boolean;\n write: boolean;\n delete: boolean;\n}\n\nfunction CreateApiKeyDialog({ onClose, onCreated }: { onClose: () => void; onCreated: (key: ApiKeyWithSecret) => void }) {\n const client = useRebaseClient<RebaseClient>();\n const snackbar = useSnackbarController();\n const [name, setName] = useState(\"\");\n const [permissions, setPermissions] = useState<PermissionRow[]>([{ collection: \"*\", read: true, write: false, delete: false }]);\n const [rateLimit, setRateLimit] = useState(\"\");\n const [expiresIn, setExpiresIn] = useState(\"never\");\n const [creating, setCreating] = useState(false);\n\n const addRow = () => setPermissions([...permissions, { collection: \"\", read: true, write: false, delete: false }]);\n const removeRow = (idx: number) => setPermissions(permissions.filter((_, i) => i !== idx));\n\n const updateRow = (idx: number, field: keyof PermissionRow, value: string | boolean) => {\n setPermissions(permissions.map((row, i) => i === idx ? { ...row, [field]: value } : row));\n };\n\n const handleCreate = async () => {\n if (!client?.apiKeys || !name.trim()) return;\n const apiPerms: ApiKeyPermission[] = permissions\n .filter(r => r.collection.trim())\n .map(r => ({\n collection: r.collection.trim(),\n operations: [\n ...(r.read ? [\"read\" as const] : []),\n ...(r.write ? [\"write\" as const] : []),\n ...(r.delete ? [\"delete\" as const] : [])\n ]\n }))\n .filter(p => p.operations.length > 0);\n\n if (apiPerms.length === 0) {\n snackbar.open({ type: \"error\", message: \"At least one permission is required\" });\n return;\n }\n\n let expires_at: string | null = null;\n if (expiresIn === \"7d\") expires_at = new Date(Date.now() + 7 * 86400000).toISOString();\n else if (expiresIn === \"30d\") expires_at = new Date(Date.now() + 30 * 86400000).toISOString();\n else if (expiresIn === \"90d\") expires_at = new Date(Date.now() + 90 * 86400000).toISOString();\n else if (expiresIn === \"1y\") expires_at = new Date(Date.now() + 365 * 86400000).toISOString();\n\n setCreating(true);\n try {\n const res = await client.apiKeys.createKey({\n name: name.trim(),\n permissions: apiPerms,\n rate_limit: rateLimit ? parseInt(rateLimit, 10) : null,\n expires_at\n });\n onCreated(res.key);\n } catch (e: unknown) {\n snackbar.open({ type: \"error\", message: e instanceof Error ? e.message : String(e) });\n } finally { setCreating(false); }\n };\n\n return (\n <Dialog open onOpenChange={(open) => { if (!open) onClose(); }} maxWidth=\"lg\">\n <DialogTitle>Create API Key</DialogTitle>\n <DialogContent className=\"space-y-4\">\n <TextField\n label=\"Name\"\n value={name}\n onChange={(e) => setName(e.target.value)}\n placeholder=\"e.g. Analytics Pipeline\"\n size=\"small\"\n autoFocus\n />\n\n <div>\n <Typography variant=\"caption\" color=\"secondary\" className=\"text-[11px] uppercase tracking-wider font-medium mb-2 block\">\n Permissions\n </Typography>\n <div className=\"space-y-2\">\n {permissions.map((row, idx) => (\n <div key={idx} className={cls(\"flex items-center gap-2 p-2 rounded-lg border\", defaultBorderMixin)}>\n <TextField\n size=\"small\"\n value={row.collection}\n onChange={(e) => updateRow(idx, \"collection\", e.target.value)}\n placeholder=\"Collection slug or *\"\n className=\"flex-1\"\n />\n <label className=\"flex items-center gap-1 text-xs cursor-pointer\">\n <Checkbox size=\"small\" checked={row.read} onCheckedChange={(v) => updateRow(idx, \"read\", !!v)}/>\n <span className=\"text-emerald-600 dark:text-emerald-400\">read</span>\n </label>\n <label className=\"flex items-center gap-1 text-xs cursor-pointer\">\n <Checkbox size=\"small\" checked={row.write} onCheckedChange={(v) => updateRow(idx, \"write\", !!v)}/>\n <span className=\"text-blue-600 dark:text-blue-400\">write</span>\n </label>\n <label className=\"flex items-center gap-1 text-xs cursor-pointer\">\n <Checkbox size=\"small\" checked={row.delete} onCheckedChange={(v) => updateRow(idx, \"delete\", !!v)}/>\n <span className=\"text-red-600 dark:text-red-400\">delete</span>\n </label>\n {permissions.length > 1 && (\n <IconButton size=\"small\" onClick={() => removeRow(idx)}>\n <DeleteIcon size={iconSize.smallest}/>\n </IconButton>\n )}\n </div>\n ))}\n </div>\n <Button size=\"small\" variant=\"text\" onClick={addRow} className=\"mt-1\" startIcon={<AddIcon size={iconSize.smallest}/>}>\n Add collection\n </Button>\n </div>\n\n <div className=\"flex gap-4\">\n <div className=\"flex-1\">\n <Select label=\"Expires\" value={expiresIn} onValueChange={setExpiresIn} size=\"small\" renderValue={(v) =>\n v === \"never\" ? \"Never\" :\n v === \"7d\" ? \"7 days\" :\n v === \"30d\" ? \"30 days\" :\n v === \"90d\" ? \"90 days\" : \"1 year\"\n }>\n <SelectItem value=\"never\">Never</SelectItem>\n <SelectItem value=\"7d\">7 days</SelectItem>\n <SelectItem value=\"30d\">30 days</SelectItem>\n <SelectItem value=\"90d\">90 days</SelectItem>\n <SelectItem value=\"1y\">1 year</SelectItem>\n </Select>\n </div>\n <div className=\"flex-1\">\n <TextField\n label=\"Rate Limit (per 15 min)\"\n value={rateLimit}\n onChange={(e) => setRateLimit(e.target.value.replace(/\\D/g, \"\"))}\n placeholder=\"Default: 1000\"\n size=\"small\"\n />\n </div>\n </div>\n </DialogContent>\n <DialogActions>\n <Button variant=\"text\" onClick={onClose}>Cancel</Button>\n <Button\n color=\"primary\"\n onClick={handleCreate}\n disabled={creating || !name.trim()}\n startIcon={creating ? <CircularProgress size=\"smallest\"/> : undefined}\n >\n Create Key\n </Button>\n </DialogActions>\n </Dialog>\n );\n}\n\n/* ═══════════════════════════════════════════════════════════════\n Secret Display Dialog — shown exactly once after creation\n ═══════════════════════════════════════════════════════════════ */\n\nfunction SecretDisplayDialog({ keyWithSecret, onClose }: { keyWithSecret: ApiKeyWithSecret; onClose: () => void }) {\n const snackbar = useSnackbarController();\n const [copied, setCopied] = useState(false);\n\n const handleCopy = async () => {\n try {\n await navigator.clipboard.writeText(keyWithSecret.key);\n setCopied(true);\n snackbar.open({ type: \"success\", message: \"API key copied to clipboard\" });\n setTimeout(() => setCopied(false), 2000);\n } catch {\n snackbar.open({ type: \"error\", message: \"Failed to copy\" });\n }\n };\n\n return (\n <Dialog open onOpenChange={(open) => { if (!open) onClose(); }} maxWidth=\"md\">\n <DialogTitle>\n <div className=\"flex items-center gap-2\">\n <CheckCircleIcon size={iconSize.small} className=\"text-emerald-500\"/>\n API Key Created\n </div>\n </DialogTitle>\n <DialogContent>\n <div className=\"p-3 rounded-lg bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800/50 mb-4\">\n <div className=\"flex items-center gap-2 mb-1\">\n <AlertCircleIcon size={iconSize.smallest} className=\"text-amber-600 dark:text-amber-400\"/>\n <Typography variant=\"caption\" className=\"font-semibold text-amber-700 dark:text-amber-400\">\n Copy your key now — it won&apos;t be shown again\n </Typography>\n </div>\n <Typography variant=\"caption\" className=\"text-amber-600 dark:text-amber-300\">\n This is the only time the full API key will be displayed. Store it securely.\n </Typography>\n </div>\n\n <div className={cls(\"flex items-center gap-2 p-3 rounded-lg border bg-surface-50 dark:bg-surface-900\", defaultBorderMixin)}>\n <code className=\"flex-1 text-[12px] font-mono break-all text-surface-700 dark:text-surface-300 select-all\">\n {keyWithSecret.key}\n </code>\n <Tooltip title={copied ? \"Copied!\" : \"Copy\"}>\n <IconButton size=\"small\" onClick={handleCopy}>\n {copied\n ? <CheckCircleIcon size={iconSize.smallest} className=\"text-emerald-500\"/>\n : <CopyIcon size={iconSize.smallest}/>\n }\n </IconButton>\n </Tooltip>\n </div>\n\n <div className=\"mt-4 space-y-1\">\n <Typography variant=\"caption\" color=\"secondary\">\n <strong>Name:</strong> {keyWithSecret.name}\n </Typography>\n <Typography variant=\"caption\" color=\"secondary\">\n <strong>Permissions:</strong> {permissionSummary(keyWithSecret.permissions)}\n </Typography>\n </div>\n </DialogContent>\n <DialogActions>\n <Button color=\"primary\" onClick={onClose}>Done</Button>\n </DialogActions>\n </Dialog>\n );\n}\n"],"mappings":";;;;;AA+DA,SAAS,eAAe,KAAwC;CAC5D,IAAI,CAAC,KAAK,OAAO;CACjB,MAAM,IAAI,IAAI,KAAK,GAAG;CACtB,MAAM,MAAM,KAAK,IAAI;CACrB,MAAM,OAAO,EAAE,QAAQ,IAAI;CAC3B,MAAM,MAAM,KAAK,IAAI,IAAI;CACzB,IAAI,MAAM,KAAO,OAAO,OAAO,IAAI,WAAW;CAC9C,IAAI,MAAM,MAAS;EAAE,MAAM,IAAI,KAAK,MAAM,MAAM,GAAK;EAAG,OAAO,OAAO,IAAI,MAAM,EAAE,KAAK,GAAG,EAAE;CAAQ;CACpG,IAAI,MAAM,OAAU;EAAE,MAAM,IAAI,KAAK,MAAM,MAAM,IAAO;EAAG,OAAO,OAAO,IAAI,MAAM,EAAE,KAAK,GAAG,EAAE;CAAQ;CACvG,OAAO,EAAE,mBAAmB;AAChC;AAEA,SAAS,kBAAkB,OAAmC;CAC1D,IAAI,MAAM,WAAW,GAAG,OAAO;CAC/B,MAAM,WAAW,MAAM,MAAK,MAAK,EAAE,eAAe,GAAG;CACrD,IAAI,UACA,OAAO,oBAAoB,SAAS,WAAW,KAAK,IAAI,EAAE;CAE9D,IAAI,MAAM,WAAW,GACjB,OAAO,GAAG,MAAM,GAAG,WAAW,IAAI,MAAM,GAAG,WAAW,KAAK,IAAI,EAAE;CAErE,OAAO,GAAG,MAAM,OAAO;AAC3B;AAEA,SAAS,UAAU,KAA4B;CAC3C,OAAO,CAAC,EAAE,IAAI,cAAc,IAAI,KAAK,IAAI,UAAU,oBAAI,IAAI,KAAK;AACpE;AAEA,SAAS,UAAU,KAAqD;CACpE,IAAI,IAAI,YAAY,OAAO;EAAE,OAAO;EAAW,OAAO;CAAe;CACrE,IAAI,UAAU,GAAG,GAAG,OAAO;EAAE,OAAO;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E,cAAc;MAC9B;SACZ,qBAAC,YAAD;MAAY,SAAQ;MAAU,OAAM;gBAApC;OACI,oBAAC,UAAD,EAAA,UAAQ,eAAoB,CAAA;OAAC;OAAE,kBAAkB,cAAc,WAAW;MAClE;OACX;;GACM,EAAA,CAAA;GACf,oBAAC,eAAD,EAAA,UACI,oBAAC,QAAD;IAAQ,OAAM;IAAU,SAAS;cAAS;GAAY,CAAA,EAC3C,CAAA;EACX;;AAEhB"}
@@ -0,0 +1,298 @@
1
+ import { useApiConfig } from "@rebasepro/app";
2
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
3
+ import { ArrowDownToLineIcon, Checkbox, Label, Select, SelectItem, TextField, Typography, cls, defaultBorderMixin } from "@rebasepro/ui";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ //#region src/components/LogsExplorer/LogsExplorer.tsx
6
+ var LEVEL_COLORS = {
7
+ debug: "text-surface-500",
8
+ info: "text-blue-600 dark:text-blue-500",
9
+ warn: "text-amber-600 dark:text-amber-500",
10
+ error: "text-red-600 dark:text-red-500"
11
+ };
12
+ var SOURCE_COLORS = {
13
+ api: "text-sky-600 dark:text-sky-400",
14
+ auth: "text-purple-600 dark:text-purple-400",
15
+ storage: "text-green-600 dark:text-green-500",
16
+ realtime: "text-orange-600 dark:text-orange-400",
17
+ system: "text-surface-600 dark:text-surface-400"
18
+ };
19
+ var idNum = (entry) => Number(entry.id.slice(4));
20
+ var sameLogs = (a, b) => a.length === b.length && a[0]?.id === b[0]?.id && a[a.length - 1]?.id === b[b.length - 1]?.id;
21
+ var STICK_THRESHOLD = 40;
22
+ function LogsExplorer() {
23
+ const [logs, setLogs] = useState([]);
24
+ const [level, setLevel] = useState("all");
25
+ const [source, setSource] = useState("all");
26
+ const [searchInput, setSearchInput] = useState("");
27
+ const [search, setSearch] = useState("");
28
+ const [autoScroll, setAutoScroll] = useState(true);
29
+ const [error, setError] = useState(null);
30
+ const [newCount, setNewCount] = useState(0);
31
+ const [atBottom, setAtBottom] = useState(true);
32
+ const containerRef = useRef(null);
33
+ const stickRef = useRef(true);
34
+ const lastMaxIdRef = useRef(null);
35
+ const apiConfig = useApiConfig();
36
+ useEffect(() => {
37
+ const t = setTimeout(() => setSearch(searchInput), 300);
38
+ return () => clearTimeout(t);
39
+ }, [searchInput]);
40
+ const fetchLogs = useCallback(async () => {
41
+ if (!apiConfig?.apiUrl) {
42
+ setError("No API URL configured — cannot load logs.");
43
+ return;
44
+ }
45
+ try {
46
+ const params = new URLSearchParams();
47
+ if (level && level !== "all") params.set("level", level);
48
+ if (source && source !== "all") params.set("source", source);
49
+ if (search) params.set("search", search);
50
+ params.set("limit", "200");
51
+ const headers = {};
52
+ const token = apiConfig.getAuthToken ? await apiConfig.getAuthToken() : null;
53
+ if (token) headers["Authorization"] = `Bearer ${token}`;
54
+ const resp = await fetch(`${apiConfig.apiUrl}/api/logs?${params}`, { headers });
55
+ if (!resp.ok) {
56
+ setError(resp.status === 401 || resp.status === 403 ? "Not authorised to read logs — an admin role is required." : `Could not load logs (HTTP ${resp.status}).`);
57
+ return;
58
+ }
59
+ const entries = ((await resp.json()).entries || []).slice().reverse();
60
+ const prevMax = lastMaxIdRef.current;
61
+ if (prevMax != null && !stickRef.current) {
62
+ const fresh = entries.filter((e) => idNum(e) > prevMax).length;
63
+ if (fresh > 0) setNewCount((c) => c + fresh);
64
+ }
65
+ if (entries.length > 0) lastMaxIdRef.current = idNum(entries[entries.length - 1]);
66
+ setLogs((prev) => sameLogs(prev, entries) ? prev : entries);
67
+ setError(null);
68
+ } catch (e) {
69
+ setError(e instanceof Error ? e.message : "Could not load logs.");
70
+ }
71
+ }, [
72
+ level,
73
+ source,
74
+ search,
75
+ apiConfig
76
+ ]);
77
+ useEffect(() => {
78
+ lastMaxIdRef.current = null;
79
+ setNewCount(0);
80
+ }, [
81
+ level,
82
+ source,
83
+ search
84
+ ]);
85
+ useEffect(() => {
86
+ let timeoutId = null;
87
+ let cancelled = false;
88
+ fetchLogs();
89
+ const scheduleNext = () => {
90
+ if (cancelled) return;
91
+ timeoutId = setTimeout(async () => {
92
+ if (document.visibilityState === "visible") await fetchLogs();
93
+ scheduleNext();
94
+ }, 3e3);
95
+ };
96
+ scheduleNext();
97
+ const handleVisibility = () => {
98
+ if (document.visibilityState === "visible") fetchLogs();
99
+ };
100
+ document.addEventListener("visibilitychange", handleVisibility);
101
+ return () => {
102
+ cancelled = true;
103
+ if (timeoutId) clearTimeout(timeoutId);
104
+ document.removeEventListener("visibilitychange", handleVisibility);
105
+ };
106
+ }, [fetchLogs]);
107
+ const scrollToBottom = useCallback(() => {
108
+ const el = containerRef.current;
109
+ if (!el) return;
110
+ el.scrollTop = el.scrollHeight;
111
+ stickRef.current = true;
112
+ setAtBottom(true);
113
+ setNewCount(0);
114
+ }, []);
115
+ const handleScroll = useCallback(() => {
116
+ const el = containerRef.current;
117
+ if (!el) return;
118
+ const nearBottom = el.scrollHeight - el.scrollTop - el.clientHeight < STICK_THRESHOLD;
119
+ stickRef.current = nearBottom;
120
+ setAtBottom(nearBottom);
121
+ if (nearBottom) setNewCount(0);
122
+ }, []);
123
+ useLayoutEffect(() => {
124
+ if (autoScroll && stickRef.current) {
125
+ const el = containerRef.current;
126
+ if (el) el.scrollTop = el.scrollHeight;
127
+ }
128
+ }, [logs, autoScroll]);
129
+ return /* @__PURE__ */ jsxs("div", {
130
+ className: "flex flex-col h-[calc(100vh-64px)] w-full bg-surface-50 dark:bg-surface-800",
131
+ children: [
132
+ /* @__PURE__ */ jsxs("div", {
133
+ className: cls("flex gap-2 p-3 border-b items-center flex-wrap shrink-0", defaultBorderMixin),
134
+ children: [
135
+ /* @__PURE__ */ jsxs(Select, {
136
+ value: level,
137
+ onValueChange: setLevel,
138
+ size: "small",
139
+ placeholder: "All Levels",
140
+ children: [
141
+ /* @__PURE__ */ jsx(SelectItem, {
142
+ value: "all",
143
+ children: "All Levels"
144
+ }),
145
+ /* @__PURE__ */ jsx(SelectItem, {
146
+ value: "debug",
147
+ children: "Debug"
148
+ }),
149
+ /* @__PURE__ */ jsx(SelectItem, {
150
+ value: "info",
151
+ children: "Info"
152
+ }),
153
+ /* @__PURE__ */ jsx(SelectItem, {
154
+ value: "warn",
155
+ children: "Warn"
156
+ }),
157
+ /* @__PURE__ */ jsx(SelectItem, {
158
+ value: "error",
159
+ children: "Error"
160
+ })
161
+ ]
162
+ }),
163
+ /* @__PURE__ */ jsxs(Select, {
164
+ value: source,
165
+ onValueChange: setSource,
166
+ size: "small",
167
+ placeholder: "All Sources",
168
+ children: [
169
+ /* @__PURE__ */ jsx(SelectItem, {
170
+ value: "all",
171
+ children: "All Sources"
172
+ }),
173
+ /* @__PURE__ */ jsx(SelectItem, {
174
+ value: "api",
175
+ children: "API"
176
+ }),
177
+ /* @__PURE__ */ jsx(SelectItem, {
178
+ value: "auth",
179
+ children: "Auth"
180
+ }),
181
+ /* @__PURE__ */ jsx(SelectItem, {
182
+ value: "storage",
183
+ children: "Storage"
184
+ }),
185
+ /* @__PURE__ */ jsx(SelectItem, {
186
+ value: "realtime",
187
+ children: "Realtime"
188
+ }),
189
+ /* @__PURE__ */ jsx(SelectItem, {
190
+ value: "system",
191
+ children: "System"
192
+ })
193
+ ]
194
+ }),
195
+ /* @__PURE__ */ jsx(TextField, {
196
+ size: "small",
197
+ placeholder: "Search logs...",
198
+ value: searchInput,
199
+ onChange: (e) => setSearchInput(e.target.value),
200
+ className: "flex-1 min-w-[200px]"
201
+ }),
202
+ /* @__PURE__ */ jsxs("div", {
203
+ className: "flex items-center gap-1.5 cursor-pointer ml-2",
204
+ children: [/* @__PURE__ */ jsx(Checkbox, {
205
+ id: "auto-scroll",
206
+ checked: autoScroll,
207
+ onCheckedChange: (checked) => {
208
+ setAutoScroll(checked);
209
+ if (checked) scrollToBottom();
210
+ },
211
+ size: "small",
212
+ padding: false
213
+ }), /* @__PURE__ */ jsx(Label, {
214
+ htmlFor: "auto-scroll",
215
+ className: "text-xs select-none cursor-pointer text-surface-600 dark:text-surface-400",
216
+ children: "Auto-scroll"
217
+ })]
218
+ }),
219
+ /* @__PURE__ */ jsx("div", {
220
+ className: "ml-auto pl-4",
221
+ children: /* @__PURE__ */ jsxs(Typography, {
222
+ variant: "caption",
223
+ color: "secondary",
224
+ children: [logs.length, " entries"]
225
+ })
226
+ })
227
+ ]
228
+ }),
229
+ error && logs.length > 0 && /* @__PURE__ */ jsx("div", {
230
+ className: cls("px-4 py-1.5 border-b bg-amber-50 dark:bg-amber-950/20 shrink-0", defaultBorderMixin),
231
+ children: /* @__PURE__ */ jsx(Typography, {
232
+ variant: "caption",
233
+ className: "text-amber-700 dark:text-amber-400",
234
+ children: error
235
+ })
236
+ }),
237
+ /* @__PURE__ */ jsxs("div", {
238
+ className: "relative flex-1 min-h-0",
239
+ children: [/* @__PURE__ */ jsxs("div", {
240
+ ref: containerRef,
241
+ onScroll: handleScroll,
242
+ className: "h-full overflow-auto py-2",
243
+ children: [logs.map((log) => /* @__PURE__ */ jsxs("div", {
244
+ className: cls("flex gap-4 px-4 py-[6px] border-b hover:bg-surface-100 dark:hover:bg-surface-900 transition-colors", defaultBorderMixin),
245
+ children: [
246
+ /* @__PURE__ */ jsx(Typography, {
247
+ variant: "body2",
248
+ color: "secondary",
249
+ className: "w-[72px] shrink-0 font-mono",
250
+ children: new Date(log.timestamp).toLocaleTimeString()
251
+ }),
252
+ /* @__PURE__ */ jsx(Typography, {
253
+ variant: "body2",
254
+ className: cls("w-[48px] shrink-0 uppercase font-semibold font-mono", LEVEL_COLORS[log.level] || "text-surface-500"),
255
+ children: log.level
256
+ }),
257
+ /* @__PURE__ */ jsxs(Typography, {
258
+ variant: "body2",
259
+ className: cls("w-[80px] shrink-0 font-mono", SOURCE_COLORS[log.source] || "text-surface-500"),
260
+ children: [
261
+ "[",
262
+ log.source,
263
+ "]"
264
+ ]
265
+ }),
266
+ /* @__PURE__ */ jsx(Typography, {
267
+ variant: "body2",
268
+ className: "flex-1 font-mono break-all whitespace-pre-wrap text-surface-900 dark:text-surface-100",
269
+ children: log.message
270
+ })
271
+ ]
272
+ }, log.id)), logs.length === 0 && /* @__PURE__ */ jsx("div", {
273
+ className: "p-8 text-center",
274
+ children: /* @__PURE__ */ jsx(Typography, {
275
+ variant: "body2",
276
+ className: error ? "text-red-600 dark:text-red-500" : void 0,
277
+ color: error ? void 0 : "secondary",
278
+ children: error ?? "No log entries yet. Logs will appear here as requests come in."
279
+ })
280
+ })]
281
+ }), autoScroll && !atBottom && newCount > 0 && /* @__PURE__ */ jsxs("button", {
282
+ onClick: scrollToBottom,
283
+ className: "absolute bottom-3 left-1/2 -translate-x-1/2 flex items-center gap-1.5 rounded-full bg-primary text-white text-xs font-medium pl-2.5 pr-3 py-1.5 shadow-md hover:bg-primary-dark transition-colors",
284
+ children: [
285
+ /* @__PURE__ */ jsx(ArrowDownToLineIcon, { size: 14 }),
286
+ newCount,
287
+ " new ",
288
+ newCount === 1 ? "entry" : "entries"
289
+ ]
290
+ })]
291
+ })
292
+ ]
293
+ });
294
+ }
295
+ //#endregion
296
+ export { LogsExplorer };
297
+
298
+ //# sourceMappingURL=LogsExplorer-BCXoGREr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LogsExplorer-BCXoGREr.js","names":[],"sources":["../src/components/LogsExplorer/LogsExplorer.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from \"react\";\nimport { ArrowDownToLineIcon, Checkbox, cls, defaultBorderMixin, Label, Select, SelectItem, TextField, Typography } from \"@rebasepro/ui\";\nimport { useApiConfig } from \"@rebasepro/app\";\n\ninterface LogEntry {\n id: string;\n timestamp: string;\n level: \"debug\" | \"info\" | \"warn\" | \"error\";\n source: \"api\" | \"auth\" | \"storage\" | \"realtime\" | \"system\";\n message: string;\n metadata?: Record<string, unknown>;\n}\n\nconst LEVEL_COLORS: Record<string, string> = {\n debug: \"text-surface-500\",\n info: \"text-blue-600 dark:text-blue-500\",\n warn: \"text-amber-600 dark:text-amber-500\",\n error: \"text-red-600 dark:text-red-500\"\n};\n\nconst SOURCE_COLORS: Record<string, string> = {\n api: \"text-sky-600 dark:text-sky-400\",\n auth: \"text-purple-600 dark:text-purple-400\",\n storage: \"text-green-600 dark:text-green-500\",\n realtime: \"text-orange-600 dark:text-orange-400\",\n system: \"text-surface-600 dark:text-surface-400\"\n};\n\n// Ids are `log_<n>` with a monotonic counter, so numeric comparison tells\n// old entries from new ones across polls.\nconst idNum = (entry: LogEntry): number => Number(entry.id.slice(\"log_\".length));\n\n// The window is contiguous and ordered, so identical ends mean identical content.\nconst sameLogs = (a: LogEntry[], b: LogEntry[]): boolean =>\n a.length === b.length &&\n a[0]?.id === b[0]?.id &&\n a[a.length - 1]?.id === b[b.length - 1]?.id;\n\n// How close to the bottom edge still counts as \"at the bottom\".\nconst STICK_THRESHOLD = 40;\n\nexport function LogsExplorer() {\n const [logs, setLogs] = useState<LogEntry[]>([]);\n const [level, setLevel] = useState<string>(\"all\");\n const [source, setSource] = useState<string>(\"all\");\n const [searchInput, setSearchInput] = useState(\"\");\n const [search, setSearch] = useState(\"\");\n const [autoScroll, setAutoScroll] = useState(true);\n const [error, setError] = useState<string | null>(null);\n // Entries that arrived while the user was scrolled away from the bottom.\n const [newCount, setNewCount] = useState(0);\n const [atBottom, setAtBottom] = useState(true);\n const containerRef = useRef<HTMLDivElement>(null);\n // Whether the view is stuck to the bottom right now. A ref, not state:\n // the scroll handler and the fetch loop both read it synchronously.\n const stickRef = useRef(true);\n const lastMaxIdRef = useRef<number | null>(null);\n const apiConfig = useApiConfig();\n\n // Debounce the search box so typing doesn't refetch per keystroke.\n useEffect(() => {\n const t = setTimeout(() => setSearch(searchInput), 300);\n return () => clearTimeout(t);\n }, [searchInput]);\n\n const fetchLogs = useCallback(async () => {\n if (!apiConfig?.apiUrl) {\n setError(\"No API URL configured — cannot load logs.\");\n return;\n }\n try {\n const params = new URLSearchParams();\n if (level && level !== \"all\") params.set(\"level\", level);\n if (source && source !== \"all\") params.set(\"source\", source);\n if (search) params.set(\"search\", search);\n params.set(\"limit\", \"200\");\n\n // Logs are admin-only, so the request must carry the auth token. The\n // URL is absolute: a relative one would resolve against the frontend\n // origin, which serves index.html rather than the API.\n const headers: Record<string, string> = {};\n const token = apiConfig.getAuthToken ? await apiConfig.getAuthToken() : null;\n if (token) headers[\"Authorization\"] = `Bearer ${token}`;\n\n const resp = await fetch(`${apiConfig.apiUrl}/api/logs?${params}`, { headers });\n if (!resp.ok) {\n setError(resp.status === 401 || resp.status === 403\n ? \"Not authorised to read logs — an admin role is required.\"\n : `Could not load logs (HTTP ${resp.status}).`);\n return;\n }\n const data: { entries?: LogEntry[] } = await resp.json();\n // The API returns newest-first; the view tails like a terminal, so\n // flip to chronological order (newest at the bottom).\n const entries = (data.entries || []).slice().reverse();\n\n const prevMax = lastMaxIdRef.current;\n if (prevMax != null && !stickRef.current) {\n const fresh = entries.filter(e => idNum(e) > prevMax).length;\n if (fresh > 0) setNewCount(c => c + fresh);\n }\n if (entries.length > 0) lastMaxIdRef.current = idNum(entries[entries.length - 1]);\n\n // Unchanged window → keep the previous array so React leaves the\n // DOM alone (hover states and text selection survive the poll).\n setLogs(prev => sameLogs(prev, entries) ? prev : entries);\n setError(null);\n } catch (e) {\n setError(e instanceof Error ? e.message : \"Could not load logs.\");\n }\n }, [level, source, search, apiConfig]);\n\n // A filter change replaces the window wholesale — \"new entries since last\n // poll\" stops meaning anything, so the counter starts over.\n useEffect(() => {\n lastMaxIdRef.current = null;\n setNewCount(0);\n }, [level, source, search]);\n\n useEffect(() => {\n let timeoutId: ReturnType<typeof setTimeout> | null = null;\n let cancelled = false;\n\n fetchLogs();\n\n const scheduleNext = () => {\n if (cancelled) return;\n timeoutId = setTimeout(async () => {\n if (document.visibilityState === \"visible\") {\n await fetchLogs();\n }\n scheduleNext();\n }, 3000);\n };\n\n scheduleNext();\n\n const handleVisibility = () => {\n if (document.visibilityState === \"visible\") {\n fetchLogs();\n }\n };\n document.addEventListener(\"visibilitychange\", handleVisibility);\n\n return () => {\n cancelled = true;\n if (timeoutId) clearTimeout(timeoutId);\n document.removeEventListener(\"visibilitychange\", handleVisibility);\n };\n }, [fetchLogs]);\n\n const scrollToBottom = useCallback(() => {\n const el = containerRef.current;\n if (!el) return;\n el.scrollTop = el.scrollHeight;\n stickRef.current = true;\n setAtBottom(true);\n setNewCount(0);\n }, []);\n\n // Stick to the bottom only while the user is already there. Scrolling up\n // disengages; scrolling back down re-engages. Our own scrollTop writes\n // always land at the bottom, so they can never disengage it.\n const handleScroll = useCallback(() => {\n const el = containerRef.current;\n if (!el) return;\n const nearBottom = el.scrollHeight - el.scrollTop - el.clientHeight < STICK_THRESHOLD;\n stickRef.current = nearBottom;\n setAtBottom(nearBottom);\n if (nearBottom) setNewCount(0);\n }, []);\n\n useLayoutEffect(() => {\n if (autoScroll && stickRef.current) {\n const el = containerRef.current;\n if (el) el.scrollTop = el.scrollHeight;\n }\n }, [logs, autoScroll]);\n\n return (\n <div className=\"flex flex-col h-[calc(100vh-64px)] w-full bg-surface-50 dark:bg-surface-800\">\n {/* Toolbar */}\n <div className={cls(\n \"flex gap-2 p-3 border-b items-center flex-wrap shrink-0\",\n defaultBorderMixin\n )}>\n <Select\n value={level}\n onValueChange={setLevel}\n size=\"small\"\n placeholder=\"All Levels\"\n >\n <SelectItem value=\"all\">All Levels</SelectItem>\n <SelectItem value=\"debug\">Debug</SelectItem>\n <SelectItem value=\"info\">Info</SelectItem>\n <SelectItem value=\"warn\">Warn</SelectItem>\n <SelectItem value=\"error\">Error</SelectItem>\n </Select>\n <Select\n value={source}\n onValueChange={setSource}\n size=\"small\"\n placeholder=\"All Sources\"\n >\n <SelectItem value=\"all\">All Sources</SelectItem>\n <SelectItem value=\"api\">API</SelectItem>\n <SelectItem value=\"auth\">Auth</SelectItem>\n <SelectItem value=\"storage\">Storage</SelectItem>\n <SelectItem value=\"realtime\">Realtime</SelectItem>\n <SelectItem value=\"system\">System</SelectItem>\n </Select>\n <TextField\n size=\"small\"\n placeholder=\"Search logs...\"\n value={searchInput}\n onChange={e => setSearchInput(e.target.value)}\n className=\"flex-1 min-w-[200px]\"\n />\n <div className=\"flex items-center gap-1.5 cursor-pointer ml-2\">\n <Checkbox\n id=\"auto-scroll\"\n checked={autoScroll}\n onCheckedChange={(checked: boolean) => {\n setAutoScroll(checked);\n if (checked) scrollToBottom();\n }}\n size=\"small\"\n padding={false}\n />\n <Label\n htmlFor=\"auto-scroll\"\n className=\"text-xs select-none cursor-pointer text-surface-600 dark:text-surface-400\"\n >\n Auto-scroll\n </Label>\n </div>\n <div className=\"ml-auto pl-4\">\n <Typography variant=\"caption\" color=\"secondary\">\n {logs.length} entries\n </Typography>\n </div>\n </div>\n\n {/* A failing poll must stay visible even while stale logs are on\n screen — otherwise the view quietly freezes. */}\n {error && logs.length > 0 && (\n <div className={cls(\n \"px-4 py-1.5 border-b bg-amber-50 dark:bg-amber-950/20 shrink-0\",\n defaultBorderMixin\n )}>\n <Typography variant=\"caption\" className=\"text-amber-700 dark:text-amber-400\">\n {error}\n </Typography>\n </div>\n )}\n\n {/* Log entries */}\n <div className=\"relative flex-1 min-h-0\">\n <div\n ref={containerRef}\n onScroll={handleScroll}\n className=\"h-full overflow-auto py-2\"\n >\n {logs.map(log => (\n <div\n key={log.id}\n className={cls(\n \"flex gap-4 px-4 py-[6px] border-b hover:bg-surface-100 dark:hover:bg-surface-900 transition-colors\",\n defaultBorderMixin\n )}\n >\n <Typography variant=\"body2\" color=\"secondary\" className=\"w-[72px] shrink-0 font-mono\">\n {new Date(log.timestamp).toLocaleTimeString()}\n </Typography>\n <Typography variant=\"body2\" className={cls(\"w-[48px] shrink-0 uppercase font-semibold font-mono\", LEVEL_COLORS[log.level] || \"text-surface-500\")}>\n {log.level}\n </Typography>\n <Typography variant=\"body2\" className={cls(\"w-[80px] shrink-0 font-mono\", SOURCE_COLORS[log.source] || \"text-surface-500\")}>\n [{log.source}]\n </Typography>\n <Typography variant=\"body2\" className=\"flex-1 font-mono break-all whitespace-pre-wrap text-surface-900 dark:text-surface-100\">\n {log.message}\n </Typography>\n </div>\n ))}\n {logs.length === 0 && (\n <div className=\"p-8 text-center\">\n <Typography\n variant=\"body2\"\n className={error ? \"text-red-600 dark:text-red-500\" : undefined}\n color={error ? undefined : \"secondary\"}\n >\n {error ?? \"No log entries yet. Logs will appear here as requests come in.\"}\n </Typography>\n </div>\n )}\n </div>\n\n {autoScroll && !atBottom && newCount > 0 && (\n <button\n onClick={scrollToBottom}\n className=\"absolute bottom-3 left-1/2 -translate-x-1/2 flex items-center gap-1.5 rounded-full bg-primary text-white text-xs font-medium pl-2.5 pr-3 py-1.5 shadow-md hover:bg-primary-dark transition-colors\"\n >\n <ArrowDownToLineIcon size={14}/>\n {newCount} new {newCount === 1 ? \"entry\" : \"entries\"}\n </button>\n )}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;AAaA,IAAM,eAAuC;CACzC,OAAO;CACP,MAAM;CACN,MAAM;CACN,OAAO;AACX;AAEA,IAAM,gBAAwC;CAC1C,KAAK;CACL,MAAM;CACN,SAAS;CACT,UAAU;CACV,QAAQ;AACZ;AAIA,IAAM,SAAS,UAA4B,OAAO,MAAM,GAAG,MAAM,CAAa,CAAC;AAG/E,IAAM,YAAY,GAAe,MAC7B,EAAE,WAAW,EAAE,UACf,EAAE,IAAI,OAAO,EAAE,IAAI,MACnB,EAAE,EAAE,SAAS,IAAI,OAAO,EAAE,EAAE,SAAS,IAAI;AAG7C,IAAM,kBAAkB;AAExB,SAAgB,eAAe;CAC3B,MAAM,CAAC,MAAM,WAAW,SAAqB,CAAC,CAAC;CAC/C,MAAM,CAAC,OAAO,YAAY,SAAiB,KAAK;CAChD,MAAM,CAAC,QAAQ,aAAa,SAAiB,KAAK;CAClD,MAAM,CAAC,aAAa,kBAAkB,SAAS,EAAE;CACjD,MAAM,CAAC,QAAQ,aAAa,SAAS,EAAE;CACvC,MAAM,CAAC,YAAY,iBAAiB,SAAS,IAAI;CACjD,MAAM,CAAC,OAAO,YAAY,SAAw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UAAD;KACI,SAAS;KACT,WAAU;eAFd;MAII,oBAAC,qBAAD,EAAqB,MAAM,GAAI,CAAA;MAC9B;MAAS;MAAM,aAAa,IAAI,UAAU;KACvC;MAEX;;EACJ;;AAEb"}
@@ -57,34 +57,34 @@ var POLICY_PRESETS = [
57
57
  {
58
58
  id: "user_select_own",
59
59
  label: "Users can read their own rows",
60
- description: "Users can only read rows where the user_id matches their auth.uid()",
60
+ description: "Users can only read rows where the uid matches their auth.uid()",
61
61
  policyname: "Users can select their own data",
62
62
  cmd: "SELECT",
63
63
  permissive: "PERMISSIVE",
64
64
  roles: ["authenticated"],
65
- qual: "auth.uid() = user_id",
65
+ qual: "auth.uid() = uid",
66
66
  with_check: ""
67
67
  },
68
68
  {
69
69
  id: "user_update_own",
70
70
  label: "Users can update their own rows",
71
- description: "Users can only update rows where the user_id matches their auth.uid()",
71
+ description: "Users can only update rows where the uid matches their auth.uid()",
72
72
  policyname: "Users can update their own data",
73
73
  cmd: "UPDATE",
74
74
  permissive: "PERMISSIVE",
75
75
  roles: ["authenticated"],
76
- qual: "auth.uid() = user_id",
77
- with_check: "auth.uid() = user_id"
76
+ qual: "auth.uid() = uid",
77
+ with_check: "auth.uid() = uid"
78
78
  },
79
79
  {
80
80
  id: "user_delete_own",
81
81
  label: "Users can delete their own rows",
82
- description: "Users can only delete rows where the user_id matches their auth.uid()",
82
+ description: "Users can only delete rows where the uid matches their auth.uid()",
83
83
  policyname: "Users can delete their own data",
84
84
  cmd: "DELETE",
85
85
  permissive: "PERMISSIVE",
86
86
  roles: ["authenticated"],
87
- qual: "auth.uid() = user_id",
87
+ qual: "auth.uid() = uid",
88
88
  with_check: ""
89
89
  }
90
90
  ];
@@ -139,9 +139,10 @@ var PolicyEditor = ({ policy, schema, table, onSave, onCancel }) => {
139
139
  });
140
140
  };
141
141
  return /* @__PURE__ */ jsxs(Fragment, { children: [
142
- /* @__PURE__ */ jsxs(DialogTitle, {
143
- className: "flex justify-between items-center w-full",
142
+ /* @__PURE__ */ jsxs(Typography, {
144
143
  variant: "h6",
144
+ gutterBottom: true,
145
+ className: "mt-8 mx-8 flex justify-between items-center w-full",
145
146
  children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", { children: policy ? t("studio_policy_edit") : t("studio_policy_create") }), /* @__PURE__ */ jsxs("div", {
146
147
  className: "text-sm font-normal text-text-secondary dark:text-text-secondary-dark tracking-wide mt-1",
147
148
  children: [
@@ -456,7 +457,7 @@ var PolicyEditor = ({ policy, schema, table, onSave, onCancel }) => {
456
457
  }),
457
458
  /* @__PURE__ */ jsx("div", {
458
459
  className: cls("bg-surface-100 dark:bg-surface-950 px-3 py-2 rounded-md font-mono text-sm my-2", defaultBorderMixin),
459
- children: "Example: auth.uid() = user_id"
460
+ children: "Example: auth.uid() = uid"
460
461
  }),
461
462
  /* @__PURE__ */ jsx(Typography, {
462
463
  variant: "caption",
@@ -480,7 +481,7 @@ var PolicyEditor = ({ policy, schema, table, onSave, onCancel }) => {
480
481
  }),
481
482
  /* @__PURE__ */ jsx("div", {
482
483
  className: cls("bg-surface-100 dark:bg-surface-950 px-3 py-2 rounded-md font-mono text-sm my-2", defaultBorderMixin),
483
- children: "Example: auth.uid() = user_id"
484
+ children: "Example: auth.uid() = uid"
484
485
  }),
485
486
  /* @__PURE__ */ jsx(Typography, {
486
487
  variant: "caption",
@@ -512,7 +513,7 @@ var PolicyEditor = ({ policy, schema, table, onSave, onCancel }) => {
512
513
  className: "block mt-0.5",
513
514
  children: ["Returns the current user's ID as text. Example: ", /* @__PURE__ */ jsx("code", {
514
515
  className: "bg-surface-100 dark:bg-surface-950 px-1 py-0.5 rounded text-[11px]",
515
- children: "auth.uid() = user_id"
516
+ children: "auth.uid() = uid"
516
517
  })]
517
518
  })] }),
518
519
  /* @__PURE__ */ jsxs("li", { children: [/* @__PURE__ */ jsx("code", {
@@ -1556,4 +1557,4 @@ var RLSEditor = ({ apiUrl = "" }) => {
1556
1557
  //#endregion
1557
1558
  export { RLSEditor };
1558
1559
 
1559
- //# sourceMappingURL=RLSEditor-DO_pFwLP.js.map
1560
+ //# sourceMappingURL=RLSEditor-rLlMcZPG.js.map