@rebasepro/studio 0.35.1 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{ApiExplorer-C61w8gCc.js → ApiExplorer-BVQHAjHB.js} +3 -2
- package/dist/{ApiExplorer-C61w8gCc.js.map → ApiExplorer-BVQHAjHB.js.map} +1 -1
- package/dist/{useRunAsUsers-CF7tkGzj.js → AuthSimulationSelector-XogpkeXC.js} +4 -68
- package/dist/AuthSimulationSelector-XogpkeXC.js.map +1 -0
- package/dist/{CronJobsView-DUuyzkJK.js → CronJobsView-DyX9MINh.js} +2 -2
- package/dist/{CronJobsView-DUuyzkJK.js.map → CronJobsView-DyX9MINh.js.map} +1 -1
- package/dist/DatabaseView-Bi0NZS90.js +1897 -0
- package/dist/DatabaseView-Bi0NZS90.js.map +1 -0
- package/dist/{JSEditor-Bi2Aol-Y.js → JSEditor-B4Lazm-z.js} +4 -3
- package/dist/{JSEditor-Bi2Aol-Y.js.map → JSEditor-B4Lazm-z.js.map} +1 -1
- package/dist/RLSEditor-CcHkWFNg.js +973 -0
- package/dist/RLSEditor-CcHkWFNg.js.map +1 -0
- package/dist/{SQLEditor-DRo5kW1h.js → SQLEditorRoute-f5j_ZKdj.js} +1472 -320
- package/dist/SQLEditorRoute-f5j_ZKdj.js.map +1 -0
- package/dist/SchemaDiagramView-CckQobIZ.js +98 -0
- package/dist/SchemaDiagramView-CckQobIZ.js.map +1 -0
- package/dist/{StorageView-D0D8z4lI.js → StorageView-DQEIDFvO.js} +592 -447
- package/dist/StorageView-DQEIDFvO.js.map +1 -0
- package/dist/TableEditorView-BRZNvD6U.js +3615 -0
- package/dist/TableEditorView-BRZNvD6U.js.map +1 -0
- package/dist/TablePolicies-C1-tbC8x.js +1740 -0
- package/dist/TablePolicies-C1-tbC8x.js.map +1 -0
- package/dist/{SchemaVisualizer-Dy4kWKT5.js → TablesDiagram-RTJfwVEN.js} +651 -489
- package/dist/TablesDiagram-RTJfwVEN.js.map +1 -0
- package/dist/{UsersAndRolesView-CKw4SJPj.js → UsersAndRolesView-Cx6xtMVH.js} +2 -2
- package/dist/{UsersAndRolesView-CKw4SJPj.js.map → UsersAndRolesView-Cx6xtMVH.js.map} +1 -1
- package/dist/{WebhooksView-CFPY-N9h.js → WebhooksView-Bn9KB7xG.js} +2 -2
- package/dist/{WebhooksView-CFPY-N9h.js.map → WebhooksView-Bn9KB7xG.js.map} +1 -1
- package/dist/{adminFetch-BfOnfRgU.js → adminFetch-C7Ra8rpP.js} +26 -1
- package/dist/{adminFetch-BfOnfRgU.js.map → adminFetch-C7Ra8rpP.js.map} +1 -1
- package/dist/components/Database/ActivitySection.d.ts +9 -0
- package/dist/components/Database/AdvisorsSection.d.ts +17 -0
- package/dist/components/Database/DatabaseView.d.ts +13 -0
- package/dist/components/Database/ExtensionsSection.d.ts +2 -0
- package/dist/components/Database/FunctionsSection.d.ts +2 -0
- package/dist/components/Database/QueriesSection.d.ts +3 -0
- package/dist/components/Database/TriggersSection.d.ts +2 -0
- package/dist/components/Database/TypesSection.d.ts +2 -0
- package/dist/components/Database/format.d.ts +6 -0
- package/dist/components/Database/links.d.ts +11 -0
- package/dist/components/Database/shared.d.ts +35 -0
- package/dist/components/Database/source.d.ts +12 -0
- package/dist/components/Database/useCatalogList.d.ts +13 -0
- package/dist/components/RLSEditor/RLSEditor.d.ts +2 -0
- package/dist/components/RLSEditor/TablePolicies.d.ts +54 -0
- package/dist/components/SQLEditor/ExplainVisualizer.d.ts +8 -20
- package/dist/components/SQLEditor/ResultChart.d.ts +18 -0
- package/dist/components/SQLEditor/SQLEditor.d.ts +13 -1
- package/dist/components/SQLEditor/SQLEditorRoute.d.ts +13 -0
- package/dist/components/SQLEditor/SQLEditorSidebar.d.ts +7 -1
- package/dist/components/SQLEditor/SqlParamsPanel.d.ts +16 -0
- package/dist/components/SQLEditor/useSqlSnippets.d.ts +47 -0
- package/dist/components/SchemaVisualizer/SchemaDiagramView.d.ts +12 -0
- package/dist/components/SchemaVisualizer/TablesDiagram.d.ts +23 -0
- package/dist/components/SchemaVisualizer/useSchemaGraph.d.ts +32 -1
- package/dist/components/StorageView/StorageView.d.ts +5 -0
- package/dist/components/TableEditor/CreateTableDialog.d.ts +8 -0
- package/dist/components/TableEditor/DdlConfirm.d.ts +23 -0
- package/dist/components/TableEditor/SqlBlock.d.ts +7 -0
- package/dist/components/TableEditor/TableDdlSheet.d.ts +9 -0
- package/dist/components/TableEditor/TableEditorView.d.ts +7 -0
- package/dist/components/TableEditor/tableModel.d.ts +210 -0
- package/dist/components/TableEditor/tabs/DataTab.d.ts +12 -0
- package/dist/components/TableEditor/tabs/PoliciesTab.d.ts +8 -0
- package/dist/components/TableEditor/tabs/RelationsTab.d.ts +8 -0
- package/dist/components/TableEditor/tabs/SettingsTab.d.ts +11 -0
- package/dist/components/TableEditor/tabs/StatsTab.d.ts +8 -0
- package/dist/components/TableEditor/tabs/StructureTab.d.ts +12 -0
- package/dist/index.es.js +29 -15
- package/dist/index.es.js.map +1 -1
- package/dist/{sql_utils-CYcgpgam.js → sql_utils-DkMYltfq.js} +27 -3
- package/dist/sql_utils-DkMYltfq.js.map +1 -0
- package/dist/useRunAsUsers-GPFCxcBC.js +69 -0
- package/dist/useRunAsUsers-GPFCxcBC.js.map +1 -0
- package/dist/utils/adminFetch.d.ts +1 -0
- package/dist/utils/csv_parse.d.ts +11 -0
- package/dist/utils/explain_plan.d.ts +70 -0
- package/dist/utils/sql_params.d.ts +51 -0
- package/dist/utils/sql_utils.d.ts +16 -0
- package/package.json +11 -9
- package/dist/RLSEditor-CTG3jLE7.js +0 -2572
- package/dist/RLSEditor-CTG3jLE7.js.map +0 -1
- package/dist/SQLEditor-DRo5kW1h.js.map +0 -1
- package/dist/SchemaVisualizer-Dy4kWKT5.js.map +0 -1
- package/dist/StorageView-D0D8z4lI.js.map +0 -1
- package/dist/TableEditorView-BKhSBG-K.js +0 -1694
- package/dist/TableEditorView-BKhSBG-K.js.map +0 -1
- package/dist/components/SchemaVisualizer/SchemaVisualizer.d.ts +0 -3
- package/dist/policy-presets-CJKzAvQp.js +0 -167
- package/dist/policy-presets-CJKzAvQp.js.map +0 -1
- package/dist/sql_utils-CYcgpgam.js.map +0 -1
- package/dist/useRunAsUsers-CF7tkGzj.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TablePolicies-C1-tbC8x.js","names":[],"sources":["../src/components/RLSEditor/policyListing.ts","../src/components/RLSEditor/policy-presets.ts","../src/components/RLSEditor/PolicyEditor.tsx","../src/components/RLSEditor/saveSecurityRules.ts","../src/components/RLSEditor/saveRules.ts","../src/components/RLSEditor/policyRules.ts","../src/components/RLSEditor/TablePolicies.tsx"],"sourcesContent":["import { isRedactedSecurityRule, REBASE_ADMIN_REQUEST_ROLE, REBASE_ADMIN_ROLE } from \"@rebasepro/types\";\nimport type { PolicyDescriptor, PostgresPolicy, RlsDescriptor, SecurityOperation, SecurityRule } from \"@rebasepro/types\";\nimport { getPolicyNamesForRule, getPolicyOperations } from \"@rebasepro/utils\";\n\n/** A part of a policy the database can hold differently from its declaration. */\nexport type PolicyDriftField = \"roles\" | \"command\" | \"mode\" | \"USING\" | \"WITH CHECK\";\n\n/** A row of the RLS editor's policy list. */\nexport interface ListedPolicy extends PostgresPolicy {\n /**\n * What the server compiles this policy to, when the table declares one by\n * this name. For a policy the database also has, the row's own fields are\n * the database's and this is what they are compared against.\n */\n declared?: PostgresPolicy;\n /** Where the database's policy differs from {@link declared}. Empty when it does not. */\n drift?: PolicyDriftField[];\n /**\n * Rebase adds this policy itself — the admin baseline, a tenancy or\n * auth-write gate, a junction's derived policies, an admin-request\n * companion — so no rule of the author's holds it, and the next server\n * start re-creates it.\n */\n generated?: boolean;\n /** The index in the table's declared `rls.rules` of the rule this policy compiles from. */\n rule?: number;\n}\n\n/**\n * The roles of a `pg_policies` row, from its `roles` column.\n *\n * A driver hands a `name[]` back as an array or as Postgres's text for one:\n * `{public}`, `{anon,authenticated}`, and with an element quoted — a `\"` or\n * `\\` in it escaped by a backslash — when it holds a comma, a brace, a quote,\n * a backslash or a space: `{\"my role\",anon}`. Split on commas, that last one\n * reads as the role `\"my role\"`, quotes and all: the policy shows drift that\n * is not there, and an edit of it names a role that does not exist.\n */\nexport function readPolicyRoles(value: unknown): string[] {\n if (Array.isArray(value)) return value.filter((role): role is string => typeof role === \"string\");\n if (typeof value !== \"string\") return [];\n const body = value.trim().replace(/^\\{/, \"\").replace(/\\}$/, \"\");\n const roles: string[] = [];\n let i = 0;\n while (i < body.length) {\n if (body[i] === \"\\\"\") {\n let role = \"\";\n i++;\n while (i < body.length && body[i] !== \"\\\"\") {\n if (body[i] === \"\\\\\") i++;\n role += body[i] ?? \"\";\n i++;\n }\n roles.push(role);\n i++;\n } else {\n const comma = body.indexOf(\",\", i);\n const end = comma === -1 ? body.length : comma;\n const role = body.slice(i, end).trim();\n if (role) roles.push(role);\n i = end;\n }\n // Past the comma that ends this element, if there is one.\n while (i < body.length && body[i] !== \",\") i++;\n i++;\n }\n return roles;\n}\n\nconst COMMANDS: Record<SecurityOperation, PostgresPolicy[\"cmd\"]> = {\n select: \"SELECT\",\n insert: \"INSERT\",\n update: \"UPDATE\",\n delete: \"DELETE\",\n all: \"ALL\"\n};\n\nfunction commandOf(operation: string): PostgresPolicy[\"cmd\"] {\n return operation in COMMANDS ? COMMANDS[operation as SecurityOperation] : \"ALL\";\n}\n\n/** A policy the server compiled, in the shape `pg_policies` describes one. */\nexport function servedAsPostgresPolicy(served: PolicyDescriptor, tableName: string): PostgresPolicy {\n return {\n policyname: served.name,\n tablename: tableName,\n permissive: served.mode === \"restrictive\" ? \"RESTRICTIVE\" : \"PERMISSIVE\",\n cmd: commandOf(served.operation),\n roles: [...served.roles],\n qual: served.using,\n with_check: served.withCheck\n };\n}\n\n/**\n * The rule's own clauses, for a declared rule the server compiled no policy\n * from — an `existsIn` naming a table the backend does not hold, say. Only\n * ever a `code_only` row's content: nothing is compared against it.\n */\nfunction uncompiledPolicy(rule: SecurityRule, operation: SecurityOperation, name: string, tableName: string): PostgresPolicy {\n return {\n policyname: name,\n tablename: tableName,\n permissive: rule.mode === \"restrictive\" ? \"RESTRICTIVE\" : \"PERMISSIVE\",\n cmd: COMMANDS[operation],\n roles: [...(rule.pgRoles ?? [\"public\"])],\n qual: rule.using || null,\n with_check: rule.withCheck || null\n };\n}\n\nfunction sameRoles(a: readonly string[], b: readonly string[]): boolean {\n const left = [...a].sort();\n const right = [...b].sort();\n return left.length === right.length && left.every((role, i) => role === right[i]);\n}\n\n/**\n * Where a live policy differs from the one the code compiles to.\n *\n * The same comparison `rebase doctor` makes: the `TO` list, the command, the\n * mode, and whether each clause is there at all. Never the clause text —\n * Postgres rewrites an expression when it stores it, so the text of a policy\n * that matches its declaration exactly still differs from the declaration's.\n * A clause that is missing is not a rewrite, though: a `USING` that is gone\n * changes who the policy admits.\n */\nexport function policyDrift(declared: PostgresPolicy, live: PostgresPolicy): PolicyDriftField[] {\n const drift: PolicyDriftField[] = [];\n if (!sameRoles(declared.roles, live.roles)) drift.push(\"roles\");\n if (declared.cmd !== live.cmd) drift.push(\"command\");\n if (declared.permissive !== live.permissive) drift.push(\"mode\");\n if ((declared.qual != null) !== (live.qual != null)) drift.push(\"USING\");\n if ((declared.with_check != null) !== (live.with_check != null)) drift.push(\"WITH CHECK\");\n return drift;\n}\n\n/**\n * What the server says a table's policies are: its declared rules and the\n * policies it compiled from them, or — for a junction — the derived policies\n * alone. `undefined` when the table is not one the server declares, or when it\n * withheld the compiled policies from this caller (no `schema:read`).\n */\nexport interface DeclaredPolicies {\n /** The declared rules, as written; empty for a junction. */\n rules: readonly SecurityRule[];\n /** Every policy the server compiles for the table. */\n policies: readonly PolicyDescriptor[];\n}\n\n/** The {@link DeclaredPolicies} of a served table, when the server included its compiled policies. */\nexport function declaredPoliciesOf(rls: RlsDescriptor): DeclaredPolicies | undefined {\n return rls.policies ? { rules: rls.rules, policies: rls.policies } : undefined;\n}\n\n/**\n * The policies of one table: every policy the database has, as the database\n * has it, and every policy the server compiles for the table that it does not.\n *\n * The server is the one compiler: what it serves in `rls.policies` (and\n * `rls.junctions`) is exactly what `db push` and every server start write.\n * This only compares it with `pg_policies`. A policy in both keeps the\n * database's fields — this list is what Postgres enforces — and carries the\n * declaration beside them, with where the two differ.\n *\n * @param live The table's `pg_policies` rows.\n * @param declared What the server serves for the table, if anything.\n */\nexport function listPolicies(\n live: readonly PostgresPolicy[],\n declared: DeclaredPolicies | undefined,\n tableName: string\n): ListedPolicy[] {\n const listed = new Map<string, ListedPolicy>();\n for (const policy of live) listed.set(policy.policyname, { ...policy, status: \"live\" });\n if (!declared) return [...listed.values()];\n\n const livePolicies = new Map(live.map(policy => [policy.policyname, policy]));\n const compiledRules = new Set<number>();\n\n for (const served of declared.policies) {\n if (served.rule !== undefined) compiledRules.add(served.rule);\n const existing = livePolicies.get(served.name);\n // The `TO rebase_admin_request USING (true)` companion a server writes\n // beside an admin-only policy where it made that role safe: Rebase's,\n // and compared like any declared policy when it is there. Not listed\n // when absent — a server that cannot make the role safe writes none.\n if (served.roles.includes(REBASE_ADMIN_REQUEST_ROLE) && !existing) continue;\n const compiled = servedAsPostgresPolicy(served, tableName);\n // A policy compiled TO rebase_admin is written TO public by a server\n // whose admin switch is not live — its documented fallback, not drift.\n // Only that one form is accepted.\n const fellBack = existing !== undefined && sameRoles(compiled.roles, [REBASE_ADMIN_ROLE]) && sameRoles(existing.roles, [\"public\"]);\n const declaredPolicy = fellBack ? { ...compiled, roles: [\"public\"] } : compiled;\n const rule = served.rule !== undefined ? { rule: served.rule } : {};\n if (existing) {\n listed.set(served.name, {\n ...existing,\n status: \"both\",\n declared: declaredPolicy,\n drift: policyDrift(declaredPolicy, existing),\n generated: served.injected,\n ...rule\n });\n } else {\n listed.set(served.name, { ...declaredPolicy, status: \"code_only\", generated: served.injected, ...rule });\n }\n }\n\n // A declared rule the server compiled nothing from still belongs in the\n // list: the code declares it, and the database cannot have it.\n declared.rules.forEach((rule, index) => {\n if (compiledRules.has(index) || isRedactedSecurityRule(rule)) return;\n const operations = getPolicyOperations(rule);\n getPolicyNamesForRule(rule, tableName).forEach((name: string, position: number) => {\n const existing = listed.get(name);\n if (existing) {\n // In the database under its name: nothing compiled to compare it with.\n if (existing.status === \"live\") listed.set(name, { ...existing, status: \"both\", generated: false, rule: index });\n return;\n }\n listed.set(name, {\n ...uncompiledPolicy(rule, operations[position] ?? \"all\", name, tableName),\n status: \"code_only\",\n generated: false,\n rule: index\n });\n });\n });\n\n return [...listed.values()];\n}\n","/**\n * What the RLS editor offers before the user types anything: the roles a `TO`\n * list may name, and the ready-made policies.\n *\n * Separated from the component because these are the parts that have to agree\n * with the *server*, not with the UI — and the ways they can silently disagree\n * are the reason this file has tests.\n */\nimport { policy as policyExpr } from \"@rebasepro/types\";\nimport { compilePolicyExpression, REBASE_USER_ROLE } from \"@rebasepro/common\";\n\nexport type PolicyCommand = \"ALL\" | \"SELECT\" | \"INSERT\" | \"UPDATE\" | \"DELETE\";\n\nexport const COMMAND_OPTIONS: PolicyCommand[] = [\"ALL\", \"SELECT\", \"INSERT\", \"UPDATE\", \"DELETE\"];\n\n/**\n * The roles a policy's `TO` list can name when nothing better is known.\n *\n * Not `authenticated` / `anon` / `admin`, which is what this list used to be.\n * The first two are Supabase's role names and Rebase never creates them, so\n * `CREATE POLICY ... TO authenticated` — which is literally what the editor\n * builds and executes — fails with `role \"authenticated\" does not exist`. The\n * driver's `validatePolicyPgRoles` rejects the same three names in\n * `SecurityRule.pgRoles` and says why: they are another platform's convention,\n * and application roles belong in a condition, not in the `TO` list.\n *\n * `admin` was the more dangerous entry, because it is a plausible *application*\n * role. Had one existed as a database role too, the policy would have been\n * created successfully and then matched nothing at all: requests run as\n * {@link REBASE_USER_ROLE} after a `SET LOCAL ROLE`, and a `TO` list naming a\n * role the request never assumes filters every row without erroring.\n *\n * So: `public` (what the framework's own generator emits) and the role requests\n * actually arrive as. \"Signed-in users\" and \"admins\" are not roles here — they\n * are conditions over `rebase.uid()` and `rebase.roles()`, which is what the\n * presets below now compile to.\n */\nexport const FALLBACK_ROLE_OPTIONS = [\"public\", REBASE_USER_ROLE];\n\n/**\n * The `TO` list the editor offers, given what the database reported and what\n * the policy being edited already targets.\n *\n * Three sources, and each is there for a reason the others do not cover:\n *\n * - {@link FALLBACK_ROLE_OPTIONS} always, because `public` is a **keyword, not\n * a row in `pg_roles`** — `fetchAvailableRoles` cannot return it, so seeding\n * from the live fetch alone would drop the one role every generated policy\n * targets.\n * - the live roles, so an operator's own `app_read` is reachable without\n * hand-editing SQL.\n * - the edited policy's own roles, because a `MultiSelect` silently drops a\n * value with no matching item. That value is the `TO` list of a policy\n * already enforcing something, so opening an unrelated policy for a one-word\n * rename would have quietly rewritten who it applies to.\n */\nexport function roleOptionsFor(\n fetched: readonly string[] | undefined,\n policyRoles: readonly string[] | undefined\n): string[] {\n return [...new Set([...FALLBACK_ROLE_OPTIONS, ...(fetched ?? []), ...(policyRoles ?? [])])];\n}\n\n/**\n * Preset conditions, compiled by the framework's own policy compiler rather\n * than written out here.\n *\n * `compilePolicyExpression` is the function `db push` generates policies with, so a\n * preset cannot drift from what the framework emits — and the one that matters\n * has drifted before: `authenticated()` used to compile to a bare\n * `IS NOT NULL`, which is true for anonymous visitors, and any copy of that\n * string sitting in a preset would still be handing out the old grant today.\n */\nexport const SIGNED_IN_SQL = compilePolicyExpression(policyExpr.authenticated());\nexport const IS_ADMIN_SQL = compilePolicyExpression(policyExpr.rolesOverlap([\"admin\"]));\nexport const OWNS_ROW_SQL = compilePolicyExpression(\n policyExpr.compare(policyExpr.authUid(), \"eq\", policyExpr.field(\"uid\"))\n);\n\nexport interface PolicyPreset {\n id: string;\n label: string;\n description: string;\n policyname: string;\n cmd: PolicyCommand;\n permissive: \"PERMISSIVE\" | \"RESTRICTIVE\";\n roles: string[];\n qual: string;\n with_check: string;\n}\n\n/**\n * Every preset targets `TO public`, which is what the framework's generator\n * emits and what actually reaches a request running as `rebase_user`. The part\n * that used to be expressed as a role — \"authenticated\", \"admin\" — is a\n * condition now, so it is enforced where Postgres will actually evaluate it.\n */\nexport const POLICY_PRESETS: PolicyPreset[] = [\n {\n id: \"public_read\",\n label: \"Enable read access to everyone\",\n description: \"Anyone can read data, regardless of authentication status.\",\n policyname: \"Enable read access for all users\",\n cmd: \"SELECT\",\n permissive: \"PERMISSIVE\",\n roles: [\"public\"],\n qual: \"true\",\n with_check: \"\"\n },\n {\n id: \"auth_read\",\n label: \"Enable read access for signed-in users only\",\n description: \"Only signed-in users are allowed to read data. Anonymous requests carry a sentinel uid, so the condition excludes them explicitly.\",\n policyname: \"Enable read access for signed-in users\",\n cmd: \"SELECT\",\n permissive: \"PERMISSIVE\",\n roles: [\"public\"],\n qual: SIGNED_IN_SQL,\n with_check: \"\"\n },\n {\n id: \"auth_insert\",\n label: \"Enable insert for signed-in users only\",\n description: \"Only signed-in users are allowed to insert new data.\",\n policyname: \"Enable insert for signed-in users only\",\n cmd: \"INSERT\",\n permissive: \"PERMISSIVE\",\n roles: [\"public\"],\n qual: \"\",\n with_check: SIGNED_IN_SQL\n },\n {\n id: \"admin_all\",\n label: \"Admins can do anything\",\n description: \"Restricted to users holding the `admin` application role, matched inside the policy via rebase.roles().\",\n policyname: \"Admins have full access\",\n cmd: \"ALL\",\n permissive: \"PERMISSIVE\",\n roles: [\"public\"],\n qual: IS_ADMIN_SQL,\n with_check: IS_ADMIN_SQL\n },\n {\n id: \"user_select_own\",\n label: \"Users can read their own rows\",\n description: \"Users can only read rows whose uid column matches their rebase.uid()\",\n policyname: \"Users can select their own data\",\n cmd: \"SELECT\",\n permissive: \"PERMISSIVE\",\n roles: [\"public\"],\n qual: OWNS_ROW_SQL,\n with_check: \"\"\n },\n {\n id: \"user_update_own\",\n label: \"Users can update their own rows\",\n description: \"Users can only update rows whose uid column matches their rebase.uid()\",\n policyname: \"Users can update their own data\",\n cmd: \"UPDATE\",\n permissive: \"PERMISSIVE\",\n roles: [\"public\"],\n qual: OWNS_ROW_SQL,\n with_check: OWNS_ROW_SQL\n },\n {\n id: \"user_delete_own\",\n label: \"Users can delete their own rows\",\n description: \"Users can only delete rows whose uid column matches their rebase.uid()\",\n policyname: \"Users can delete their own data\",\n cmd: \"DELETE\",\n permissive: \"PERMISSIVE\",\n roles: [\"public\"],\n qual: OWNS_ROW_SQL,\n with_check: \"\"\n }\n];\n","import React, { useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n Button,\n cls,\n defaultBorderMixin,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n HelpCircleIcon,\n IconButton,\n iconSize,\n MultiSelect,\n MultiSelectItem,\n Paper,\n Select,\n SelectItem,\n TextField,\n Typography\n} from \"@rebasepro/ui\";\nimport { useTranslation } from \"@rebasepro/app\";\nimport { RLS_JWT_SQL, RLS_ROLES_SQL, RLS_UID_SQL } from \"@rebasepro/types\";\nimport { REBASE_USER_ROLE } from \"@rebasepro/common\";\nimport {\n COMMAND_OPTIONS,\n POLICY_PRESETS,\n roleOptionsFor,\n type PolicyCommand\n} from \"./policy-presets\";\nimport { MonacoEditor, type MonacoEditorHandle } from \"../SQLEditor/MonacoEditor\";\nimport type { PostgresPolicy } from \"./RLSEditor\";\n\nexport interface PolicyEditorProps {\n policy?: PostgresPolicy;\n schema: string;\n table: string;\n /**\n * Native PostgreSQL roles this database actually has, for the `TO` list.\n *\n * Supplied by the caller from `fetchAvailableRoles()`. Merged with the\n * always-offered defaults by `roleOptionsFor`, never used in place of them:\n * `public` is a keyword and never comes back from that query.\n */\n roleOptions?: readonly string[];\n onSave: (policyData: Partial<PostgresPolicy>) => void;\n onCancel: () => void;\n}\n\nexport const PolicyEditor = ({\n policy,\n schema,\n table,\n roleOptions,\n onSave,\n onCancel\n}: PolicyEditorProps) => {\n\n const { t } = useTranslation();\n const [name, setName] = useState(\"\");\n const [helpOpen, setHelpOpen] = useState(false);\n const [behavior, setBehavior] = useState<\"PERMISSIVE\" | \"RESTRICTIVE\">(\"PERMISSIVE\");\n const [command, setCommand] = useState<PolicyCommand>(\"ALL\");\n const [roles, setRoles] = useState<string[]>([\"public\"]);\n const [usingExpr, setUsingExpr] = useState<string>(\"\");\n const [checkExpr, setCheckExpr] = useState<string>(\"\");\n\n const [selectedPreset, setSelectedPreset] = useState<string>(\"\");\n\n const availableRoles = useMemo(\n () => roleOptionsFor(roleOptions, policy?.roles),\n [roleOptions, policy]\n );\n\n useEffect(() => {\n if (policy) {\n setName(policy.policyname || \"\");\n setBehavior(policy.permissive || \"PERMISSIVE\");\n setCommand((policy.cmd as PolicyCommand) || \"ALL\");\n\n const initialRoles = policy.roles\n ? (Array.isArray(policy.roles) ? policy.roles : [policy.roles])\n : [\"public\"];\n setRoles(initialRoles as string[]);\n\n setUsingExpr(policy.qual || \"\");\n setCheckExpr(policy.with_check || \"\");\n } else {\n setName(\"\");\n setBehavior(\"PERMISSIVE\");\n setCommand(\"ALL\");\n setRoles([\"public\"]);\n setUsingExpr(\"\");\n setCheckExpr(\"\");\n setSelectedPreset(\"\");\n }\n }, [policy]);\n\n const handlePresetChange = (presetId: string) => {\n const preset = POLICY_PRESETS.find(p => p.id === presetId);\n if (!preset) return;\n\n setSelectedPreset(presetId);\n setName(preset.policyname);\n setBehavior(preset.permissive);\n setCommand(preset.cmd);\n setRoles(preset.roles);\n setUsingExpr(preset.qual);\n setCheckExpr(preset.with_check);\n };\n\n const showCheck = command === \"ALL\" || command === \"INSERT\" || command === \"UPDATE\";\n\n /**\n * The two expression editors. Save reads what they hold now: an edit\n * reaches `usingExpr` and `checkExpr` only when this re-renders, so a Save\n * right after a paste wrote the expression from before it.\n */\n const usingEditor = useRef<MonacoEditorHandle>(null);\n const checkEditor = useRef<MonacoEditorHandle>(null);\n\n const handleSave = () => {\n onSave({\n policyname: name,\n permissive: behavior,\n cmd: command,\n roles: roles,\n qual: usingEditor.current?.getValue() ?? usingExpr,\n with_check: showCheck ? checkEditor.current?.getValue() ?? checkExpr : null\n });\n };\n\n return (\n <>\n {/* Inline header: this editor renders as a full pane, not inside a Dialog,\n so DialogTitle (Radix-bound) cannot be used here. */}\n <Typography variant=\"h6\" gutterBottom className=\"mt-8 mx-8 flex justify-between items-center w-full\">\n <div>\n <div>{policy ? t(\"studio_policy_edit\") : t(\"studio_policy_create\")}</div>\n <div className=\"text-sm font-normal text-text-secondary dark:text-text-secondary-dark tracking-wide mt-1\">\n {t(\"studio_policy_defining_rules\")} <span className=\"font-mono text-primary bg-primary-bg px-1 py-0.5 rounded\">{schema}.{table}</span>\n </div>\n </div>\n <IconButton aria-label={t(\"help\")} size=\"small\" onClick={() => setHelpOpen(true)}>\n <HelpCircleIcon size={iconSize.smallest}/>\n </IconButton>\n </Typography>\n\n <DialogContent className=\"p-4 md:p-6 border-t border-hairline bg-surface-well\" includeMargin={false}>\n <div className=\"max-w-4xl mx-auto\">\n <Paper className={cls(\"p-4 md:p-6 flex flex-col gap-6 bg-surface-card border-none sm:border-solid rounded-none sm:rounded-xl\", defaultBorderMixin)}>\n\n {/* Presets - only for new policies */}\n {!policy && (\n <div className=\"flex flex-col gap-1.5 bg-primary/5 p-3 sm:p-4 rounded-lg border border-primary/10 dark:border-primary/20\">\n <Typography variant=\"caption\" className=\"text-primary dark:text-primary-light uppercase tracking-wider\">{t(\"studio_policy_template\")}</Typography>\n <Select\n size=\"small\"\n value={selectedPreset}\n onValueChange={handlePresetChange}\n position=\"item-aligned\"\n placeholder={t(\"studio_policy_select_template\")}\n className=\"bg-surface-card\"\n >\n {POLICY_PRESETS.map((preset) => (\n <SelectItem key={preset.id} value={preset.id}>\n <div className=\"flex flex-col text-left\">\n <span className=\"text-sm\">{preset.label}</span>\n <span className=\"text-xs text-text-secondary dark:text-text-secondary-dark\">{preset.description}</span>\n </div>\n </SelectItem>\n ))}\n </Select>\n </div>\n )}\n\n <div className=\"grid grid-cols-1 md:grid-cols-2 gap-4 sm:gap-6\">\n {/* Policy Name */}\n <div className=\"flex flex-col gap-1.5\">\n <Typography variant=\"caption\" className=\"uppercase tracking-wider text-text-secondary\">{t(\"studio_policy_name\")}</Typography>\n <TextField\n value={name}\n aria-label={t(\"studio_policy_name\")}\n onChange={(e) => setName(e.target.value)}\n placeholder={t(\"studio_policy_name_placeholder\")}\n className=\"w-full\"\n />\n </div>\n\n {/* Behavior */}\n <div className=\"flex flex-col gap-1.5\">\n <Typography variant=\"caption\" className=\"uppercase tracking-wider text-text-secondary\">\n {t(\"studio_policy_behavior\")} <code className=\"text-xs bg-hairline text-text-secondary dark:text-text-secondary-dark px-1 py-0.5 rounded ml-1\">AS</code>\n </Typography>\n <Select\n value={behavior}\n onValueChange={(val) => setBehavior(val as \"PERMISSIVE\" | \"RESTRICTIVE\")}\n position=\"item-aligned\"\n >\n <SelectItem value=\"PERMISSIVE\">\n <div className=\"flex flex-col text-left\">\n <span className=\"\">{t(\"studio_policy_permissive\")}</span>\n <span className=\"text-xs text-text-secondary dark:text-text-secondary-dark\">{t(\"studio_policy_permissive_desc\")}</span>\n </div>\n </SelectItem>\n <SelectItem value=\"RESTRICTIVE\">\n <div className=\"flex flex-col text-left\">\n <span className=\"\">{t(\"studio_policy_restrictive\")}</span>\n <span className=\"text-xs text-text-secondary dark:text-text-secondary-dark\">{t(\"studio_policy_restrictive_desc\")}</span>\n </div>\n </SelectItem>\n </Select>\n </div>\n </div>\n\n {/* Command */}\n <div className=\"flex flex-col gap-1.5\">\n <Typography variant=\"caption\" className=\"uppercase tracking-wider text-text-secondary\">\n {t(\"studio_policy_command\")} <code className=\"text-xs bg-hairline text-text-secondary dark:text-text-secondary-dark px-1 py-0.5 rounded ml-1\">FOR</code>\n </Typography>\n <div className=\"flex flex-wrap gap-1.5\">\n {COMMAND_OPTIONS.map(cmd => (\n <Button\n key={cmd}\n size=\"small\"\n variant={command === cmd ? \"filled\" : \"text\"}\n color=\"neutral\"\n onClick={() => setCommand(cmd)}\n className=\"min-w-[80px]\"\n >\n {cmd}\n </Button>\n ))}\n </div>\n </div>\n\n {/* Roles */}\n <div className=\"flex flex-col gap-1.5\">\n <Typography variant=\"caption\" className=\"uppercase tracking-wider text-text-secondary\">\n {t(\"studio_policy_target_roles\")} <code className=\"text-xs bg-hairline text-text-secondary dark:text-text-secondary-dark px-1 py-0.5 rounded ml-1\">TO</code>\n </Typography>\n <MultiSelect\n size=\"small\"\n value={roles}\n onValueChange={setRoles}\n placeholder={t(\"studio_policy_roles_placeholder\")}\n >\n {availableRoles.map(role => (\n <MultiSelectItem key={role} value={role}>\n {role}\n </MultiSelectItem>\n ))}\n </MultiSelect>\n </div>\n\n </Paper>\n\n <div className=\"mt-8 flex flex-col gap-4\">\n {/* USING Expression */}\n {command !== \"INSERT\" && (\n <div className=\"flex flex-col gap-1.5\">\n <div className=\"flex flex-col gap-0.5\">\n <Typography variant=\"caption\" className=\"uppercase tracking-wider text-text-secondary\">{t(\"studio_policy_using_expr\")}</Typography>\n <Typography variant=\"caption\" className=\"text-text-secondary opacity-70\">{t(\"studio_policy_using_expr_desc\")}</Typography>\n </div>\n <div className={cls(\"h-32 border rounded-md overflow-hidden bg-surface-card\", defaultBorderMixin)}>\n <MonacoEditor\n ref={usingEditor}\n value={usingExpr}\n onChange={(v) => setUsingExpr(v || \"\")}\n readOnly={false}\n autoFocus={true}\n />\n </div>\n </div>\n )}\n\n {/* WITH CHECK Expression */}\n {showCheck && (\n <div className=\"flex flex-col gap-1.5 mt-2\">\n <div className=\"flex flex-col gap-0.5\">\n <Typography variant=\"caption\" className=\"uppercase tracking-wider text-text-secondary\">{t(\"studio_policy_check_expr\")}</Typography>\n <Typography variant=\"caption\" className=\"text-text-secondary opacity-70\">{t(\"studio_policy_check_expr_desc\")}</Typography>\n </div>\n <div className={cls(\"h-32 border rounded-md overflow-hidden bg-surface-card\", defaultBorderMixin)}>\n <MonacoEditor\n ref={checkEditor}\n value={checkExpr}\n onChange={(v) => setCheckExpr(v || \"\")}\n readOnly={false}\n autoFocus={command === \"INSERT\"}\n />\n </div>\n </div>\n )}\n </div>\n\n </div>\n </DialogContent>\n\n <DialogActions>\n <Button size=\"small\" variant=\"text\" color=\"neutral\" onClick={onCancel}>\n {t(\"studio_policy_cancel\")}\n </Button>\n <Button size=\"small\" variant=\"filled\" color=\"primary\" onClick={handleSave} disabled={!name}>\n {t(\"studio_policy_save\")}\n </Button>\n </DialogActions>\n\n <Dialog open={helpOpen} onOpenChange={setHelpOpen} maxWidth=\"3xl\">\n <DialogTitle hidden>{t(\"studio_policy_help_title\")}</DialogTitle>\n <DialogContent className=\"p-4 sm:p-6 lg:p-8 flex flex-col gap-6\">\n <div>\n <Typography variant=\"h5\" className=\"mb-2\">{t(\"studio_policy_help_title\")}</Typography>\n <Typography className=\"text-text-secondary dark:text-text-secondary-dark\">\n {t(\"studio_policy_help_intro\")}\n </Typography>\n </div>\n\n <div className=\"flex flex-col gap-4\">\n <Paper className={cls(\"p-4 sm:p-5 flex flex-col gap-1\", defaultBorderMixin)}>\n <Typography variant=\"subtitle2\" className=\"text-primary dark:text-primary-light font-medium\">{t(\"studio_policy_help_step1_title\")}</Typography>\n <Typography variant=\"body2\" className=\"text-text-secondary dark:text-text-secondary-dark\">\n {t(\"studio_policy_help_step1_desc\")}\n </Typography>\n </Paper>\n\n <Paper className={cls(\"p-4 sm:p-5 flex flex-col gap-1\", defaultBorderMixin)}>\n <Typography variant=\"subtitle2\" className=\"text-primary dark:text-primary-light font-medium\">{t(\"studio_policy_help_step2_title\")}</Typography>\n <Typography variant=\"body2\" className=\"text-text-secondary dark:text-text-secondary-dark mb-1\">\n {t(\"studio_policy_help_step2_desc\")}\n </Typography>\n {/* Database roles, which is all a `TO` list can name. Every\n API request runs as REBASE_USER_ROLE, so \"signed-in users\"\n and \"anonymous visitors\" are not roles a policy can target\n — they are conditions, and the templates write them as such. */}\n <ul className=\"list-disc pl-5 space-y-1 text-sm text-text-secondary dark:text-text-secondary-dark\">\n <li><strong>public</strong>: {t(\"studio_policy_help_role_public\")}</li>\n <li><strong>{REBASE_USER_ROLE}</strong>: {t(\"studio_policy_help_role_rebase_user\")}</li>\n </ul>\n <Typography variant=\"body2\" className=\"text-text-secondary dark:text-text-secondary-dark mt-1\">\n {t(\"studio_policy_help_roles_not_users\")}\n </Typography>\n </Paper>\n\n <Paper className={cls(\"p-4 sm:p-5 flex flex-col gap-1\", defaultBorderMixin)}>\n <Typography variant=\"subtitle2\" className=\"text-primary dark:text-primary-light font-medium\">{t(\"studio_policy_help_step3_title\")}</Typography>\n <Typography variant=\"body2\" className=\"text-text-secondary dark:text-text-secondary-dark mb-1\">\n {t(\"studio_policy_help_step3_desc\")}\n </Typography>\n <div className={cls(\"bg-surface-well px-3 py-2 rounded-md font-mono text-sm my-2\", defaultBorderMixin)}>\n {t(\"studio_policy_help_example\")} {RLS_UID_SQL} = uid\n </div>\n <Typography variant=\"caption\" className=\"text-text-secondary dark:text-text-secondary-dark\">\n {t(\"studio_policy_help_step3_example\")}\n </Typography>\n </Paper>\n\n <Paper className={cls(\"p-4 sm:p-5 flex flex-col gap-1\", defaultBorderMixin)}>\n <Typography variant=\"subtitle2\" className=\"text-primary dark:text-primary-light font-medium\">{t(\"studio_policy_help_step4_title\")}</Typography>\n <Typography variant=\"body2\" className=\"text-text-secondary dark:text-text-secondary-dark mb-1\">\n {t(\"studio_policy_help_step4_desc\")}\n </Typography>\n <div className={cls(\"bg-surface-well px-3 py-2 rounded-md font-mono text-sm my-2\", defaultBorderMixin)}>\n {t(\"studio_policy_help_example\")} {RLS_UID_SQL} = uid\n </div>\n <Typography variant=\"caption\" className=\"text-text-secondary dark:text-text-secondary-dark\">\n {t(\"studio_policy_help_step4_example\")}\n </Typography>\n </Paper>\n\n <Paper className={cls(\"p-4 sm:p-5 flex flex-col gap-2 bg-primary/5\", defaultBorderMixin)}>\n <Typography variant=\"subtitle2\" className=\"text-primary dark:text-primary-light font-medium\">{t(\"studio_policy_help_auth_vars_title\")}</Typography>\n <Typography variant=\"body2\" className=\"text-text-secondary dark:text-text-secondary-dark\">\n {t(\"studio_policy_help_auth_vars_desc\")}\n </Typography>\n <ul className=\"list-disc pl-5 space-y-2 text-sm text-text-secondary dark:text-text-secondary-dark font-normal\">\n <li>\n <code className=\"bg-surface-well px-1.5 py-0.5 rounded mr-1 whitespace-nowrap\">{RLS_UID_SQL}</code>\n <span className=\"block mt-0.5\">{t(\"studio_policy_help_auth_uid\")} <code className=\"bg-surface-well px-1 py-0.5 rounded text-xs\">{RLS_UID_SQL} = uid</code></span>\n </li>\n <li>\n <code className=\"bg-surface-well px-1.5 py-0.5 rounded mr-1 whitespace-nowrap\">{RLS_JWT_SQL}</code>\n <span className=\"block mt-0.5\">{t(\"studio_policy_help_auth_jwt\")} <code className=\"bg-surface-well px-1 py-0.5 rounded text-xs\">{RLS_JWT_SQL} ->> 'email' = 'admin@example.com'</code></span>\n </li>\n <li>\n <code className=\"bg-surface-well px-1.5 py-0.5 rounded mr-1 whitespace-nowrap\">{RLS_ROLES_SQL}</code>\n <span className=\"block mt-0.5\">{t(\"studio_policy_help_auth_roles\")} <code className=\"bg-surface-well px-1 py-0.5 rounded text-xs\">string_to_array({RLS_ROLES_SQL}, ',') @> ARRAY['admin']</code></span>\n </li>\n </ul>\n </Paper>\n </div>\n\n <div className={cls(\"mt-2 flex flex-col sm:flex-row justify-between items-start sm:items-center bg-primary/5 p-4 rounded-xl border border-primary/10 dark:border-primary/20\", defaultBorderMixin)}>\n <Typography variant=\"body2\" className=\"text-primary dark:text-primary-light mb-4 sm:mb-0 max-w-md\">\n {t(\"studio_policy_help_docs_cta\")}\n </Typography>\n <Button\n component=\"a\"\n href=\"https://www.postgresql.org/docs/current/sql-createpolicy.html\"\n target=\"_blank\"\n variant=\"outlined\"\n color=\"primary\"\n size=\"small\"\n className=\"whitespace-nowrap flex-shrink-0\"\n >\n {t(\"studio_policy_help_read_docs\")}\n </Button>\n </div>\n </DialogContent>\n <DialogActions className=\"p-4 sm:px-6 sm:pb-6 pt-0 border-t-0\">\n <Button onClick={() => setHelpOpen(false)} variant=\"filled\" color=\"primary\">{t(\"studio_policy_help_got_it\")}</Button>\n </DialogActions>\n </Dialog>\n </>\n );\n};\n","import type { TablePatch } from \"@rebasepro/types\";\n\n/**\n * Write a table's rule edits to its source file: `{ patches }` to the\n * source-only schema editor (`/admin/schema-editor/apply`).\n *\n * The schema-editor routes sit behind an admin gate that accepts a bearer token\n * and nothing else — there is no cookie fallback — so a request without an\n * `Authorization` header is a 401 every time. The RLS editor's two write paths\n * (\"Create policy\" on a mapped table, and \"Import to codebase\") both sent none,\n * and both reported the failure as a constant \"Failed to save policy\", which is\n * also what a 501 and a parse error looked like.\n *\n * It lives in its own module rather than inline in the component so that the\n * header can be asserted without rendering the whole RLS editor.\n */\nexport async function postTablePatches(options: {\n apiBase: string;\n patches: TablePatch[];\n getAuthToken?: () => Promise<string | null | undefined>;\n}): Promise<void> {\n const { apiBase, patches, getAuthToken } = options;\n\n const headers: Record<string, string> = { \"Content-Type\": \"application/json\" };\n const token = getAuthToken ? await getAuthToken() : null;\n if (token) headers[\"Authorization\"] = `Bearer ${token}`;\n\n const response = await fetch(`${apiBase}/admin/schema-editor/apply`, {\n method: \"POST\",\n headers,\n // Only the operations: each names the table and the rule it changes,\n // and whatever it does not name stays as written.\n body: JSON.stringify({ patches })\n });\n\n if (response.ok) return;\n\n const body = await response.text().catch(() => \"\");\n let message: string | undefined;\n try {\n const parsed: unknown = JSON.parse(body);\n const error = typeof parsed === \"object\" && parsed !== null && \"error\" in parsed ? parsed.error : undefined;\n message = typeof error === \"object\" && error !== null && \"message\" in error && typeof error.message === \"string\"\n ? error.message\n : undefined;\n } catch {\n message = body.trim() || undefined;\n }\n throw new Error(message ?? `Failed to save policy (HTTP ${response.status}).`);\n}\n","import type { StudioSchemaEditing } from \"@rebasepro/app\";\nimport type { RlsDescriptor, SecurityRule, SecurityRuleBase, TablePatch } from \"@rebasepro/types\";\nimport { rulePatches } from \"@rebasepro/types\";\n\nimport { postTablePatches } from \"./saveSecurityRules\";\nimport type { PolicyRule } from \"./policyRules\";\n\n/**\n * Where a table's security rules go when the RLS editor saves them — the one\n * function every RLS-editor write to the source goes through.\n *\n * The edit is sent as the rule operations it is (`TablePatch`): the rules the\n * table declares, compared with the rules it should declare, by\n * {@link rulePatches} — one `replaceRule` for an edited rule, one `addRule`\n * for an imported one. A policy's name is a hash of its rule as written, so a\n * rule the edit did not touch is never rewritten. A posture is `setRls`:\n * removing the last rule is `\"admin-only\"`, never an empty list.\n *\n * A table whose rules are inherited from `defaultRls` keeps `\"inherit\"`\n * unless the person deliberately detaches it: `confirmDetach` asks (naming\n * what happens), and saying no writes nothing.\n *\n * There are two doors onto one file. With a collection editor mounted, the\n * write goes through its plan/apply flow — planned, shown as SQL, confirmed,\n * applied to the database — arriving over the Studio bridge as\n * {@link StudioSchemaEditing} (`@rebasepro/cms` is a *peer* of\n * `@rebasepro/studio`, which has to run without it). Without one, it goes to\n * the source-only schema editor directly.\n *\n * A separate module from the component so the decision can be asserted\n * without a database and a rendered editor.\n */\nexport async function saveRules(\n schemaEditing: StudioSchemaEditing,\n transport: { apiBase: string; getAuthToken?: () => Promise<string | null | undefined> },\n table: { slug: string; rls: RlsDescriptor },\n rules: readonly PolicyRule[],\n options: {\n /** Asked before a table on `defaultRls` gets rules of its own; `false` keeps `\"inherit\"`. */\n confirmDetach: (slug: string) => Promise<boolean>;\n }\n): Promise<void> {\n const patches = await rlsEdit(table, rules.map(asSecurityRule), options.confirmDetach);\n if (patches.length === 0) return;\n if (schemaEditing.available) {\n await schemaEditing.applyTablePatches(table.slug, patches);\n return;\n }\n await postTablePatches({ apiBase: transport.apiBase, patches, getAuthToken: transport.getAuthToken });\n}\n\n/**\n * A rule the policy editor built — its fields assigned one at a time, so\n * wider than any one variant — as the `SecurityRule` variant its fields make\n * it. Which fields go together is the variants' rule; the editor never sets\n * two that exclude each other ({@link PolicyRule}).\n */\nexport function asSecurityRule(rule: PolicyRule): SecurityRule {\n const { using, withCheck, ownerField, access, condition, check, redacted, ...rest } = rule;\n const base: SecurityRuleBase = rest;\n if (redacted) return { ...base, redacted, ...(access !== undefined ? { access } : {}) };\n if (using !== undefined) return { ...base, using, ...(withCheck !== undefined ? { withCheck } : {}) };\n if (withCheck !== undefined) return { ...base, withCheck };\n if (ownerField !== undefined) return { ...base, ownerField };\n if (access !== undefined) {\n if (condition !== undefined) return { ...base, access, condition, ...(check !== undefined ? { check } : {}) };\n if (check !== undefined) return { ...base, access, check };\n switch (access) {\n case \"public\": return { ...base, access: \"public\" };\n case \"authenticated\": return { ...base, access: \"authenticated\" };\n case \"registered\": return { ...base, access: \"registered\" };\n }\n }\n if (condition !== undefined) return { ...base, condition, ...(check !== undefined ? { check } : {}) };\n return base;\n}\n\n/** The person kept `\"inherit\"`: an answer, matched like the plan dialog's cancellation. */\nclass DetachDeclined extends Error {\n constructor() {\n super(\"The table keeps its inherited rules.\");\n this.name = \"SchemaChangeCancelled\";\n }\n}\n\n/**\n * The operations that make `table` declare `rules`.\n *\n * Exported for the tests: the decision is the whole of what this module adds.\n */\nexport async function rlsEdit(\n table: { slug: string; rls: RlsDescriptor },\n rules: readonly SecurityRule[],\n confirmDetach: (slug: string) => Promise<boolean>\n): Promise<TablePatch[]> {\n const declared = table.rls.posture === \"rules\" ? table.rls.rules : [];\n if (table.rls.inherited) {\n if (rules.length === 0 || JSON.stringify(rules) === JSON.stringify(declared)) return [];\n if (!await confirmDetach(table.slug)) throw new DetachDeclined();\n return [{ op: \"setRls\", table: table.slug, rls: [rules[0], ...rules.slice(1)] }];\n }\n if (rules.length === 0) {\n return declared.length === 0 ? [] : [{ op: \"setRls\", table: table.slug, rls: \"admin-only\" }];\n }\n if (declared.length === 0) return [{ op: \"setRls\", table: table.slug, rls: [rules[0], ...rules.slice(1)] }];\n return rulePatches(table.slug, declared, rules);\n}\n\n/**\n * Was this rejection the person closing the plan dialog, or keeping a table's\n * inherited rules?\n *\n * Either is an answer, not a failure, and a caller that treats every\n * rejection as an error reports someone's own choice back to them in red — as\n * the collection editor once did, with \"Error persisting collection: The schema\n * change was not applied.\"\n *\n * Matched by name rather than `instanceof`: `SchemaChangeCancelled` is declared\n * in `@rebasepro/cms`, which this package cannot import, and two copies of a\n * class in one bundle make `instanceof` silently false anyway.\n */\nexport function isCancellation(err: unknown): boolean {\n return err instanceof Error && err.name === \"SchemaChangeCancelled\";\n}\n","import { isRedactedSecurityRule } from \"@rebasepro/types\";\nimport type {\n AuthenticatedSecurityRule,\n CheckedAccessSecurityRule,\n ConditionalAccessSecurityRule,\n OwnerSecurityRule,\n PolicyCondition,\n PostgresPolicy,\n PublicSecurityRule,\n RawSQLCheckOnlySecurityRule,\n RawSQLSecurityRule,\n RedactedSecurityRule,\n RegisteredSecurityRule,\n RolesOnlySecurityRule,\n SecurityRule,\n SecurityRuleAccess,\n SecurityRuleBase,\n StructuredSecurityRule\n} from \"@rebasepro/types\";\nimport { policyToSecurityRule } from \"@rebasepro/common\";\nimport { getPolicyOperations } from \"@rebasepro/utils\";\nimport type { ListedPolicy } from \"./policyListing\";\n\n/**\n * The security-rule fields a {@link PostgresPolicy} describes, and the ones an\n * edit carries over from the rule it changes.\n *\n * Wider than any one `SecurityRule` variant on purpose: an edit starts from the\n * rule as written and deletes and assigns the fields that changed one at a\n * time, and the variants are exclusive about which fields go together.\n */\nexport type PolicyRule = SecurityRuleBase & {\n using?: string;\n withCheck?: string;\n ownerField?: string;\n access?: SecurityRuleAccess;\n condition?: PolicyCondition;\n check?: PolicyCondition;\n /** Carried through untouched; a redacted rule is never edited ({@link ruleForm}). */\n redacted?: true;\n};\n\n/**\n * Which form a declared rule is written in — what the editor can do with it.\n *\n * Every rule form but one is editable as SQL: the editor shows the policy the\n * rule compiles to, and a field is only rewritten when the form changed it\n * ({@link applyPolicyEdit}), so an untouched rule — a `PolicyShorthand`\n * condition, `access` with a condition — is saved exactly as written, and\n * its policy keeps its name. The exception is `redacted`: the server withheld\n * the rule's clauses from this caller, so there is nothing to show or edit;\n * it is defined on the server.\n */\nexport type PolicyRuleForm =\n | \"owner\" | \"access\" | \"conditional_access\" | \"structured\" | \"raw\" | \"roles_only\" | \"redacted\";\n\n/**\n * Every `SecurityRule` member {@link ruleForm} classifies. A member added to\n * the union and not listed here fails to compile at {@link RULE_FORMS_COVER_THE_UNION}\n * — the one place to decide how the editor treats it.\n */\ntype ClassifiedRule =\n | OwnerSecurityRule | PublicSecurityRule | AuthenticatedSecurityRule | RegisteredSecurityRule\n | ConditionalAccessSecurityRule | CheckedAccessSecurityRule | StructuredSecurityRule\n | RawSQLSecurityRule | RawSQLCheckOnlySecurityRule | RolesOnlySecurityRule | RedactedSecurityRule;\nconst RULE_FORMS_COVER_THE_UNION: [Exclude<SecurityRule, ClassifiedRule>] extends [never] ? true : false = true;\nvoid RULE_FORMS_COVER_THE_UNION;\n\n/** The {@link PolicyRuleForm} of a declared rule. */\nexport function ruleForm(rule: SecurityRule): PolicyRuleForm {\n if (isRedactedSecurityRule(rule)) return \"redacted\";\n if (rule.using != null || rule.withCheck != null) return \"raw\";\n if (rule.ownerField != null) return \"owner\";\n if (rule.access !== undefined) return rule.condition != null || rule.check != null ? \"conditional_access\" : \"access\";\n if (rule.condition != null || rule.check != null) return \"structured\";\n return \"roles_only\";\n}\n\n/** Why an edited policy could not be written back to a rule. */\nexport type PolicyEditRefusal =\n /** Rebase adds it (the admin baseline, tenancy); no declared rule holds it. */\n | \"generated\"\n /** It exists only in the database. */\n | \"not_declared\"\n /** Its rule covers several operations, and the policy is one of them. */\n | \"several_operations\"\n /** Its rule was served redacted: the clauses are defined on the server. */\n | \"redacted\";\n\nexport type PolicyEdit =\n | { ok: true; rules: PolicyRule[] }\n | { ok: false; reason: PolicyEditRefusal };\n\n/**\n * Write an edit of one policy back to the declared rule it compiles from.\n *\n * The rule is the one the server says the policy was compiled from (the\n * served policy's `rule` index, carried on the listed row) — the server is the\n * one compiler, so the editor never guesses it from names. A policy with no\n * rule is Rebase's own (`generated`: the admin baseline, tenancy, a junction's\n * derived policies) or exists only in the database.\n *\n * A rule over several operations is refused rather than split: taking one\n * operation out renames every policy the rule compiles to.\n *\n * @param declared The table's declared rules (`rls.rules`), as written.\n * @param original The listed policy the editor was opened with.\n */\nexport function applyPolicyEdit(\n declared: readonly SecurityRule[],\n original: ListedPolicy,\n edited: Partial<PostgresPolicy>\n): PolicyEdit {\n const index = original.rule;\n if (index === undefined || declared[index] === undefined) {\n return { ok: false, reason: original.generated ? \"generated\" : \"not_declared\" };\n }\n const rule = declared[index];\n if (ruleForm(rule) === \"redacted\") return { ok: false, reason: \"redacted\" };\n if (getPolicyOperations(rule).length > 1) return { ok: false, reason: \"several_operations\" };\n\n return {\n ok: true,\n rules: declared.map((r, i) => (i === index ? editedRule(r, original, edited) : r))\n };\n}\n\n/**\n * The rule with what the editor changed, and nothing else.\n *\n * The editor shows a rule as a policy — name, command, mode, `TO` list and raw\n * USING / WITH CHECK — and an `ownerField` or `access` rule has no raw clause\n * to show. So a field is only written when it differs from what the editor was\n * opened with: renaming an `access: \"public\"` rule keeps it public, and an\n * unnamed rule stays unnamed unless the name was changed. A condition typed in\n * replaces the rule's condition whole — the forms are exclusive.\n */\nfunction editedRule(rule: SecurityRule, original: PostgresPolicy, edited: Partial<PostgresPolicy>): PolicyRule {\n const next = policyToSecurityRule(edited);\n const result: PolicyRule = { ...rule };\n\n if ((edited.policyname ?? \"\") !== original.policyname) {\n if (next.name) result.name = next.name;\n else delete result.name;\n }\n if (edited.cmd !== original.cmd) {\n delete result.operations;\n result.operation = next.operation;\n }\n if (edited.permissive !== original.permissive) {\n result.mode = next.mode;\n }\n if (!sameRoles(edited.roles, original.roles)) {\n if (next.pgRoles) result.pgRoles = next.pgRoles;\n else delete result.pgRoles;\n }\n if ((edited.qual || null) !== (original.qual || null) || (edited.with_check || null) !== (original.with_check || null)) {\n delete result.ownerField;\n delete result.access;\n delete result.condition;\n delete result.check;\n delete result.using;\n delete result.withCheck;\n if (next.using) result.using = next.using;\n if (next.withCheck) result.withCheck = next.withCheck;\n }\n return result;\n}\n\nfunction sameRoles(a: readonly string[] | undefined, b: readonly string[] | undefined): boolean {\n const left = [...(a ?? [])].sort();\n const right = [...(b ?? [])].sort();\n return left.length === right.length && left.every((role, i) => role === right[i]);\n}\n","import React, { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n Alert,\n AlertTriangleIcon,\n Button,\n cls,\n defaultBorderMixin,\n IconButton,\n iconSize,\n KeyIcon,\n Paper,\n PlusIcon,\n ShieldIcon,\n StatusDot,\n Tooltip,\n Trash2Icon,\n Typography\n} from \"@rebasepro/ui\";\nimport {\n ConfirmationDialog,\n useApiBase,\n useApiConfig,\n useRebaseContext,\n useSnackbarController,\n useStudioCapabilities,\n useStudioSchemaEditing,\n useTableDescriptors,\n useTranslation\n} from \"@rebasepro/app\";\nimport { policyToSecurityRule, REBASE_INTERNAL_PREFIXES, REBASE_INTERNAL_SCHEMAS } from \"@rebasepro/common\";\nimport { adminRequestPolicyName } from \"@rebasepro/utils\";\nimport type { JunctionPolicyDescriptor, PostgresPolicy, SecurityRule, TableDescriptor } from \"@rebasepro/types\";\nimport { PolicyEditor } from \"./PolicyEditor\";\nimport { isCancellation, saveRules } from \"./saveRules\";\nimport { applyPolicyEdit, type PolicyEditRefusal, type PolicyRule } from \"./policyRules\";\nimport { declaredPoliciesOf, listPolicies, type DeclaredPolicies, type ListedPolicy } from \"./policyListing\";\nimport { quoteIdentifier } from \"../../utils/sql_utils\";\nimport { schemaSourceProblem, SchemaSourceProblemAlert } from \"../schema-source\";\n\nexport type TableCategory = \"collection\" | \"junction\" | \"internal\" | \"other\";\n\n/**\n * Whether `descriptor` is the table the server declares for a live table: the\n * same SQL table in the same schema, as the server resolved both.\n *\n * Matched once by name, a table was taken for any collection whose `id`,\n * `path`, `table`, `slug` or `collectionId` equalled its name, in any schema.\n * So an unmapped table named like another table's slug, or a same-named table\n * in another schema, was taken for that table: it listed the declared\n * policies as missing from the table, and offered to import the table's own\n * policies into the declaration. A view is never a `pg_tables` row.\n */\nexport function mapsTable(descriptor: TableDescriptor, table: { schemaName: string; tableName: string }): boolean {\n return descriptor.kind === \"table\" && descriptor.table === table.tableName && descriptor.schema === table.schemaName;\n}\n\n/**\n * A table the project's own schema maps is the CUSTOMER'S, whatever schema\n * Postgres put it in: Rebase creates a tenant's collection tables in the\n * `rebase` schema, so the schema can never decide this on its own. `users`\n * and `branches` are both platform tables AND, on a project that defines\n * them, collections the customer writes policies for. The mapping is the only\n * thing that knows, so it is asked first.\n */\nexport function classifyTableClient(\n tableName: string,\n schemaName: string,\n isJunction: boolean,\n isMappedToCollection: boolean\n): TableCategory {\n if (isMappedToCollection) return \"collection\";\n if (\n REBASE_INTERNAL_SCHEMAS.includes(schemaName) ||\n REBASE_INTERNAL_PREFIXES.some((prefix) => tableName.startsWith(prefix))\n ) {\n return \"internal\";\n }\n if (isJunction) return \"junction\";\n return \"other\";\n}\n\n/**\n * Every junction the server derives, with its policies, by `schema.table`. A\n * junction has no descriptor of its own: it is listed under each table that\n * declares a relation through it.\n */\nexport function servedJunctionsOf(declaredTables: readonly TableDescriptor[]): Map<string, JunctionPolicyDescriptor> {\n const junctions = new Map<string, JunctionPolicyDescriptor>();\n for (const table of declaredTables) {\n for (const junction of table.rls.junctions ?? []) {\n junctions.set(`${junction.schema}.${junction.table}`, junction);\n }\n // Without the compiled policies (no `schema:read`) the relation\n // still names its junction: it is still the platform's table.\n for (const relation of table.relations) {\n if (relation.kind !== \"manyToMany\") continue;\n const key = `${table.schema}.${relation.through.table}`;\n if (!junctions.has(key)) junctions.set(key, { table: relation.through.table, schema: table.schema, policies: [] });\n }\n }\n return junctions;\n}\n\n/** What the editor says when an edit has no declared rule to go back to. */\nconst POLICY_EDIT_REFUSALS: Record<PolicyEditRefusal, string> = {\n generated: \"studio_rls_edit_generated\",\n not_declared: \"studio_rls_edit_not_declared\",\n several_operations: \"studio_rls_edit_several_operations\",\n redacted: \"studio_rls_edit_redacted\"\n};\n\nexport interface TablePoliciesProps {\n schemaName: string;\n tableName: string;\n rlsEnabled: boolean;\n /** What Postgres holds for the table now (`pg_policies`). */\n policies: readonly PostgresPolicy[];\n /** The table looks like a junction (every column a foreign key), whether or not the server derives it. */\n isJunction?: boolean;\n /** Read the live state again after a change this component made. */\n onChanged: () => void;\n}\n\n/**\n * One table's row level security: the RLS switch, the policies Postgres\n * enforces merged with what the code declares (drift, unapplied), and the\n * editor that writes a policy where it belongs — the declaration when there\n * is a codebase, the database otherwise.\n *\n * The RLS view and the table inspector's Policies tab both render this, so\n * there is one place a policy is listed, edited and dropped.\n */\nexport function TablePolicies({ schemaName, tableName, rlsEnabled, policies, isJunction = false, onChanged }: TablePoliciesProps) {\n const { databaseAdmin } = useRebaseContext();\n const snackbarController = useSnackbarController();\n const { t } = useTranslation();\n // The tables the server declares, with the policies it compiles for each:\n // the server is the one compiler, this editor only compares its answer\n // with what Postgres holds.\n const descriptors = useTableDescriptors();\n const schemaProblem = schemaSourceProblem(descriptors);\n const declaredTables = descriptors.tables;\n const { codebase: hasCodebase } = useStudioCapabilities();\n const apiConfig = useApiConfig();\n const apiBase = useApiBase() ?? \"/api\";\n const schemaEditing = useStudioSchemaEditing();\n const reloadDeclared = descriptors.reload;\n\n const activeTableData = useMemo(() => ({ schemaName, tableName }), [schemaName, tableName]);\n\n /**\n * Saving rules on a table that inherits them from `defaultRls` detaches it\n * into rules of its own: asked here, never done silently. Settled by the\n * dialog below — \"OK\" detaches, \"Cancel\" keeps `\"inherit\"`.\n */\n const [detaching, setDetaching] = useState<string | null>(null);\n const settleDetach = useRef<((detach: boolean) => void) | null>(null);\n const confirmDetach = useCallback((slug: string) => new Promise<boolean>(resolve => {\n settleDetach.current?.(false);\n settleDetach.current = resolve;\n setDetaching(slug);\n }), []);\n const answerDetach = useCallback((detach: boolean) => {\n settleDetach.current?.(detach);\n settleDetach.current = null;\n setDetaching(null);\n }, []);\n\n /** Through the plan/apply dialog when there is one — see `saveRules`. */\n const saveSecurityRules = useCallback(\n async (table: TableDescriptor, securityRules: readonly PolicyRule[]) => {\n await saveRules(\n schemaEditing,\n { apiBase, getAuthToken: apiConfig?.getAuthToken },\n table,\n securityRules,\n { confirmDetach }\n );\n reloadDeclared();\n },\n [apiBase, apiConfig, schemaEditing, reloadDeclared, confirmDetach]);\n\n /** Closing the plan dialog is an answer, not a failure — see `saveRules`. */\n const reportSaveFailure = useCallback((e: unknown) => {\n if (isCancellation(e)) return;\n snackbarController.open({ type: \"error\", message: e instanceof Error ? e.message : String(e) });\n }, [snackbarController]);\n\n // Hosts key this component by table, so another table starts with nothing open.\n const [editingPolicy, setEditingPolicy] = useState<ListedPolicy | \"new\" | null>(null);\n\n const [confirmToggleRls, setConfirmToggleRls] = useState<{ enabled: boolean; managed: boolean } | null>(null);\n const [confirmDropPolicy, setConfirmDropPolicy] = useState<string | null>(null);\n const [confirming, setConfirming] = useState(false);\n\n /**\n * Native PostgreSQL roles, for the policy editor's `TO` list.\n *\n * `fetchAvailableRoles` and not `fetchApplicationRoles`: a policy's `TO`\n * clause names database roles, and an application role put there produces\n * a policy that either fails to create or matches nothing.\n */\n const [pgRoleOptions, setPgRoleOptions] = useState<string[]>([]);\n useEffect(() => {\n let mounted = true;\n if (!databaseAdmin?.fetchAvailableRoles) return;\n databaseAdmin.fetchAvailableRoles()\n .then((roles) => { if (mounted) setPgRoleOptions(roles); })\n .catch((e) => console.error(\"Failed to fetch database roles\", e));\n return () => { mounted = false; };\n }, [databaseAdmin]);\n\n const qualifiedTable = `${quoteIdentifier(schemaName)}.${quoteIdentifier(tableName)}`;\n\n const applyToggleRls = useCallback(async () => {\n if (!confirmToggleRls || !databaseAdmin?.executeSql) return;\n const action = confirmToggleRls.enabled ? \"DISABLE\" : \"ENABLE\";\n setConfirming(true);\n try {\n await databaseAdmin.executeSql(`ALTER TABLE ${qualifiedTable} ${action} ROW LEVEL SECURITY`);\n snackbarController.open({\n type: \"success\",\n message: t(confirmToggleRls.enabled ? \"studio_tables_rls_disabled_on\" : \"studio_tables_rls_enabled_on\", { name: tableName })\n });\n setConfirmToggleRls(null);\n onChanged();\n } catch (e: unknown) {\n snackbarController.open({ type: \"error\", message: e instanceof Error ? e.message : String(e) });\n } finally {\n setConfirming(false);\n }\n }, [confirmToggleRls, databaseAdmin, qualifiedTable, snackbarController, t, tableName, onChanged]);\n\n const applyDropPolicy = useCallback(async () => {\n if (!confirmDropPolicy || !databaseAdmin?.executeSql) return;\n setConfirming(true);\n try {\n // Its admin-request companion (`USING (true)` for every admin) goes\n // with it, in the same implicit transaction: left behind, it would\n // keep admitting every admin to every row the dropped policy did.\n await databaseAdmin.executeSql(\n `DROP POLICY ${quoteIdentifier(confirmDropPolicy)} ON ${qualifiedTable}; ` +\n `DROP POLICY IF EXISTS ${quoteIdentifier(adminRequestPolicyName(confirmDropPolicy))} ON ${qualifiedTable}`\n );\n snackbarController.open({ type: \"success\", message: t(\"studio_tables_policy_dropped\", { name: confirmDropPolicy }) });\n setConfirmDropPolicy(null);\n onChanged();\n } catch (e: unknown) {\n snackbarController.open({ type: \"error\", message: e instanceof Error ? e.message : String(e) });\n } finally {\n setConfirming(false);\n }\n }, [confirmDropPolicy, databaseAdmin, qualifiedTable, snackbarController, t, onChanged]);\n\n const servedJunctions = useMemo(() => servedJunctionsOf(declaredTables), [declaredTables]);\n\n /** The table the server declares for this one, if any. */\n const activeDescriptor = useMemo(\n () => declaredTables.find(descriptor => mapsTable(descriptor, activeTableData)) ?? null,\n [activeTableData, declaredTables]\n );\n\n /**\n * The junction a relation derives this table as, when it is one. Its\n * policies are Rebase's — derived from the endpoints' relations — and the\n * server re-creates them on every start, like a declared table's.\n */\n const activeJunction = useMemo(() => {\n if (activeDescriptor) return null;\n return servedJunctions.get(`${schemaName}.${tableName}`) ?? null;\n }, [activeDescriptor, servedJunctions, schemaName, tableName]);\n\n const activeTableCategory = classifyTableClient(tableName, schemaName, Boolean(activeJunction) || isJunction, Boolean(activeDescriptor));\n\n /** Whether the server re-asserts this table's RLS on every start. */\n const activeTableManaged = Boolean(activeDescriptor || activeJunction);\n\n /**\n * What the server says the table's policies are — `undefined` when it\n * declares none, or withheld them from this caller.\n */\n const activeDeclared = useMemo((): DeclaredPolicies | undefined => {\n if (activeDescriptor) return declaredPoliciesOf(activeDescriptor.rls);\n if (activeJunction && activeJunction.policies.length > 0) return { rules: [], policies: activeJunction.policies };\n return undefined;\n }, [activeDescriptor, activeJunction]);\n\n /**\n * The table is declared, but this caller is not shown what it compiles to\n * (no `schema:read`): the list is what the database holds, and nothing is\n * written to the declaration — its raw rules may be redacted.\n */\n const declaredWithheld = activeDescriptor !== null && activeDeclared === undefined;\n\n /** A save to the declaration needs the declaration, and a codebase to write it into. */\n const savesToCodebase = activeDescriptor !== null && hasCodebase;\n\n /**\n * What Postgres enforces on the table, and what the code declares that it\n * does not have yet. A policy in both is listed with the *database's*\n * fields, and the declaration rides beside it with where the two differ.\n */\n const mergedPolicies = useMemo((): ListedPolicy[] =>\n listPolicies([...policies], activeDeclared, tableName).sort((a, b) => a.policyname.localeCompare(b.policyname)),\n [policies, activeDeclared, tableName]);\n\n const handleSave = async (newPolicy: Partial<PostgresPolicy>) => {\n if (!editingPolicy) return;\n /*\n * Where a policy for a *mapped* table belongs depends on the host, not\n * on the table. Beside its own source, the collection file is the\n * right home: the rule is checked in, and the next migration applies\n * it. The hosted console has no source, and the schema-editor routes\n * are not mounted under NODE_ENV=production, so there the database is\n * the only place a policy can live — the same path unmapped tables use.\n */\n if (savesToCodebase && activeDescriptor) {\n if (declaredWithheld) {\n snackbarController.open({ type: \"error\", message: t(\"studio_rls_save_needs_schema_read\", { table: tableName }) });\n return;\n }\n const existingRules: readonly SecurityRule[] = activeDescriptor.rls.rules;\n let newRules: PolicyRule[];\n if (editingPolicy === \"new\") {\n newRules = [...existingRules, policyToSecurityRule(newPolicy)];\n } else {\n // Back to the rule the policy compiles from, or a refusal that\n // says why there is none — never the unchanged rules reported\n // as saved.\n const edit = applyPolicyEdit(existingRules, editingPolicy, newPolicy);\n if (!edit.ok) {\n snackbarController.open({ type: \"error\", message: t(POLICY_EDIT_REFUSALS[edit.reason], { policy: editingPolicy.policyname }) });\n return;\n }\n newRules = edit.rules;\n if (JSON.stringify(newRules) === JSON.stringify(existingRules)) {\n snackbarController.open({ type: \"info\", message: t(\"studio_rls_nothing_changed\") });\n return;\n }\n }\n try {\n // Addressed by its slug: the schema editor finds tables by it, never by the SQL name.\n await saveSecurityRules(activeDescriptor, newRules);\n snackbarController.open({ type: \"success\", message: t(\"studio_tables_policy_saved\") });\n setEditingPolicy(null);\n onChanged();\n } catch (e: unknown) {\n reportSaveFailure(e);\n }\n return;\n }\n\n // A policy Rebase generates is re-created on the next start, and what\n // the database holds for it is a compiled condition the form only\n // shows as text: rewriting it here cannot last, and one slip in that\n // text drops the condition. The source path refuses the same edit.\n if (editingPolicy !== \"new\" && editingPolicy.generated) {\n snackbarController.open({ type: \"error\", message: t(POLICY_EDIT_REFUSALS.generated, { policy: editingPolicy.policyname }) });\n return;\n }\n if (!databaseAdmin?.executeSql) return;\n try {\n const policyName = quoteIdentifier(newPolicy.policyname || \"unnamed_policy\");\n const cmd = newPolicy.cmd || \"ALL\";\n const permissive = (newPolicy.permissive || \"PERMISSIVE\") === \"PERMISSIVE\" ? \"PERMISSIVE\" : \"RESTRICTIVE\";\n const roles = newPolicy.roles && newPolicy.roles.length > 0\n ? newPolicy.roles.map(r => quoteIdentifier(r)).join(\", \")\n : \"public\";\n\n let sql = `CREATE POLICY ${policyName} ON ${qualifiedTable} AS ${permissive} FOR ${cmd} TO ${roles}`;\n if (newPolicy.qual) sql += ` USING (${newPolicy.qual})`;\n if (newPolicy.with_check) sql += ` WITH CHECK (${newPolicy.with_check})`;\n\n // An edit replaces the policy under the name it *had*, and its\n // admin-request companion, in the same statement as the CREATE:\n // Postgres runs a multi-statement simple query as one implicit\n // transaction, so a CREATE that fails takes the DROP back with it.\n if (editingPolicy !== \"new\") {\n const previousName = quoteIdentifier(editingPolicy.policyname);\n const companion = quoteIdentifier(adminRequestPolicyName(editingPolicy.policyname));\n sql = `DROP POLICY IF EXISTS ${previousName} ON ${qualifiedTable}; DROP POLICY IF EXISTS ${companion} ON ${qualifiedTable}; ${sql}`;\n }\n await databaseAdmin.executeSql(sql);\n snackbarController.open({ type: \"success\", message: t(\"studio_tables_policy_applied\", { name: newPolicy.policyname ?? \"\" }) });\n setEditingPolicy(null);\n onChanged();\n } catch (e: unknown) {\n snackbarController.open({ type: \"error\", message: e instanceof Error ? e.message : String(e) });\n }\n };\n\n const importToCodebase = async (policy: ListedPolicy) => {\n if (!activeDescriptor) return;\n // A live policy's `roles` is its `TO` list: database roles, so\n // `pgRoles`. Copied into `roles`, `TO public` became an\n // application-role check nobody passes.\n const rule = policyToSecurityRule(policy);\n try {\n await saveSecurityRules(activeDescriptor, [...activeDescriptor.rls.rules, rule]);\n snackbarController.open({ type: \"success\", message: t(\"studio_tables_policy_imported\") });\n onChanged();\n } catch (e: unknown) {\n reportSaveFailure(e);\n }\n };\n\n const renderPolicyTag = (label: string, value: string) => (\n <div className=\"flex items-center gap-1.5 px-2 py-1 rounded-md bg-surface-field\">\n <Typography variant=\"caption\" color=\"secondary\" className=\"font-medium\">{label}</Typography>\n <Typography variant=\"mono\" className=\"text-xs break-all\">{value}</Typography>\n </div>\n );\n\n if (editingPolicy) {\n return (\n <PolicyEditor\n policy={editingPolicy === \"new\" ? undefined : editingPolicy}\n schema={schemaName}\n table={tableName}\n roleOptions={pgRoleOptions}\n onSave={(policy) => void handleSave(policy)}\n onCancel={() => setEditingPolicy(null)}\n />\n );\n }\n\n return (\n <div className=\"flex flex-col gap-5\">\n <div className=\"flex items-center justify-between gap-3 flex-wrap\">\n <StatusDot tone={rlsEnabled ? \"ok\" : \"busy\"}>\n {rlsEnabled ? t(\"studio_rls_enabled\") : t(\"studio_rls_disabled\")}\n </StatusDot>\n <div className=\"flex items-center gap-2\">\n <Button\n size=\"small\"\n variant=\"outlined\"\n onClick={() => setConfirmToggleRls({ enabled: rlsEnabled, managed: activeTableManaged })}\n >\n {rlsEnabled ? t(\"studio_rls_disable_rls\") : t(\"studio_rls_enable_rls\")}\n </Button>\n <Button size=\"small\" color=\"primary\" variant=\"filled\" onClick={() => setEditingPolicy(\"new\")}>\n <PlusIcon size={iconSize.smallest} />\n {t(\"studio_rls_create_policy\")}\n </Button>\n </div>\n </div>\n\n {/* Without the served tables the list is only what the database holds: say why. */}\n {schemaProblem && <SchemaSourceProblemAlert problem={schemaProblem}/>}\n {declaredWithheld && (\n <Alert color=\"info\">\n <Typography variant=\"caption\">{t(\"studio_rls_declared_withheld\", { table: tableName })}</Typography>\n </Alert>\n )}\n {/* A table the server re-asserts on every start, where this editor\n writes straight to the database: what is changed here does not\n outlive the next start. */}\n {activeTableManaged && !savesToCodebase && (\n <Alert color=\"info\">\n <Typography variant=\"caption\">{t(\"studio_rls_reapplied_on_start\", { table: tableName })}</Typography>\n </Alert>\n )}\n {activeTableCategory === \"internal\" && (\n <Alert color=\"info\">\n <Typography variant=\"body2\" className=\"mb-1 font-semibold\">Rebase System Table</Typography>\n <Typography variant=\"caption\" className=\"opacity-80\">\n This table is managed internally by Rebase. Its security policies are configured automatically.\n Editing policies on system tables is an advanced operation.\n </Typography>\n </Alert>\n )}\n {activeTableCategory === \"junction\" && (\n <Alert color=\"info\">\n <Typography variant=\"body2\" className=\"mb-1 font-semibold\">Junction Table</Typography>\n <Typography variant=\"caption\" className=\"opacity-80\">\n This is an auto-generated junction table for a many-to-many relation.\n Rebase derives its policies: rows are readable when both related rows\n are, and writable following the declaring table's update rules\n (plus the server/admin baseline). You can still add RLS policies\n directly to broaden access.\n </Typography>\n </Alert>\n )}\n\n {!rlsEnabled && (\n <Alert color=\"warning\">\n <Typography variant=\"subtitle2\">Row Level Security (RLS) is disabled</Typography>\n <Typography variant=\"body2\" className=\"mt-1\">\n Your table is completely readable and writable by anyone with access privileges. Enable RLS to create policies that restrict access to specific rows.\n </Typography>\n </Alert>\n )}\n\n {mergedPolicies.length > 0 && (\n <div className=\"flex flex-col gap-3\">\n <Typography variant=\"subtitle2\">{t(\"studio_rls_policies\")}</Typography>\n {mergedPolicies.map(policy => (\n <Paper key={policy.policyname} className={cls(\"p-3 sm:px-4 sm:py-3 flex flex-col sm:flex-row sm:items-center justify-between gap-4 border rounded-lg\", defaultBorderMixin)}>\n <div className=\"flex flex-col gap-2 min-w-0\">\n <div className=\"flex items-center gap-2 flex-wrap\">\n <KeyIcon size={iconSize.smallest} className=\"text-text-secondary dark:text-text-secondary-dark shrink-0\"/>\n <Typography variant=\"body2\" className=\"truncate\">{policy.policyname}</Typography>\n {policy.status === \"code_only\" && (\n <Tooltip title={t(\"studio_rls_unapplied_tooltip\")}>\n <span><StatusDot tone=\"idle\" size=\"small\">{t(\"studio_rls_unapplied\")}</StatusDot></span>\n </Tooltip>\n )}\n {/* The database holds this policy differently from its\n declaration: TO list, command, mode, and whether each\n clause is there — never the clause text. */}\n {policy.drift && policy.drift.length > 0 && (\n <Tooltip title={t(\"studio_rls_drift_tooltip\", { fields: policy.drift.join(\", \") })}>\n <span><StatusDot tone=\"busy\" size=\"small\">{`${t(\"studio_rls_drift\")}: ${policy.drift.join(\", \")}`}</StatusDot></span>\n </Tooltip>\n )}\n {/* A *drift* signal: the codebase does not declare this policy.\n Without a codebase every policy trivially qualifies. */}\n {policy.status === \"live\" && hasCodebase && (\n <Tooltip title={t(\"studio_tables_policy_db_only_tooltip\")}>\n <span><StatusDot tone=\"busy\" size=\"small\">{t(\"studio_tables_policy_db_only\")}</StatusDot></span>\n </Tooltip>\n )}\n </div>\n <div className=\"flex flex-wrap gap-1.5\">\n {renderPolicyTag(t(\"studio_tables_policy_action\"), policy.cmd)}\n {renderPolicyTag(t(\"studio_tables_policy_roles\"), Array.isArray(policy.roles) ? policy.roles.join(\", \") : String(policy.roles))}\n {policy.qual && renderPolicyTag(\"USING\", policy.qual)}\n {policy.with_check && renderPolicyTag(\"WITH CHECK\", policy.with_check)}\n </div>\n </div>\n <div className=\"flex gap-2 shrink-0 items-center\">\n {/* Writes a collection source file, so it needs a codebase on the other end. */}\n {policy.status === \"live\" && savesToCodebase && activeDescriptor && !declaredWithheld && (\n <Button size=\"small\" variant=\"outlined\" onClick={() => void importToCodebase(policy)}>\n {t(\"studio_tables_policy_import\")}\n </Button>\n )}\n <Button size=\"small\" variant=\"text\" onClick={() => setEditingPolicy(policy)}>\n {t(\"studio_rls_edit\")}\n </Button>\n {policy.status !== \"code_only\" && (\n <Tooltip title={t(\"studio_rls_delete\")} asChild={true}>\n <IconButton aria-label={t(\"studio_rls_delete\")} size=\"small\" onClick={() => setConfirmDropPolicy(policy.policyname)}>\n <Trash2Icon size={iconSize.smallest}/>\n </IconButton>\n </Tooltip>\n )}\n </div>\n </Paper>\n ))}\n </div>\n )}\n\n {mergedPolicies.length === 0 && rlsEnabled && (\n <div className=\"flex flex-col items-center justify-center py-12 text-center gap-2\">\n <ShieldIcon size={36} className=\"text-text-disabled dark:text-text-disabled-dark\"/>\n <Typography variant=\"subtitle2\" color=\"secondary\">{t(\"studio_tables_policies_none_title\")}</Typography>\n <Typography variant=\"caption\" color=\"secondary\" className=\"max-w-sm\">{t(\"studio_tables_policies_none_body\")}</Typography>\n </div>\n )}\n\n {mergedPolicies.length === 0 && !rlsEnabled && activeDescriptor && (\n <div className=\"flex flex-col items-center justify-center py-12 text-center gap-2\">\n <AlertTriangleIcon size={36} className=\"text-text-disabled dark:text-text-disabled-dark\"/>\n <Typography variant=\"subtitle2\" color=\"secondary\">{t(\"studio_tables_policies_no_access_control\")}</Typography>\n </div>\n )}\n\n <ConfirmationDialog\n open={confirmToggleRls !== null}\n loading={confirming}\n onAccept={applyToggleRls}\n onCancel={() => setConfirmToggleRls(null)}\n title={confirmToggleRls?.enabled ? t(\"studio_rls_disable_confirm_title\") : t(\"studio_rls_enable_confirm_title\")}\n body={confirmToggleRls?.enabled\n ? [\n t(\"studio_rls_disable_confirm_body\", { table: tableName }),\n // The server switches a managed table's RLS back on at its next start.\n confirmToggleRls.managed ? t(\"studio_rls_disable_reapplied\", { table: tableName }) : \"\"\n ].filter(Boolean).join(\" \")\n : t(\"studio_rls_enable_confirm_body\", { table: tableName })}\n />\n <ConfirmationDialog\n open={detaching !== null}\n onAccept={() => answerDetach(true)}\n onCancel={() => answerDetach(false)}\n title={t(\"schema_rules_detach_title\")}\n body={t(\"schema_rules_detach_body\", { table: detaching ?? \"\" })}\n />\n <ConfirmationDialog\n open={confirmDropPolicy !== null}\n loading={confirming}\n onAccept={applyDropPolicy}\n onCancel={() => setConfirmDropPolicy(null)}\n title={t(\"studio_rls_drop_policy_title\")}\n body={t(\"studio_rls_drop_policy_body\", { policy: confirmDropPolicy ?? \"\", table: tableName })}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,gBAAgB,OAA0B;CACtD,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM,QAAQ,SAAyB,OAAO,SAAS,QAAQ;CAChG,IAAI,OAAO,UAAU,UAAU,OAAO,CAAC;CACvC,MAAM,OAAO,MAAM,KAAK,CAAC,CAAC,QAAQ,OAAO,EAAE,CAAC,CAAC,QAAQ,OAAO,EAAE;CAC9D,MAAM,QAAkB,CAAC;CACzB,IAAI,IAAI;CACR,OAAO,IAAI,KAAK,QAAQ;EACpB,IAAI,KAAK,OAAO,MAAM;GAClB,IAAI,OAAO;GACX;GACA,OAAO,IAAI,KAAK,UAAU,KAAK,OAAO,MAAM;IACxC,IAAI,KAAK,OAAO,MAAM;IACtB,QAAQ,KAAK,MAAM;IACnB;GACJ;GACA,MAAM,KAAK,IAAI;GACf;EACJ,OAAO;GACH,MAAM,QAAQ,KAAK,QAAQ,KAAK,CAAC;GACjC,MAAM,MAAM,UAAU,KAAK,KAAK,SAAS;GACzC,MAAM,OAAO,KAAK,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK;GACrC,IAAI,MAAM,MAAM,KAAK,IAAI;GACzB,IAAI;EACR;EAEA,OAAO,IAAI,KAAK,UAAU,KAAK,OAAO,KAAK;EAC3C;CACJ;CACA,OAAO;AACX;AA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