@rebasepro/studio 0.34.2 → 0.35.1
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/README.md +1 -1
- package/dist/{ApiExplorer-BhQFd_iR.js → ApiExplorer-C61w8gCc.js} +73 -58
- package/dist/ApiExplorer-C61w8gCc.js.map +1 -0
- package/dist/{ApiKeysView-CLBXUCgu.js → ApiKeysView-BdqASL_2.js} +33 -32
- package/dist/ApiKeysView-BdqASL_2.js.map +1 -0
- package/dist/{BranchesView-BKGhk-PC.js → BranchesView-Bh5lq9T_.js} +5 -5
- package/dist/BranchesView-Bh5lq9T_.js.map +1 -0
- package/dist/{CronJobsView-CwF_m6ZB.js → CronJobsView-DUuyzkJK.js} +392 -8
- package/dist/CronJobsView-DUuyzkJK.js.map +1 -0
- package/dist/FixedEditorOverlay-DtgPBSjq.js +93 -0
- package/dist/FixedEditorOverlay-DtgPBSjq.js.map +1 -0
- package/dist/{JSEditor-Br22PfLh.js → JSEditor-Bi2Aol-Y.js} +27 -21
- package/dist/JSEditor-Bi2Aol-Y.js.map +1 -0
- package/dist/{LogsExplorer-DOLRFQaW.js → LogsExplorer-BA8RfTwd.js} +46 -67
- package/dist/LogsExplorer-BA8RfTwd.js.map +1 -0
- package/dist/{RLSEditor-RE4YpN_z.js → RLSEditor-CTG3jLE7.js} +478 -224
- package/dist/RLSEditor-CTG3jLE7.js.map +1 -0
- package/dist/{SQLEditor-Dj5INEUZ.js → SQLEditor-DRo5kW1h.js} +15 -96
- package/dist/SQLEditor-DRo5kW1h.js.map +1 -0
- package/dist/{SchemaVisualizer-D2_cck4I.js → SchemaVisualizer-Dy4kWKT5.js} +15 -14
- package/dist/SchemaVisualizer-Dy4kWKT5.js.map +1 -0
- package/dist/{StorageView-DHm22S7y.js → StorageView-D0D8z4lI.js} +497 -4
- package/dist/StorageView-D0D8z4lI.js.map +1 -0
- package/dist/TableEditorView-BKhSBG-K.js +1694 -0
- package/dist/TableEditorView-BKhSBG-K.js.map +1 -0
- package/dist/UsersAndRolesView-CKw4SJPj.js +689 -0
- package/dist/UsersAndRolesView-CKw4SJPj.js.map +1 -0
- package/dist/WebhooksView-CFPY-N9h.js +465 -0
- package/dist/WebhooksView-CFPY-N9h.js.map +1 -0
- package/dist/adminFetch-BfOnfRgU.js +108 -0
- package/dist/adminFetch-BfOnfRgU.js.map +1 -0
- package/dist/components/ApiExplorer/TryItPanel.d.ts +6 -0
- package/dist/components/ApiKeys/scope-words.d.ts +1 -1
- package/dist/components/AuthSimulationSelector.d.ts +9 -1
- package/dist/components/CronJobs/DbCronJobsPanel.d.ts +2 -0
- package/dist/components/RLSEditor/DirectRlsPoliciesPanel.d.ts +7 -0
- package/dist/components/RebaseStudio.d.ts +1 -1
- package/dist/components/RebaseStudioApp.d.ts +28 -0
- package/dist/components/SQLEditor/FixedEditorOverlay.d.ts +12 -0
- package/dist/components/SQLEditor/SQLEditor.d.ts +2 -11
- package/dist/components/StorageView/StoragePoliciesPanel.d.ts +2 -0
- package/dist/components/StudioHomePage.d.ts +3 -1
- package/dist/components/TableEditor/TableEditorView.d.ts +2 -0
- package/dist/components/UsersAndRoles/UsersAndRolesView.d.ts +2 -0
- package/dist/components/Webhooks/WebhooksView.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +739 -109
- package/dist/index.es.js.map +1 -1
- package/dist/policy-presets-CJKzAvQp.js +167 -0
- package/dist/policy-presets-CJKzAvQp.js.map +1 -0
- package/dist/{useRunAsUsers-CLaAtXt6.js → useRunAsUsers-CF7tkGzj.js} +22 -3
- package/dist/useRunAsUsers-CF7tkGzj.js.map +1 -0
- package/dist/utils/adminFetch.d.ts +25 -0
- package/package.json +12 -16
- package/dist/ApiExplorer-BhQFd_iR.js.map +0 -1
- package/dist/ApiKeysView-CLBXUCgu.js.map +0 -1
- package/dist/BranchesView-BKGhk-PC.js.map +0 -1
- package/dist/CronJobsView-CwF_m6ZB.js.map +0 -1
- package/dist/JSEditor-Br22PfLh.js.map +0 -1
- package/dist/LogsExplorer-DOLRFQaW.js.map +0 -1
- package/dist/RLSEditor-RE4YpN_z.js.map +0 -1
- package/dist/SQLEditor-Dj5INEUZ.js.map +0 -1
- package/dist/SchemaVisualizer-D2_cck4I.js.map +0 -1
- package/dist/StorageView-DHm22S7y.js.map +0 -1
- package/dist/useRunAsUsers-CLaAtXt6.js.map +0 -1
|
@@ -1,175 +1,15 @@
|
|
|
1
|
+
import { a as asStringArray, i as asString, n as asNullableString, o as isRecord, s as useAdminFetch, t as asBoolean } from "./adminFetch-BfOnfRgU.js";
|
|
1
2
|
import { o as quoteIdentifier } from "./sql_utils-CYcgpgam.js";
|
|
3
|
+
import { i as roleOptionsFor, n as POLICY_PRESETS, t as COMMAND_OPTIONS } from "./policy-presets-CJKzAvQp.js";
|
|
2
4
|
import { t as MonacoEditor } from "./MonacoEditor-7IlHFZU5.js";
|
|
3
5
|
import { r as schemaSourceProblem, t as SchemaSourceProblemAlert } from "./schema-source-C4ekB7WU.js";
|
|
4
6
|
import { ConfirmationDialog, ErrorView, useApiBase, useApiConfig, useRebaseContext, useSnackbarController, useStudioCapabilities, useStudioSchemaEditing, useTableDescriptors, useTranslation } from "@rebasepro/app";
|
|
5
7
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
6
|
-
import { Alert, AlertTriangleIcon, Button, Chip, CircularProgress, DatabaseIcon, Dialog, DialogActions, DialogContent, DialogTitle, HelpCircleIcon, IconButton, KeyIcon, LockIcon, MultiSelect, MultiSelectItem, Paper, RefreshCwIcon, ResizablePanels, Select, SelectItem, ShieldIcon, Tab, Tabs, TextField, Tooltip, Trash2Icon, Typography, cls, defaultBorderMixin, iconSize } from "@rebasepro/ui";
|
|
8
|
+
import { Alert, AlertTriangleIcon, BooleanSwitchWithLabel, Button, Card, Chip, CircularProgress, DatabaseIcon, Dialog, DialogActions, DialogContent, DialogTitle, HelpCircleIcon, IconButton, KeyIcon, LockIcon, MultiSelect, MultiSelectItem, Paper, PlusIcon, RefreshCwIcon, ResizablePanels, Select, SelectItem, ShieldIcon, Tab, Table, TableBody, TableCell, TableHeader, TableRow, Tabs, TextField, Tooltip, Trash2Icon, Typography, cls, defaultBorderMixin, iconSize } from "@rebasepro/ui";
|
|
7
9
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
-
import { REBASE_ADMIN_REQUEST_ROLE, REBASE_ADMIN_ROLE, RLS_JWT_SQL, RLS_ROLES_SQL, RLS_UID_SQL, isRedactedSecurityRule,
|
|
10
|
+
import { REBASE_ADMIN_REQUEST_ROLE, REBASE_ADMIN_ROLE, RLS_JWT_SQL, RLS_ROLES_SQL, RLS_UID_SQL, isRedactedSecurityRule, rulePatches } from "@rebasepro/types";
|
|
9
11
|
import { adminRequestPolicyName, getPolicyNamesForRule, getPolicyOperations } from "@rebasepro/utils";
|
|
10
|
-
import { JUNCTION_TABLES_SQL, REBASE_INTERNAL_PREFIXES, REBASE_INTERNAL_SCHEMAS, REBASE_USER_ROLE,
|
|
11
|
-
//#region src/components/RLSEditor/policy-presets.ts
|
|
12
|
-
/**
|
|
13
|
-
* What the RLS editor offers before the user types anything: the roles a `TO`
|
|
14
|
-
* list may name, and the ready-made policies.
|
|
15
|
-
*
|
|
16
|
-
* Separated from the component because these are the parts that have to agree
|
|
17
|
-
* with the *server*, not with the UI — and the ways they can silently disagree
|
|
18
|
-
* are the reason this file has tests.
|
|
19
|
-
*/
|
|
20
|
-
var COMMAND_OPTIONS = [
|
|
21
|
-
"ALL",
|
|
22
|
-
"SELECT",
|
|
23
|
-
"INSERT",
|
|
24
|
-
"UPDATE",
|
|
25
|
-
"DELETE"
|
|
26
|
-
];
|
|
27
|
-
/**
|
|
28
|
-
* The roles a policy's `TO` list can name when nothing better is known.
|
|
29
|
-
*
|
|
30
|
-
* Not `authenticated` / `anon` / `admin`, which is what this list used to be.
|
|
31
|
-
* The first two are Supabase's role names and Rebase never creates them, so
|
|
32
|
-
* `CREATE POLICY ... TO authenticated` — which is literally what the editor
|
|
33
|
-
* builds and executes — fails with `role "authenticated" does not exist`. The
|
|
34
|
-
* driver's `validatePolicyPgRoles` rejects the same three names in
|
|
35
|
-
* `SecurityRule.pgRoles` and says why: they are another platform's convention,
|
|
36
|
-
* and application roles belong in a condition, not in the `TO` list.
|
|
37
|
-
*
|
|
38
|
-
* `admin` was the more dangerous entry, because it is a plausible *application*
|
|
39
|
-
* role. Had one existed as a database role too, the policy would have been
|
|
40
|
-
* created successfully and then matched nothing at all: requests run as
|
|
41
|
-
* {@link REBASE_USER_ROLE} after a `SET LOCAL ROLE`, and a `TO` list naming a
|
|
42
|
-
* role the request never assumes filters every row without erroring.
|
|
43
|
-
*
|
|
44
|
-
* So: `public` (what the framework's own generator emits) and the role requests
|
|
45
|
-
* actually arrive as. "Signed-in users" and "admins" are not roles here — they
|
|
46
|
-
* are conditions over `rebase.uid()` and `rebase.roles()`, which is what the
|
|
47
|
-
* presets below now compile to.
|
|
48
|
-
*/
|
|
49
|
-
var FALLBACK_ROLE_OPTIONS = ["public", REBASE_USER_ROLE];
|
|
50
|
-
/**
|
|
51
|
-
* The `TO` list the editor offers, given what the database reported and what
|
|
52
|
-
* the policy being edited already targets.
|
|
53
|
-
*
|
|
54
|
-
* Three sources, and each is there for a reason the others do not cover:
|
|
55
|
-
*
|
|
56
|
-
* - {@link FALLBACK_ROLE_OPTIONS} always, because `public` is a **keyword, not
|
|
57
|
-
* a row in `pg_roles`** — `fetchAvailableRoles` cannot return it, so seeding
|
|
58
|
-
* from the live fetch alone would drop the one role every generated policy
|
|
59
|
-
* targets.
|
|
60
|
-
* - the live roles, so an operator's own `app_read` is reachable without
|
|
61
|
-
* hand-editing SQL.
|
|
62
|
-
* - the edited policy's own roles, because a `MultiSelect` silently drops a
|
|
63
|
-
* value with no matching item. That value is the `TO` list of a policy
|
|
64
|
-
* already enforcing something, so opening an unrelated policy for a one-word
|
|
65
|
-
* rename would have quietly rewritten who it applies to.
|
|
66
|
-
*/
|
|
67
|
-
function roleOptionsFor(fetched, policyRoles) {
|
|
68
|
-
return [.../* @__PURE__ */ new Set([
|
|
69
|
-
...FALLBACK_ROLE_OPTIONS,
|
|
70
|
-
...fetched ?? [],
|
|
71
|
-
...policyRoles ?? []
|
|
72
|
-
])];
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Preset conditions, compiled by the framework's own policy compiler rather
|
|
76
|
-
* than written out here.
|
|
77
|
-
*
|
|
78
|
-
* `compilePolicyExpression` is the function `db push` generates policies with, so a
|
|
79
|
-
* preset cannot drift from what the framework emits — and the one that matters
|
|
80
|
-
* has drifted before: `authenticated()` used to compile to a bare
|
|
81
|
-
* `IS NOT NULL`, which is true for anonymous visitors, and any copy of that
|
|
82
|
-
* string sitting in a preset would still be handing out the old grant today.
|
|
83
|
-
*/
|
|
84
|
-
var SIGNED_IN_SQL = compilePolicyExpression(policy.authenticated());
|
|
85
|
-
var IS_ADMIN_SQL = compilePolicyExpression(policy.rolesOverlap(["admin"]));
|
|
86
|
-
var OWNS_ROW_SQL = compilePolicyExpression(policy.compare(policy.authUid(), "eq", policy.field("uid")));
|
|
87
|
-
/**
|
|
88
|
-
* Every preset targets `TO public`, which is what the framework's generator
|
|
89
|
-
* emits and what actually reaches a request running as `rebase_user`. The part
|
|
90
|
-
* that used to be expressed as a role — "authenticated", "admin" — is a
|
|
91
|
-
* condition now, so it is enforced where Postgres will actually evaluate it.
|
|
92
|
-
*/
|
|
93
|
-
var POLICY_PRESETS = [
|
|
94
|
-
{
|
|
95
|
-
id: "public_read",
|
|
96
|
-
label: "Enable read access to everyone",
|
|
97
|
-
description: "Anyone can read data, regardless of authentication status.",
|
|
98
|
-
policyname: "Enable read access for all users",
|
|
99
|
-
cmd: "SELECT",
|
|
100
|
-
permissive: "PERMISSIVE",
|
|
101
|
-
roles: ["public"],
|
|
102
|
-
qual: "true",
|
|
103
|
-
with_check: ""
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
id: "auth_read",
|
|
107
|
-
label: "Enable read access for signed-in users only",
|
|
108
|
-
description: "Only signed-in users are allowed to read data. Anonymous requests carry a sentinel uid, so the condition excludes them explicitly.",
|
|
109
|
-
policyname: "Enable read access for signed-in users",
|
|
110
|
-
cmd: "SELECT",
|
|
111
|
-
permissive: "PERMISSIVE",
|
|
112
|
-
roles: ["public"],
|
|
113
|
-
qual: SIGNED_IN_SQL,
|
|
114
|
-
with_check: ""
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
id: "auth_insert",
|
|
118
|
-
label: "Enable insert for signed-in users only",
|
|
119
|
-
description: "Only signed-in users are allowed to insert new data.",
|
|
120
|
-
policyname: "Enable insert for signed-in users only",
|
|
121
|
-
cmd: "INSERT",
|
|
122
|
-
permissive: "PERMISSIVE",
|
|
123
|
-
roles: ["public"],
|
|
124
|
-
qual: "",
|
|
125
|
-
with_check: SIGNED_IN_SQL
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
id: "admin_all",
|
|
129
|
-
label: "Admins can do anything",
|
|
130
|
-
description: "Restricted to users holding the `admin` application role, matched inside the policy via rebase.roles().",
|
|
131
|
-
policyname: "Admins have full access",
|
|
132
|
-
cmd: "ALL",
|
|
133
|
-
permissive: "PERMISSIVE",
|
|
134
|
-
roles: ["public"],
|
|
135
|
-
qual: IS_ADMIN_SQL,
|
|
136
|
-
with_check: IS_ADMIN_SQL
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
id: "user_select_own",
|
|
140
|
-
label: "Users can read their own rows",
|
|
141
|
-
description: "Users can only read rows whose uid column matches their rebase.uid()",
|
|
142
|
-
policyname: "Users can select their own data",
|
|
143
|
-
cmd: "SELECT",
|
|
144
|
-
permissive: "PERMISSIVE",
|
|
145
|
-
roles: ["public"],
|
|
146
|
-
qual: OWNS_ROW_SQL,
|
|
147
|
-
with_check: ""
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
id: "user_update_own",
|
|
151
|
-
label: "Users can update their own rows",
|
|
152
|
-
description: "Users can only update rows whose uid column matches their rebase.uid()",
|
|
153
|
-
policyname: "Users can update their own data",
|
|
154
|
-
cmd: "UPDATE",
|
|
155
|
-
permissive: "PERMISSIVE",
|
|
156
|
-
roles: ["public"],
|
|
157
|
-
qual: OWNS_ROW_SQL,
|
|
158
|
-
with_check: OWNS_ROW_SQL
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
id: "user_delete_own",
|
|
162
|
-
label: "Users can delete their own rows",
|
|
163
|
-
description: "Users can only delete rows whose uid column matches their rebase.uid()",
|
|
164
|
-
policyname: "Users can delete their own data",
|
|
165
|
-
cmd: "DELETE",
|
|
166
|
-
permissive: "PERMISSIVE",
|
|
167
|
-
roles: ["public"],
|
|
168
|
-
qual: OWNS_ROW_SQL,
|
|
169
|
-
with_check: ""
|
|
170
|
-
}
|
|
171
|
-
];
|
|
172
|
-
//#endregion
|
|
12
|
+
import { JUNCTION_TABLES_SQL, REBASE_INTERNAL_PREFIXES, REBASE_INTERNAL_SCHEMAS, REBASE_USER_ROLE, policyToSecurityRule } from "@rebasepro/common";
|
|
173
13
|
//#region src/components/RLSEditor/PolicyEditor.tsx
|
|
174
14
|
var PolicyEditor = ({ policy, schema, table, roleOptions, onSave, onCancel }) => {
|
|
175
15
|
const { t } = useTranslation();
|
|
@@ -1009,7 +849,7 @@ function readPolicyRoles(value) {
|
|
|
1009
849
|
}
|
|
1010
850
|
return roles;
|
|
1011
851
|
}
|
|
1012
|
-
var COMMANDS = {
|
|
852
|
+
var COMMANDS$1 = {
|
|
1013
853
|
select: "SELECT",
|
|
1014
854
|
insert: "INSERT",
|
|
1015
855
|
update: "UPDATE",
|
|
@@ -1017,7 +857,7 @@ var COMMANDS = {
|
|
|
1017
857
|
all: "ALL"
|
|
1018
858
|
};
|
|
1019
859
|
function commandOf(operation) {
|
|
1020
|
-
return operation in COMMANDS ? COMMANDS[operation] : "ALL";
|
|
860
|
+
return operation in COMMANDS$1 ? COMMANDS$1[operation] : "ALL";
|
|
1021
861
|
}
|
|
1022
862
|
/** A policy the server compiled, in the shape `pg_policies` describes one. */
|
|
1023
863
|
function servedAsPostgresPolicy(served, tableName) {
|
|
@@ -1041,7 +881,7 @@ function uncompiledPolicy(rule, operation, name, tableName) {
|
|
|
1041
881
|
policyname: name,
|
|
1042
882
|
tablename: tableName,
|
|
1043
883
|
permissive: rule.mode === "restrictive" ? "RESTRICTIVE" : "PERMISSIVE",
|
|
1044
|
-
cmd: COMMANDS[operation],
|
|
884
|
+
cmd: COMMANDS$1[operation],
|
|
1045
885
|
roles: [...rule.pgRoles ?? ["public"]],
|
|
1046
886
|
qual: rule.using || null,
|
|
1047
887
|
with_check: rule.withCheck || null
|
|
@@ -1150,6 +990,406 @@ function listPolicies(live, declared, tableName) {
|
|
|
1150
990
|
return [...listed.values()];
|
|
1151
991
|
}
|
|
1152
992
|
//#endregion
|
|
993
|
+
//#region src/components/RLSEditor/DirectRlsPoliciesPanel.tsx
|
|
994
|
+
var COMMANDS = [
|
|
995
|
+
"ALL",
|
|
996
|
+
"SELECT",
|
|
997
|
+
"INSERT",
|
|
998
|
+
"UPDATE",
|
|
999
|
+
"DELETE"
|
|
1000
|
+
];
|
|
1001
|
+
var POLICY_TEMPLATES = [
|
|
1002
|
+
{
|
|
1003
|
+
labelKey: "studio_rls_direct_tpl_public_read",
|
|
1004
|
+
name: "public_read",
|
|
1005
|
+
command: "SELECT",
|
|
1006
|
+
using: "true",
|
|
1007
|
+
withCheck: ""
|
|
1008
|
+
},
|
|
1009
|
+
{
|
|
1010
|
+
labelKey: "studio_rls_direct_tpl_authenticated",
|
|
1011
|
+
name: "authenticated_all",
|
|
1012
|
+
command: "ALL",
|
|
1013
|
+
using: "rebase.uid() IS NOT NULL",
|
|
1014
|
+
withCheck: "rebase.uid() IS NOT NULL"
|
|
1015
|
+
},
|
|
1016
|
+
{
|
|
1017
|
+
labelKey: "studio_rls_direct_tpl_owner",
|
|
1018
|
+
name: "owner_all",
|
|
1019
|
+
command: "ALL",
|
|
1020
|
+
using: "user_id = rebase.uid()",
|
|
1021
|
+
withCheck: "user_id = rebase.uid()"
|
|
1022
|
+
},
|
|
1023
|
+
{
|
|
1024
|
+
labelKey: "studio_rls_direct_tpl_admin",
|
|
1025
|
+
name: "admin_all",
|
|
1026
|
+
command: "ALL",
|
|
1027
|
+
using: "'admin' = ANY(string_to_array(rebase.roles(), ','))",
|
|
1028
|
+
withCheck: "'admin' = ANY(string_to_array(rebase.roles(), ','))"
|
|
1029
|
+
}
|
|
1030
|
+
];
|
|
1031
|
+
function parsePolicy(raw) {
|
|
1032
|
+
if (!isRecord(raw) || typeof raw.name !== "string") return null;
|
|
1033
|
+
return {
|
|
1034
|
+
name: raw.name,
|
|
1035
|
+
command: asString(raw.operation ?? raw.command, "ALL"),
|
|
1036
|
+
roles: asStringArray(raw.roles),
|
|
1037
|
+
using: asNullableString(raw.using),
|
|
1038
|
+
withCheck: asNullableString(raw.withCheck)
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
function parseTable(raw) {
|
|
1042
|
+
if (!isRecord(raw) || typeof raw.name !== "string") return null;
|
|
1043
|
+
const policies = Array.isArray(raw.policies) ? raw.policies.map(parsePolicy).filter((p) => p !== null) : [];
|
|
1044
|
+
return {
|
|
1045
|
+
schema: asString(raw.schema, "public"),
|
|
1046
|
+
name: raw.name,
|
|
1047
|
+
rlsEnabled: asBoolean(raw.rlsEnabled, false),
|
|
1048
|
+
policies
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
/**
|
|
1052
|
+
* Direct PostgreSQL RLS policy manager over `/api/admin/db/tables`.
|
|
1053
|
+
* Works with zero `backend/schema` source files — every change applies live
|
|
1054
|
+
* to Postgres and reloads the data API immediately.
|
|
1055
|
+
*/
|
|
1056
|
+
function DirectRlsPoliciesPanel() {
|
|
1057
|
+
const { requestJson } = useAdminFetch();
|
|
1058
|
+
const snackbar = useSnackbarController();
|
|
1059
|
+
const { t } = useTranslation();
|
|
1060
|
+
const [tables, setTables] = useState([]);
|
|
1061
|
+
const [loading, setLoading] = useState(true);
|
|
1062
|
+
const [error, setError] = useState(null);
|
|
1063
|
+
const [selectedName, setSelectedName] = useState(null);
|
|
1064
|
+
const [dialogOpen, setDialogOpen] = useState(false);
|
|
1065
|
+
const [policyName, setPolicyName] = useState("");
|
|
1066
|
+
const [command, setCommand] = useState("ALL");
|
|
1067
|
+
const [usingExpr, setUsingExpr] = useState("rebase.uid() IS NOT NULL");
|
|
1068
|
+
const [withCheckExpr, setWithCheckExpr] = useState("");
|
|
1069
|
+
const [saving, setSaving] = useState(false);
|
|
1070
|
+
const load = useCallback(async () => {
|
|
1071
|
+
setLoading(true);
|
|
1072
|
+
setError(null);
|
|
1073
|
+
try {
|
|
1074
|
+
const raw = await requestJson("/admin/db/tables");
|
|
1075
|
+
const list = isRecord(raw) && Array.isArray(raw.tables) ? raw.tables.map(parseTable).filter((t) => t !== null) : [];
|
|
1076
|
+
setTables(list);
|
|
1077
|
+
setSelectedName((prev) => prev && list.some((t) => t.name === prev) ? prev : list[0]?.name ?? null);
|
|
1078
|
+
} catch (err) {
|
|
1079
|
+
setError(err instanceof Error ? err.message : t("studio_rls_direct_load_failed"));
|
|
1080
|
+
} finally {
|
|
1081
|
+
setLoading(false);
|
|
1082
|
+
}
|
|
1083
|
+
}, [requestJson, t]);
|
|
1084
|
+
useEffect(() => {
|
|
1085
|
+
load();
|
|
1086
|
+
}, [load]);
|
|
1087
|
+
const selected = useMemo(() => tables.find((t) => t.name === selectedName) ?? null, [tables, selectedName]);
|
|
1088
|
+
const handleToggleRls = async (enabled) => {
|
|
1089
|
+
if (!selected) return;
|
|
1090
|
+
try {
|
|
1091
|
+
await requestJson(`/admin/db/tables/${encodeURIComponent(selected.name)}`, {
|
|
1092
|
+
method: "PATCH",
|
|
1093
|
+
body: { rlsEnabled: enabled }
|
|
1094
|
+
});
|
|
1095
|
+
snackbar.open({
|
|
1096
|
+
type: "success",
|
|
1097
|
+
message: t(enabled ? "studio_tables_rls_enabled_on" : "studio_tables_rls_disabled_on", { name: selected.name })
|
|
1098
|
+
});
|
|
1099
|
+
await load();
|
|
1100
|
+
} catch (err) {
|
|
1101
|
+
snackbar.open({
|
|
1102
|
+
type: "error",
|
|
1103
|
+
message: err instanceof Error ? err.message : t("studio_rls_direct_update_failed")
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
};
|
|
1107
|
+
const handleCreatePolicy = async () => {
|
|
1108
|
+
if (!selected || !policyName.trim()) return;
|
|
1109
|
+
setSaving(true);
|
|
1110
|
+
try {
|
|
1111
|
+
await requestJson(`/admin/db/tables/${encodeURIComponent(selected.name)}/policies`, {
|
|
1112
|
+
method: "POST",
|
|
1113
|
+
body: {
|
|
1114
|
+
name: policyName.trim(),
|
|
1115
|
+
operation: command,
|
|
1116
|
+
...usingExpr.trim() ? { using: usingExpr.trim() } : {},
|
|
1117
|
+
...withCheckExpr.trim() ? { withCheck: withCheckExpr.trim() } : {}
|
|
1118
|
+
}
|
|
1119
|
+
});
|
|
1120
|
+
snackbar.open({
|
|
1121
|
+
type: "success",
|
|
1122
|
+
message: t("studio_rls_direct_policy_created", { name: policyName.trim() })
|
|
1123
|
+
});
|
|
1124
|
+
setDialogOpen(false);
|
|
1125
|
+
setPolicyName("");
|
|
1126
|
+
await load();
|
|
1127
|
+
} catch (err) {
|
|
1128
|
+
snackbar.open({
|
|
1129
|
+
type: "error",
|
|
1130
|
+
message: err instanceof Error ? err.message : t("studio_rls_direct_policy_create_failed")
|
|
1131
|
+
});
|
|
1132
|
+
} finally {
|
|
1133
|
+
setSaving(false);
|
|
1134
|
+
}
|
|
1135
|
+
};
|
|
1136
|
+
const handleDropPolicy = async (name) => {
|
|
1137
|
+
if (!selected) return;
|
|
1138
|
+
try {
|
|
1139
|
+
await requestJson(`/admin/db/tables/${encodeURIComponent(selected.name)}/policies/${encodeURIComponent(name)}`, { method: "DELETE" });
|
|
1140
|
+
snackbar.open({
|
|
1141
|
+
type: "success",
|
|
1142
|
+
message: t("studio_rls_direct_policy_dropped", { name })
|
|
1143
|
+
});
|
|
1144
|
+
await load();
|
|
1145
|
+
} catch (err) {
|
|
1146
|
+
snackbar.open({
|
|
1147
|
+
type: "error",
|
|
1148
|
+
message: err instanceof Error ? err.message : t("studio_rls_direct_policy_drop_failed")
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
};
|
|
1152
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1153
|
+
className: "flex h-full w-full overflow-hidden bg-surface-card",
|
|
1154
|
+
children: [
|
|
1155
|
+
/* @__PURE__ */ jsxs("aside", {
|
|
1156
|
+
className: cls("w-64 shrink-0 border-r bg-surface-card flex flex-col", defaultBorderMixin),
|
|
1157
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1158
|
+
className: cls("h-[42px] px-3 border-b bg-surface-sheet flex items-center justify-between shrink-0", defaultBorderMixin),
|
|
1159
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
1160
|
+
variant: "caption",
|
|
1161
|
+
className: "font-semibold uppercase tracking-wider text-text-disabled dark:text-text-disabled-dark",
|
|
1162
|
+
children: t("studio_rls_direct_tables_heading")
|
|
1163
|
+
}), /* @__PURE__ */ jsx(Tooltip, {
|
|
1164
|
+
title: t("refresh"),
|
|
1165
|
+
children: /* @__PURE__ */ jsx(IconButton, {
|
|
1166
|
+
size: "small",
|
|
1167
|
+
"aria-label": t("studio_rls_direct_refresh_aria"),
|
|
1168
|
+
onClick: () => void load(),
|
|
1169
|
+
children: /* @__PURE__ */ jsx(RefreshCwIcon, { size: iconSize.smallest })
|
|
1170
|
+
})
|
|
1171
|
+
})]
|
|
1172
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
1173
|
+
className: "flex-1 overflow-y-auto p-2 flex flex-col gap-1",
|
|
1174
|
+
children: loading ? /* @__PURE__ */ jsx("div", {
|
|
1175
|
+
className: "flex justify-center py-8",
|
|
1176
|
+
children: /* @__PURE__ */ jsx(CircularProgress, { size: "small" })
|
|
1177
|
+
}) : tables.map((table) => /* @__PURE__ */ jsxs("button", {
|
|
1178
|
+
type: "button",
|
|
1179
|
+
onClick: () => setSelectedName(table.name),
|
|
1180
|
+
className: cls("w-full text-left px-2.5 h-8 rounded-lg flex items-center justify-between gap-2 text-[13px] transition-colors cursor-pointer", table.name === selectedName ? "bg-surface-active text-text-primary dark:text-text-primary-dark font-medium" : "text-text-secondary dark:text-text-secondary-dark hover:bg-surface-hover hover:text-text-primary dark:hover:text-text-primary-dark"),
|
|
1181
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1182
|
+
className: "font-mono truncate",
|
|
1183
|
+
children: table.name
|
|
1184
|
+
}), /* @__PURE__ */ jsx(Chip, {
|
|
1185
|
+
size: "small",
|
|
1186
|
+
colorScheme: table.rlsEnabled ? "greenLight" : "grayLight",
|
|
1187
|
+
children: table.policies.length
|
|
1188
|
+
})]
|
|
1189
|
+
}, table.name))
|
|
1190
|
+
})]
|
|
1191
|
+
}),
|
|
1192
|
+
/* @__PURE__ */ jsxs("main", {
|
|
1193
|
+
className: "flex-1 flex flex-col min-w-0 h-full overflow-hidden bg-surface-sheet",
|
|
1194
|
+
children: [error && /* @__PURE__ */ jsx("div", {
|
|
1195
|
+
className: "p-5 pb-0",
|
|
1196
|
+
children: /* @__PURE__ */ jsx(Alert, {
|
|
1197
|
+
color: "error",
|
|
1198
|
+
children: error
|
|
1199
|
+
})
|
|
1200
|
+
}), !selected ? /* @__PURE__ */ jsx("div", {
|
|
1201
|
+
className: "p-5",
|
|
1202
|
+
children: /* @__PURE__ */ jsx(Card, {
|
|
1203
|
+
className: "p-8 text-center",
|
|
1204
|
+
children: /* @__PURE__ */ jsx(Typography, {
|
|
1205
|
+
variant: "body2",
|
|
1206
|
+
color: "secondary",
|
|
1207
|
+
children: t("studio_rls_direct_select_table")
|
|
1208
|
+
})
|
|
1209
|
+
})
|
|
1210
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
1211
|
+
className: cls("h-[42px] px-4 border-b bg-surface-sheet flex items-center justify-between gap-4 shrink-0", defaultBorderMixin),
|
|
1212
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1213
|
+
className: "flex items-center gap-2.5 min-w-0",
|
|
1214
|
+
children: [
|
|
1215
|
+
/* @__PURE__ */ jsx(ShieldIcon, {
|
|
1216
|
+
size: iconSize.small,
|
|
1217
|
+
className: "text-text-secondary shrink-0"
|
|
1218
|
+
}),
|
|
1219
|
+
/* @__PURE__ */ jsxs(Typography, {
|
|
1220
|
+
variant: "subtitle2",
|
|
1221
|
+
className: "font-mono truncate",
|
|
1222
|
+
children: [
|
|
1223
|
+
selected.schema,
|
|
1224
|
+
".",
|
|
1225
|
+
selected.name
|
|
1226
|
+
]
|
|
1227
|
+
}),
|
|
1228
|
+
/* @__PURE__ */ jsx(Chip, {
|
|
1229
|
+
size: "smallest",
|
|
1230
|
+
colorScheme: selected.rlsEnabled ? "greenLight" : "orangeLight",
|
|
1231
|
+
children: selected.rlsEnabled ? t("studio_rls_enabled") : t("studio_rls_disabled")
|
|
1232
|
+
})
|
|
1233
|
+
]
|
|
1234
|
+
}), /* @__PURE__ */ jsxs(Button, {
|
|
1235
|
+
size: "small",
|
|
1236
|
+
color: "primary",
|
|
1237
|
+
variant: "filled",
|
|
1238
|
+
onClick: () => setDialogOpen(true),
|
|
1239
|
+
children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.smallest }), t("studio_new_policy")]
|
|
1240
|
+
})]
|
|
1241
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1242
|
+
className: "flex-1 overflow-auto p-5 flex flex-col gap-4",
|
|
1243
|
+
children: [/* @__PURE__ */ jsx(Card, {
|
|
1244
|
+
className: "p-4",
|
|
1245
|
+
children: /* @__PURE__ */ jsx(BooleanSwitchWithLabel, {
|
|
1246
|
+
label: t("studio_rls_direct_enabled_label"),
|
|
1247
|
+
value: selected.rlsEnabled,
|
|
1248
|
+
onValueChange: (v) => void handleToggleRls(v)
|
|
1249
|
+
})
|
|
1250
|
+
}), selected.policies.length === 0 ? /* @__PURE__ */ jsxs(Card, {
|
|
1251
|
+
className: "p-8 text-center flex flex-col items-center gap-3",
|
|
1252
|
+
children: [/* @__PURE__ */ jsx(Typography, {
|
|
1253
|
+
variant: "body2",
|
|
1254
|
+
color: "secondary",
|
|
1255
|
+
children: t("studio_rls_direct_no_policies", { name: selected.name })
|
|
1256
|
+
}), /* @__PURE__ */ jsxs(Button, {
|
|
1257
|
+
size: "small",
|
|
1258
|
+
color: "primary",
|
|
1259
|
+
variant: "filled",
|
|
1260
|
+
onClick: () => setDialogOpen(true),
|
|
1261
|
+
children: [/* @__PURE__ */ jsx(PlusIcon, { size: iconSize.small }), t("studio_rls_direct_add_first_policy")]
|
|
1262
|
+
})]
|
|
1263
|
+
}) : /* @__PURE__ */ jsx("div", {
|
|
1264
|
+
className: cls("overflow-x-auto rounded-lg border", defaultBorderMixin),
|
|
1265
|
+
children: /* @__PURE__ */ jsxs(Table, {
|
|
1266
|
+
className: "w-full",
|
|
1267
|
+
children: [/* @__PURE__ */ jsxs(TableHeader, { children: [
|
|
1268
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
1269
|
+
header: true,
|
|
1270
|
+
children: t("studio_policy_name")
|
|
1271
|
+
}),
|
|
1272
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
1273
|
+
header: true,
|
|
1274
|
+
children: t("studio_rls_direct_command")
|
|
1275
|
+
}),
|
|
1276
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
1277
|
+
header: true,
|
|
1278
|
+
children: "USING"
|
|
1279
|
+
}),
|
|
1280
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
1281
|
+
header: true,
|
|
1282
|
+
children: "WITH CHECK"
|
|
1283
|
+
}),
|
|
1284
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
1285
|
+
header: true,
|
|
1286
|
+
className: "text-right",
|
|
1287
|
+
children: t("actions")
|
|
1288
|
+
})
|
|
1289
|
+
] }), /* @__PURE__ */ jsx(TableBody, { children: selected.policies.map((p) => /* @__PURE__ */ jsxs(TableRow, { children: [
|
|
1290
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
1291
|
+
className: "font-mono text-sm font-medium",
|
|
1292
|
+
children: p.name
|
|
1293
|
+
}),
|
|
1294
|
+
/* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Chip, {
|
|
1295
|
+
size: "small",
|
|
1296
|
+
colorScheme: "blueLight",
|
|
1297
|
+
children: p.command
|
|
1298
|
+
}) }),
|
|
1299
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
1300
|
+
className: "font-mono text-xs text-text-secondary",
|
|
1301
|
+
children: p.using ?? "—"
|
|
1302
|
+
}),
|
|
1303
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
1304
|
+
className: "font-mono text-xs text-text-secondary",
|
|
1305
|
+
children: p.withCheck ?? "—"
|
|
1306
|
+
}),
|
|
1307
|
+
/* @__PURE__ */ jsx(TableCell, {
|
|
1308
|
+
className: "text-right",
|
|
1309
|
+
children: /* @__PURE__ */ jsx(IconButton, {
|
|
1310
|
+
size: "small",
|
|
1311
|
+
"aria-label": t("studio_rls_direct_drop_policy_aria", { name: p.name }),
|
|
1312
|
+
onClick: () => void handleDropPolicy(p.name),
|
|
1313
|
+
children: /* @__PURE__ */ jsx(Trash2Icon, {
|
|
1314
|
+
size: iconSize.small,
|
|
1315
|
+
className: "text-red-500"
|
|
1316
|
+
})
|
|
1317
|
+
})
|
|
1318
|
+
})
|
|
1319
|
+
] }, p.name)) })]
|
|
1320
|
+
})
|
|
1321
|
+
})]
|
|
1322
|
+
})] })]
|
|
1323
|
+
}),
|
|
1324
|
+
/* @__PURE__ */ jsxs(Dialog, {
|
|
1325
|
+
open: dialogOpen,
|
|
1326
|
+
onOpenChange: setDialogOpen,
|
|
1327
|
+
maxWidth: "md",
|
|
1328
|
+
fullWidth: true,
|
|
1329
|
+
children: [
|
|
1330
|
+
/* @__PURE__ */ jsx(DialogTitle, { children: t("studio_rls_direct_new_policy_title", { name: selected?.name ?? "" }) }),
|
|
1331
|
+
/* @__PURE__ */ jsxs(DialogContent, {
|
|
1332
|
+
className: "flex flex-col gap-3",
|
|
1333
|
+
children: [
|
|
1334
|
+
/* @__PURE__ */ jsx("div", {
|
|
1335
|
+
className: "flex items-center gap-1.5 flex-wrap",
|
|
1336
|
+
children: POLICY_TEMPLATES.map((tpl) => /* @__PURE__ */ jsx(Chip, {
|
|
1337
|
+
size: "small",
|
|
1338
|
+
colorScheme: "grayLight",
|
|
1339
|
+
onClick: () => {
|
|
1340
|
+
setPolicyName(tpl.name);
|
|
1341
|
+
setCommand(tpl.command);
|
|
1342
|
+
setUsingExpr(tpl.using);
|
|
1343
|
+
setWithCheckExpr(tpl.withCheck);
|
|
1344
|
+
},
|
|
1345
|
+
children: t(tpl.labelKey)
|
|
1346
|
+
}, tpl.name))
|
|
1347
|
+
}),
|
|
1348
|
+
/* @__PURE__ */ jsx(TextField, {
|
|
1349
|
+
label: t("studio_policy_name"),
|
|
1350
|
+
value: policyName,
|
|
1351
|
+
onChange: (e) => setPolicyName(e.target.value),
|
|
1352
|
+
placeholder: "owner_all"
|
|
1353
|
+
}),
|
|
1354
|
+
/* @__PURE__ */ jsx(Select, {
|
|
1355
|
+
label: t("studio_rls_direct_command"),
|
|
1356
|
+
value: command,
|
|
1357
|
+
onValueChange: (v) => setCommand(String(v)),
|
|
1358
|
+
children: COMMANDS.map((cmd) => /* @__PURE__ */ jsx(SelectItem, {
|
|
1359
|
+
value: cmd,
|
|
1360
|
+
children: cmd
|
|
1361
|
+
}, cmd))
|
|
1362
|
+
}),
|
|
1363
|
+
/* @__PURE__ */ jsx(TextField, {
|
|
1364
|
+
label: t("studio_policy_using_expr"),
|
|
1365
|
+
value: usingExpr,
|
|
1366
|
+
onChange: (e) => setUsingExpr(e.target.value),
|
|
1367
|
+
placeholder: "user_id = rebase.uid()"
|
|
1368
|
+
}),
|
|
1369
|
+
/* @__PURE__ */ jsx(TextField, {
|
|
1370
|
+
label: t("studio_rls_direct_with_check_label"),
|
|
1371
|
+
value: withCheckExpr,
|
|
1372
|
+
onChange: (e) => setWithCheckExpr(e.target.value),
|
|
1373
|
+
placeholder: "user_id = rebase.uid()"
|
|
1374
|
+
})
|
|
1375
|
+
]
|
|
1376
|
+
}),
|
|
1377
|
+
/* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Button, {
|
|
1378
|
+
variant: "text",
|
|
1379
|
+
onClick: () => setDialogOpen(false),
|
|
1380
|
+
children: t("cancel")
|
|
1381
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
1382
|
+
variant: "filled",
|
|
1383
|
+
disabled: saving || !policyName.trim(),
|
|
1384
|
+
onClick: () => void handleCreatePolicy(),
|
|
1385
|
+
children: saving ? t("saving") : t("studio_rls_create_policy")
|
|
1386
|
+
})] })
|
|
1387
|
+
]
|
|
1388
|
+
})
|
|
1389
|
+
]
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
//#endregion
|
|
1153
1393
|
//#region src/components/RLSEditor/RLSEditor.tsx
|
|
1154
1394
|
/**
|
|
1155
1395
|
* Whether `descriptor` is the table the server declares for a live table: the
|
|
@@ -1254,6 +1494,31 @@ function SidebarTableRow({ table, isSelected, onSelect, badge, dimmed, t }) {
|
|
|
1254
1494
|
});
|
|
1255
1495
|
}
|
|
1256
1496
|
var RLSEditor = ({ apiUrl = "" }) => {
|
|
1497
|
+
const [mode, setMode] = useState("inspector");
|
|
1498
|
+
const { t } = useTranslation();
|
|
1499
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1500
|
+
className: "flex flex-col h-full w-full overflow-hidden",
|
|
1501
|
+
children: [/* @__PURE__ */ jsxs(Tabs, {
|
|
1502
|
+
value: mode,
|
|
1503
|
+
onValueChange: (v) => {
|
|
1504
|
+
if (v === "inspector" || v === "direct") setMode(v);
|
|
1505
|
+
},
|
|
1506
|
+
variant: "boxy",
|
|
1507
|
+
className: "border-b border-hairline px-4 bg-surface-sheet shrink-0",
|
|
1508
|
+
children: [/* @__PURE__ */ jsx(Tab, {
|
|
1509
|
+
value: "inspector",
|
|
1510
|
+
children: t("studio_rls_tab_inspector")
|
|
1511
|
+
}), /* @__PURE__ */ jsx(Tab, {
|
|
1512
|
+
value: "direct",
|
|
1513
|
+
children: t("studio_rls_tab_direct")
|
|
1514
|
+
})]
|
|
1515
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
1516
|
+
className: "flex-1 min-h-0 overflow-hidden",
|
|
1517
|
+
children: mode === "direct" ? /* @__PURE__ */ jsx(DirectRlsPoliciesPanel, {}) : /* @__PURE__ */ jsx(RLSEditorInspector, { apiUrl })
|
|
1518
|
+
})]
|
|
1519
|
+
});
|
|
1520
|
+
};
|
|
1521
|
+
var RLSEditorInspector = ({ apiUrl = "" }) => {
|
|
1257
1522
|
const { databaseAdmin } = useRebaseContext();
|
|
1258
1523
|
const snackbarController = useSnackbarController();
|
|
1259
1524
|
const descriptors = useTableDescriptors();
|
|
@@ -1651,36 +1916,32 @@ var RLSEditor = ({ apiUrl = "" }) => {
|
|
|
1651
1916
|
minPanelSizePx: 220,
|
|
1652
1917
|
firstPanel: /* @__PURE__ */ jsxs("div", {
|
|
1653
1918
|
className: cls("flex flex-col h-full w-full bg-surface-card border-r", defaultBorderMixin),
|
|
1654
|
-
children: [/* @__PURE__ */ jsxs(
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
children:
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1919
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1920
|
+
className: cls("flex items-center justify-between pl-2 pr-2 border-b bg-surface-sheet shrink-0", defaultBorderMixin),
|
|
1921
|
+
children: [/* @__PURE__ */ jsxs(Tabs, {
|
|
1922
|
+
value: sidebarTab,
|
|
1923
|
+
onValueChange: (v) => setSidebarTab(v),
|
|
1924
|
+
variant: "boxy",
|
|
1925
|
+
className: "w-[unset] flex-shrink-0",
|
|
1926
|
+
children: [/* @__PURE__ */ jsx(Tab, {
|
|
1927
|
+
value: "tables",
|
|
1928
|
+
children: "Tables"
|
|
1929
|
+
}), /* @__PURE__ */ jsx(Tab, {
|
|
1930
|
+
value: "info",
|
|
1931
|
+
children: "Info"
|
|
1932
|
+
})]
|
|
1933
|
+
}), /* @__PURE__ */ jsx(IconButton, {
|
|
1934
|
+
"aria-label": t("refresh"),
|
|
1935
|
+
size: "small",
|
|
1936
|
+
onClick: fetchRLSData,
|
|
1937
|
+
title: t("refresh"),
|
|
1938
|
+
children: /* @__PURE__ */ jsx(RefreshCwIcon, { size: iconSize.smallest })
|
|
1665
1939
|
})]
|
|
1666
1940
|
}), /* @__PURE__ */ jsxs("div", {
|
|
1667
1941
|
className: "flex-grow overflow-hidden relative",
|
|
1668
|
-
children: [sidebarTab === "tables" && /* @__PURE__ */
|
|
1942
|
+
children: [sidebarTab === "tables" && /* @__PURE__ */ jsx("div", {
|
|
1669
1943
|
className: "flex flex-col h-full",
|
|
1670
|
-
children:
|
|
1671
|
-
className: cls("flex items-center justify-between px-3 py-2 border-b bg-surface-sheet min-h-[48px]", defaultBorderMixin),
|
|
1672
|
-
children: [/* @__PURE__ */ jsx(Typography, {
|
|
1673
|
-
variant: "caption",
|
|
1674
|
-
className: "font-semibold uppercase tracking-wider text-text-disabled dark:text-text-disabled-dark",
|
|
1675
|
-
children: t("studio_schema_tables")
|
|
1676
|
-
}), /* @__PURE__ */ jsx(IconButton, {
|
|
1677
|
-
"aria-label": t("refresh"),
|
|
1678
|
-
size: "small",
|
|
1679
|
-
onClick: fetchRLSData,
|
|
1680
|
-
title: t("refresh"),
|
|
1681
|
-
children: /* @__PURE__ */ jsx(RefreshCwIcon, { size: iconSize.smallest })
|
|
1682
|
-
})]
|
|
1683
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
1944
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1684
1945
|
className: "flex-grow overflow-y-auto no-scrollbar p-1",
|
|
1685
1946
|
children: isLoading && tables.length === 0 ? /* @__PURE__ */ jsx("div", {
|
|
1686
1947
|
className: "flex justify-center p-4",
|
|
@@ -1693,8 +1954,8 @@ var RLSEditor = ({ apiUrl = "" }) => {
|
|
|
1693
1954
|
children: t("studio_rls_no_tables")
|
|
1694
1955
|
})
|
|
1695
1956
|
}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1696
|
-
categorizedTables.collection.length > 0 && /* @__PURE__ */
|
|
1697
|
-
title: "
|
|
1957
|
+
(categorizedTables.collection.length > 0 || categorizedTables.junction.length > 0) && /* @__PURE__ */ jsxs(SidebarSection, {
|
|
1958
|
+
title: t("studio_rls_served_tables"),
|
|
1698
1959
|
icon: /* @__PURE__ */ jsx(DatabaseIcon, {
|
|
1699
1960
|
size: 12,
|
|
1700
1961
|
className: "text-primary dark:text-primary-light"
|
|
@@ -1704,15 +1965,22 @@ var RLSEditor = ({ apiUrl = "" }) => {
|
|
|
1704
1965
|
...prev,
|
|
1705
1966
|
collection: !(prev.collection ?? true)
|
|
1706
1967
|
})),
|
|
1707
|
-
children: categorizedTables.collection.map((table) => /* @__PURE__ */ jsx(SidebarTableRow, {
|
|
1968
|
+
children: [categorizedTables.collection.map((table) => /* @__PURE__ */ jsx(SidebarTableRow, {
|
|
1708
1969
|
table,
|
|
1709
1970
|
isSelected: selectedTable === `${table.schemaName}.${table.tableName}`,
|
|
1710
1971
|
onSelect: () => setSelectedTable(`${table.schemaName}.${table.tableName}`),
|
|
1711
1972
|
t
|
|
1712
|
-
}, `${table.schemaName}.${table.tableName}`))
|
|
1973
|
+
}, `${table.schemaName}.${table.tableName}`)), categorizedTables.junction.map((table) => /* @__PURE__ */ jsx(SidebarTableRow, {
|
|
1974
|
+
table,
|
|
1975
|
+
isSelected: selectedTable === `${table.schemaName}.${table.tableName}`,
|
|
1976
|
+
onSelect: () => setSelectedTable(`${table.schemaName}.${table.tableName}`),
|
|
1977
|
+
badge: "Junction",
|
|
1978
|
+
dimmed: true,
|
|
1979
|
+
t
|
|
1980
|
+
}, `${table.schemaName}.${table.tableName}`))]
|
|
1713
1981
|
}),
|
|
1714
|
-
|
|
1715
|
-
title: "
|
|
1982
|
+
categorizedTables.other.length > 0 && /* @__PURE__ */ jsx(SidebarSection, {
|
|
1983
|
+
title: "Not served",
|
|
1716
1984
|
icon: /* @__PURE__ */ jsx(AlertTriangleIcon, {
|
|
1717
1985
|
size: 12,
|
|
1718
1986
|
className: "text-yellow-500 dark:text-yellow-400"
|
|
@@ -1722,19 +1990,12 @@ var RLSEditor = ({ apiUrl = "" }) => {
|
|
|
1722
1990
|
...prev,
|
|
1723
1991
|
other: !(prev.other ?? true)
|
|
1724
1992
|
})),
|
|
1725
|
-
children:
|
|
1726
|
-
table,
|
|
1727
|
-
isSelected: selectedTable === `${table.schemaName}.${table.tableName}`,
|
|
1728
|
-
onSelect: () => setSelectedTable(`${table.schemaName}.${table.tableName}`),
|
|
1729
|
-
t
|
|
1730
|
-
}, `${table.schemaName}.${table.tableName}`)), categorizedTables.junction.map((table) => /* @__PURE__ */ jsx(SidebarTableRow, {
|
|
1993
|
+
children: categorizedTables.other.map((table) => /* @__PURE__ */ jsx(SidebarTableRow, {
|
|
1731
1994
|
table,
|
|
1732
1995
|
isSelected: selectedTable === `${table.schemaName}.${table.tableName}`,
|
|
1733
1996
|
onSelect: () => setSelectedTable(`${table.schemaName}.${table.tableName}`),
|
|
1734
|
-
badge: "Junction",
|
|
1735
|
-
dimmed: true,
|
|
1736
1997
|
t
|
|
1737
|
-
}, `${table.schemaName}.${table.tableName}`))
|
|
1998
|
+
}, `${table.schemaName}.${table.tableName}`))
|
|
1738
1999
|
}),
|
|
1739
2000
|
categorizedTables.internal.length > 0 && /* @__PURE__ */ jsx(SidebarSection, {
|
|
1740
2001
|
title: "Rebase Internal",
|
|
@@ -1757,17 +2018,10 @@ var RLSEditor = ({ apiUrl = "" }) => {
|
|
|
1757
2018
|
}, `${table.schemaName}.${table.tableName}`))
|
|
1758
2019
|
})
|
|
1759
2020
|
] })
|
|
1760
|
-
})
|
|
1761
|
-
}), sidebarTab === "info" && /* @__PURE__ */
|
|
2021
|
+
})
|
|
2022
|
+
}), sidebarTab === "info" && /* @__PURE__ */ jsx("div", {
|
|
1762
2023
|
className: "flex flex-col h-full",
|
|
1763
|
-
children:
|
|
1764
|
-
className: cls("flex items-center justify-between px-3 py-2 border-b bg-surface-sheet min-h-[48px]", defaultBorderMixin),
|
|
1765
|
-
children: /* @__PURE__ */ jsx(Typography, {
|
|
1766
|
-
variant: "caption",
|
|
1767
|
-
className: "font-semibold uppercase tracking-wider text-text-disabled dark:text-text-disabled-dark",
|
|
1768
|
-
children: "Overview"
|
|
1769
|
-
})
|
|
1770
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
2024
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
1771
2025
|
className: "flex-grow overflow-y-auto p-3 space-y-3 no-scrollbar",
|
|
1772
2026
|
children: [
|
|
1773
2027
|
/* @__PURE__ */ jsxs("div", {
|
|
@@ -1808,7 +2062,7 @@ var RLSEditor = ({ apiUrl = "" }) => {
|
|
|
1808
2062
|
children: [/* @__PURE__ */ jsx(Typography, {
|
|
1809
2063
|
variant: "caption",
|
|
1810
2064
|
className: "text-text-secondary dark:text-text-secondary-dark text-xs",
|
|
1811
|
-
children: "
|
|
2065
|
+
children: t("studio_rls_enabled")
|
|
1812
2066
|
}), /* @__PURE__ */ jsxs("div", {
|
|
1813
2067
|
className: "flex items-center gap-1.5",
|
|
1814
2068
|
children: [/* @__PURE__ */ jsx("div", { className: "w-1.5 h-1.5 rounded-full bg-green-500" }), /* @__PURE__ */ jsx(Typography, {
|
|
@@ -1885,14 +2139,14 @@ var RLSEditor = ({ apiUrl = "" }) => {
|
|
|
1885
2139
|
})] })]
|
|
1886
2140
|
})
|
|
1887
2141
|
]
|
|
1888
|
-
})
|
|
2142
|
+
})
|
|
1889
2143
|
})]
|
|
1890
2144
|
})]
|
|
1891
2145
|
}),
|
|
1892
2146
|
secondPanel: /* @__PURE__ */ jsxs("div", {
|
|
1893
2147
|
className: "flex-grow flex flex-col min-w-0 h-full w-full bg-surface-card",
|
|
1894
2148
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
1895
|
-
className: cls("flex items-center justify-between pr-2 border-b bg-surface-
|
|
2149
|
+
className: cls("flex items-center justify-between pr-2 border-b bg-surface-sheet h-[42px] shrink-0", defaultBorderMixin),
|
|
1896
2150
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
1897
2151
|
className: "flex items-center flex-grow overflow-hidden px-4",
|
|
1898
2152
|
children: [/* @__PURE__ */ jsx(Typography, {
|
|
@@ -2106,7 +2360,7 @@ var RLSEditor = ({ apiUrl = "" }) => {
|
|
|
2106
2360
|
}), /* @__PURE__ */ jsx(Typography, {
|
|
2107
2361
|
variant: "caption",
|
|
2108
2362
|
className: "opacity-80",
|
|
2109
|
-
children: "This is an auto-generated junction table for a many-to-many relation. Rebase derives its policies: rows are readable when both related rows are, and writable following the declaring
|
|
2363
|
+
children: "This is an auto-generated junction table for a many-to-many relation. Rebase derives its policies: rows are readable when both related rows are, and writable following the declaring table's update rules (plus the server/admin baseline). You can still add RLS policies directly to broaden access."
|
|
2110
2364
|
})] })
|
|
2111
2365
|
})
|
|
2112
2366
|
}),
|
|
@@ -2315,4 +2569,4 @@ var RLSEditor = ({ apiUrl = "" }) => {
|
|
|
2315
2569
|
//#endregion
|
|
2316
2570
|
export { RLSEditor };
|
|
2317
2571
|
|
|
2318
|
-
//# sourceMappingURL=RLSEditor-
|
|
2572
|
+
//# sourceMappingURL=RLSEditor-CTG3jLE7.js.map
|