@rebasepro/studio 0.30.0 → 0.31.0-canary.g59cd6fd

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/{ApiKeysView-Bqf6XYR1.js → ApiKeysView-9ZvwMPyh.js} +16 -6
  2. package/dist/ApiKeysView-9ZvwMPyh.js.map +1 -0
  3. package/dist/{JSEditor-DCnPXsx6.js → JSEditor-ojAVSkaU.js} +158 -100
  4. package/dist/JSEditor-ojAVSkaU.js.map +1 -0
  5. package/dist/{RLSEditor-zAat58U0.js → RLSEditor-BAwkENpj.js} +394 -206
  6. package/dist/RLSEditor-BAwkENpj.js.map +1 -0
  7. package/dist/{SQLEditor-DV_VEEpL.js → SQLEditor-DX9LfbU7.js} +10 -8
  8. package/dist/SQLEditor-DX9LfbU7.js.map +1 -0
  9. package/dist/{SchemaVisualizer-pCYQ_Ds6.js → SchemaVisualizer-C75TENPm.js} +196 -189
  10. package/dist/SchemaVisualizer-C75TENPm.js.map +1 -0
  11. package/dist/components/JSEditor/JSEditorSidebar.d.ts +3 -6
  12. package/dist/components/JSEditor/JSMonacoEditor.d.ts +10 -10
  13. package/dist/components/JSEditor/table_access.d.ts +39 -0
  14. package/dist/components/RLSEditor/policy-presets.d.ts +1 -1
  15. package/dist/components/RLSEditor/policyListing.d.ts +32 -12
  16. package/dist/components/RLSEditor/policyRules.d.ts +32 -14
  17. package/dist/components/RLSEditor/saveRules.d.ts +48 -18
  18. package/dist/components/RLSEditor/saveSecurityRules.d.ts +5 -4
  19. package/dist/components/SchemaVisualizer/useSchemaGraph.d.ts +13 -8
  20. package/dist/components/schema-source.d.ts +37 -0
  21. package/dist/index.es.js +9 -9
  22. package/dist/index.es.js.map +1 -1
  23. package/dist/schema-source-C4ekB7WU.js +93 -0
  24. package/dist/schema-source-C4ekB7WU.js.map +1 -0
  25. package/dist/{sql_utils-DXvmxiCq.js → sql_utils-CYcgpgam.js} +14 -12
  26. package/dist/sql_utils-CYcgpgam.js.map +1 -0
  27. package/dist/utils/sql_utils.d.ts +14 -10
  28. package/package.json +9 -9
  29. package/dist/ApiKeysView-Bqf6XYR1.js.map +0 -1
  30. package/dist/JSEditor-DCnPXsx6.js.map +0 -1
  31. package/dist/RLSEditor-zAat58U0.js.map +0 -1
  32. package/dist/SQLEditor-DV_VEEpL.js.map +0 -1
  33. package/dist/SchemaVisualizer-pCYQ_Ds6.js.map +0 -1
  34. package/dist/sql_utils-DXvmxiCq.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { csvRecord, toSnakeCase } from "@rebasepro/utils";
1
+ import { csvRecord } from "@rebasepro/utils";
2
2
  import { astVisitor, parse } from "pgsql-ast-parser";
3
3
  //#region src/utils/sql_utils.ts
4
4
  /** The statements in `sqlText`, or `null` when the parser cannot read it. */
@@ -194,23 +194,24 @@ function tableReadOnce(sqlText, table) {
194
194
  return (mentions.get(table.toLowerCase()) ?? 0) !== 1 || withNames.some((name) => (mentions.get(name) ?? 0) > 1) ? refuse("studio_sql_edit_table_read_twice", { table }) : true;
195
195
  }
196
196
  /**
197
- * The collections a result's rows can be opened as: those whose table one of
198
- * the result's columns was read from, with the table's (single-column) primary
199
- * key read too, under a name no other column of the result has.
197
+ * The tables a result's rows can be opened as: those the server declares
198
+ * (`descriptors`, matched by SQL table and schema) whose table one of the
199
+ * result's columns was read from, with the table's (single-column) primary key
200
+ * read too, under a name no other column of the result has — and that
201
+ * `collectionFor` can open, by slug (the CMS's collection; nothing without a
202
+ * CMS on the page).
200
203
  *
201
204
  * Matched on the provenance the database reported. A text match took the
202
205
  * result's `id` for every table of a join: `SELECT p.id, a.name FROM posts p
203
206
  * JOIN authors a …` offered to open the author whose id was the post's.
204
207
  */
205
- function resolveQueryCollections(provenance, collections) {
208
+ function resolveQueryCollections(provenance, descriptors, collectionFor) {
206
209
  const results = [];
207
210
  for (const table of provenance.tables) {
208
- const collection = collections.find((c) => {
209
- const tableName = ("table" in c ? c.table : void 0) || toSnakeCase(c.slug);
210
- const schemaName = ("schema" in c ? c.schema : void 0) || "public";
211
- return tableName === table.table && schemaName === table.schema;
212
- });
213
- if (!collection || table.primaryKey.length !== 1) continue;
211
+ const descriptor = descriptors.find((d) => d.table === table.table && d.schema === table.schema);
212
+ if (!descriptor || table.primaryKey.length !== 1) continue;
213
+ const collection = collectionFor(descriptor.slug);
214
+ if (collection === void 0) continue;
214
215
  const [keyColumn] = table.primaryKey;
215
216
  const holders = provenance.columns.filter((column) => column.source?.schema === table.schema && column.source.table === table.table && column.source.column === keyColumn);
216
217
  if (holders.length !== 1) continue;
@@ -219,6 +220,7 @@ function resolveQueryCollections(provenance, collections) {
219
220
  results.push({
220
221
  tableName: table.table,
221
222
  schemaName: table.schema,
223
+ slug: descriptor.slug,
222
224
  collection,
223
225
  pkColumn
224
226
  });
@@ -493,4 +495,4 @@ function typedJsonRows(rows, columns) {
493
495
  //#endregion
494
496
  export { needsDestructiveConfirmation as a, rememberColumnWidth as c, resultsToCsv as d, tableStatementTemplates as f, withAutoLimit as h, keepLatestColumnWidths as i, resolveCellEdit as l, typedJsonRows as m, formatSql as n, quoteIdentifier as o, toCsv as p, groupSchemaRows as r, quoteTableName as s, buildExplainSql as t, resolveQueryCollections as u };
495
497
 
496
- //# sourceMappingURL=sql_utils-DXvmxiCq.js.map
498
+ //# sourceMappingURL=sql_utils-CYcgpgam.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql_utils-CYcgpgam.js","names":[],"sources":["../src/utils/sql_utils.ts"],"sourcesContent":["import { astVisitor, parse, type Statement } from \"pgsql-ast-parser\";\nimport { csvRecord } from \"@rebasepro/utils\";\nimport type { SqlScriptResult, TableDescriptor } from \"@rebasepro/types\";\nimport type { TableInfo } from \"../components/SQLEditor/sql_editor_types\";\n\n/** The statements in `sqlText`, or `null` when the parser cannot read it. */\nfunction parseStatements(sqlText: string): Statement[] | null {\n try {\n return parse(sqlText);\n } catch {\n return null;\n }\n}\n\n/**\n * The `EXPLAIN` for one statement, or `null` when `sqlText` is not exactly one.\n *\n * Never `ANALYZE`: that executes the statement to time it, so explaining a\n * `DELETE` deleted the rows — without the confirmation \"Run\" asks for.\n *\n * And never more than one statement. Sent as one simple query, `EXPLAIN (…)\n * SELECT 1; DELETE …` explains the SELECT and *runs* the DELETE. Text the\n * parser cannot read is still explained, as long as no `;` could be hiding a\n * second statement in it.\n */\nexport function buildExplainSql(sqlText: string): string | null {\n const statement = sqlText.trim().replace(/;+$/, \"\").trim();\n if (!statement) return null;\n const statements = parseStatements(statement);\n const single = statements ? statements.length === 1 : !statement.includes(\";\");\n return single ? `EXPLAIN (FORMAT JSON) ${statement}` : null;\n}\n\n/**\n * Whether the console's automatic `LIMIT` may be appended to `sqlText`: one\n * top-level SELECT that has no limit of its own.\n *\n * Decided on the parsed statement, not the text. A search for the word SELECT\n * also found it inside `INSERT INTO … SELECT` and `CREATE TABLE … AS SELECT`,\n * which then copied a thousand rows and reported success, and at the start of\n * a script whose last statement the appended `LIMIT` turned into a syntax\n * error. Text the parser cannot read is left as written.\n */\nexport function acceptsAutoLimit(sqlText: string): boolean {\n const statements = parseStatements(sqlText);\n if (!statements || statements.length !== 1) return false;\n const [statement] = statements;\n return statement.type === \"select\" && !statement.limit;\n}\n\n/** A destructive command named anywhere in a text, comments included. */\nconst DESTRUCTIVE_COMMAND = /\\b(DELETE|UPDATE|DROP|TRUNCATE)\\b/i;\n\nfunction isDestructiveStatement(statement: Statement): boolean {\n switch (statement.type) {\n case \"delete\":\n case \"update\":\n return !statement.where;\n case \"truncate table\":\n case \"drop table\":\n case \"drop sequence\":\n case \"drop index\":\n case \"drop type\":\n case \"drop trigger\":\n case \"drop function\":\n return true;\n case \"alter table\":\n return statement.changes.some(change => change.type === \"drop column\" || change.type === \"drop constraint\");\n case \"with\":\n return statement.bind.some(binding => isDestructiveStatement(binding.statement)) ||\n isDestructiveStatement(statement.in);\n case \"with recursive\":\n return isDestructiveStatement(statement.in);\n case \"do\":\n return DESTRUCTIVE_COMMAND.test(statement.code);\n default:\n return false;\n }\n}\n\n/**\n * Whether \"Run\" asks before running `sqlText`: a statement in it deletes or\n * updates without a WHERE of its own, drops or truncates.\n *\n * Decided per parsed statement, not on the text. A search of the text for the\n * word WHERE found it in another statement or in a comment, so `DELETE FROM\n * posts; SELECT * FROM posts WHERE id = 1` deleted every post without asking.\n * Text the parser cannot read is confirmed whenever it names a destructive\n * command.\n */\nexport function needsDestructiveConfirmation(sqlText: string): boolean {\n const statements = parseStatements(sqlText);\n if (!statements) return DESTRUCTIVE_COMMAND.test(sqlText);\n return statements.some(isDestructiveStatement);\n}\n\n/**\n * A table as SQL: `\"schema\".\"table\"` when a schema is given, a bare `\"table\"`\n * otherwise.\n */\nexport function quoteTableName(tableName: string, schemaName?: string): string {\n return schemaName ? `${quoteIdentifier(schemaName)}.${quoteIdentifier(tableName)}` : quoteIdentifier(tableName);\n}\n\n/** An identifier as SQL, whatever it holds: double-quoted, with `\"` doubled. */\nexport function quoteIdentifier(identifier: string): string {\n return `\"${identifier.replace(/\"/g, \"\\\"\\\"\")}\"`;\n}\n\n/**\n * The schema browser's statements for `table`, every name in them quoted. A\n * name is folded to lower case unless it is quoted, so `Posts` reads a table\n * `posts` that is not there and a column `createdAt` one called `createdat`;\n * and a reserved word is not a name at all — `SELECT * FROM user` answers\n * with the current role instead of reading the table. A table in `public` is\n * named without its schema.\n */\nexport function tableStatementTemplates(schemaName: string, table: Pick<TableInfo, \"tableName\" | \"columns\">): {\n selectTop: string;\n selectAll: string;\n insert: string;\n update: string;\n} {\n const from = schemaName === \"public\" ? quoteIdentifier(table.tableName) : quoteTableName(table.tableName, schemaName);\n const columns = table.columns.map(column => quoteIdentifier(column.name));\n return {\n selectTop: `SELECT * FROM ${from} LIMIT 100;`,\n selectAll: `SELECT \\n ${columns.join(\",\\n \")}\\nFROM ${from};`,\n insert: `INSERT INTO ${from} (\\n ${columns.join(\",\\n \")}\\n) VALUES (\\n ${columns.map(() => \"?\").join(\",\\n \")}\\n);`,\n update: `UPDATE ${from} \\nSET \\n ${columns.map(column => `${column} = ?`).join(\",\\n \")}\\nWHERE id = ?;`\n };\n}\n\n/** What the console knows about a result: its columns, and the tables they came from. */\nexport type ResultProvenance = Pick<SqlScriptResult, \"columns\" | \"tables\">;\n\n/**\n * The stored cell a result cell is, and the key that finds its row.\n */\nexport interface CellEditTarget {\n schema: string;\n table: string;\n /** The table column the edited value is written to. */\n column: string;\n /** Each primary key column of the table, and the result column holding its value for the row. */\n key: { column: string; resultColumn: string }[];\n}\n\n/**\n * Why a cell cannot be edited: a translation key of the console's, and its\n * parameters.\n */\nexport interface CellEditRefusal {\n key:\n | \"studio_sql_edit_unreadable_query\"\n | \"studio_sql_edit_not_a_select\"\n | \"studio_sql_edit_duplicate_column\"\n | \"studio_sql_edit_computed_column\"\n | \"studio_sql_edit_not_a_table\"\n | \"studio_sql_edit_inherited_table\"\n | \"studio_sql_edit_no_primary_key\"\n | \"studio_sql_edit_key_missing\"\n | \"studio_sql_edit_table_read_twice\";\n params: Record<string, string>;\n}\n\nexport type CellEditResolution =\n | { target: CellEditTarget; refusal?: undefined }\n | { target?: undefined; refusal: CellEditRefusal };\n\nconst refuse = (key: CellEditRefusal[\"key\"], params: Record<string, string> = {}): CellEditResolution =>\n ({ refusal: { key, params } });\n\n/**\n * Which stored cell an edit of the result column `resultColumn` writes, and\n * how its row is found again — or why no edit is safe.\n *\n * Decided on what the database reported, not on the query's text. Each\n * column of the result says which table column it was read from, or that it\n * was computed; a cell is editable only when it was read from a column of a\n * table, every column of that table's primary key was read too, and each of\n * them is the only column of the result with its name — a row holds one value\n * per name.\n *\n * The text was the only evidence before, and it was wrong twice over. For\n * `SELECT p.id, a.name FROM posts p JOIN authors a …` it took the post's `id`\n * for the author's key and updated whichever author shared the post's id.\n * For `SELECT id, lower(email) AS name FROM users` it wrote the edited text\n * to `users.name`.\n *\n * The database reports a table, not which mention of it: in a self-join both\n * sides are `authors`, and a key from one with a value from the other finds\n * the wrong row. So the query is still read, for one thing — the table must\n * be read once, and nothing it is read through may be read twice.\n */\nexport function resolveCellEdit(sqlText: string, provenance: ResultProvenance, resultColumn: string): CellEditResolution {\n const sameName = provenance.columns.filter(column => column.name === resultColumn);\n if (sameName.length !== 1) return refuse(\"studio_sql_edit_duplicate_column\", { column: resultColumn });\n const source = sameName[0].source;\n if (!source) return refuse(\"studio_sql_edit_computed_column\", { column: resultColumn });\n\n const tableLabel = `${source.schema}.${source.table}`;\n const table = provenance.tables.find(t => t.schema === source.schema && t.table === source.table);\n if (!table || (table.kind !== \"table\" && table.kind !== \"partitioned table\")) {\n return refuse(\"studio_sql_edit_not_a_table\", { column: resultColumn, table: tableLabel });\n }\n if (table.hasInheritors) return refuse(\"studio_sql_edit_inherited_table\", { table: tableLabel });\n if (table.primaryKey.length === 0) return refuse(\"studio_sql_edit_no_primary_key\", { table: tableLabel });\n\n const key: CellEditTarget[\"key\"] = [];\n for (const keyColumn of table.primaryKey) {\n const holders = provenance.columns.filter(column =>\n column.source?.schema === source.schema &&\n column.source.table === source.table &&\n column.source.column === keyColumn);\n const holder = holders.length === 1 && provenance.columns.filter(column => column.name === holders[0].name).length === 1\n ? holders[0]\n : undefined;\n if (!holder) return refuse(\"studio_sql_edit_key_missing\", { table: tableLabel, columns: table.primaryKey.join(\", \") });\n key.push({ column: keyColumn, resultColumn: holder.name });\n }\n\n const readOnce = tableReadOnce(sqlText, source.table);\n if (readOnce !== true) return readOnce;\n\n return { target: { schema: source.schema, table: source.table, column: source.column, key } };\n}\n\n/**\n * Whether `sqlText` is one SELECT that reads `table` once — counting every\n * mention of a table of that name, in any schema and at any depth, and every\n * mention of a `WITH` query, since one read twice reads its tables twice.\n */\nfunction tableReadOnce(sqlText: string, table: string): true | CellEditResolution {\n const statements = parseStatements(sqlText);\n if (!statements) return refuse(\"studio_sql_edit_unreadable_query\");\n if (statements.length !== 1) return refuse(\"studio_sql_edit_not_a_select\");\n const [statement] = statements;\n const isRead = statement.type === \"select\" ||\n (statement.type === \"with\" &&\n statement.in.type === \"select\" &&\n statement.bind.every(binding => binding.statement.type === \"select\"));\n if (!isRead) return refuse(\"studio_sql_edit_not_a_select\");\n\n const mentions = new Map<string, number>();\n const withNames: string[] = [];\n astVisitor(visitor => ({\n fromTable: from => {\n const name = from.name.name.toLowerCase();\n mentions.set(name, (mentions.get(name) ?? 0) + 1);\n visitor.super().fromTable(from);\n },\n with: withStatement => {\n withNames.push(...withStatement.bind.map(binding => binding.alias.name.toLowerCase()));\n visitor.super().with(withStatement);\n }\n })).statement(statement);\n\n const readTwice = (mentions.get(table.toLowerCase()) ?? 0) !== 1 ||\n withNames.some(name => (mentions.get(name) ?? 0) > 1);\n return readTwice ? refuse(\"studio_sql_edit_table_read_twice\", { table }) : true;\n}\n\n/**\n * A table whose records a query's rows can be opened as.\n */\nexport interface ResolvedQueryCollection<C> {\n /** The table, as the database named it. */\n tableName: string;\n schemaName: string;\n /** The table's slug, as the server declares it. */\n slug: string;\n /** What the record is opened with: the CMS collection the slug resolves to. */\n collection: C;\n /** The result column that holds the table's primary key. */\n pkColumn: string;\n}\n\n/**\n * The tables a result's rows can be opened as: those the server declares\n * (`descriptors`, matched by SQL table and schema) whose table one of the\n * result's columns was read from, with the table's (single-column) primary key\n * read too, under a name no other column of the result has — and that\n * `collectionFor` can open, by slug (the CMS's collection; nothing without a\n * CMS on the page).\n *\n * Matched on the provenance the database reported. A text match took the\n * result's `id` for every table of a join: `SELECT p.id, a.name FROM posts p\n * JOIN authors a …` offered to open the author whose id was the post's.\n */\nexport function resolveQueryCollections<C>(\n provenance: ResultProvenance,\n descriptors: readonly TableDescriptor[],\n collectionFor: (slug: string) => C | undefined\n): ResolvedQueryCollection<C>[] {\n const results: ResolvedQueryCollection<C>[] = [];\n for (const table of provenance.tables) {\n const descriptor = descriptors.find(d => d.table === table.table && d.schema === table.schema);\n if (!descriptor || table.primaryKey.length !== 1) continue;\n const collection = collectionFor(descriptor.slug);\n if (collection === undefined) continue;\n const [keyColumn] = table.primaryKey;\n const holders = provenance.columns.filter(column =>\n column.source?.schema === table.schema &&\n column.source.table === table.table &&\n column.source.column === keyColumn);\n if (holders.length !== 1) continue;\n const pkColumn = holders[0].name;\n if (provenance.columns.filter(column => column.name === pkColumn).length !== 1) continue;\n results.push({ tableName: table.table, schemaName: table.schema, slug: descriptor.slug, collection, pkColumn });\n }\n return results;\n}\n\n/**\n * A stretch of SQL text, by what it is to the database: code, or text that is\n * data and must not be rewritten — a string literal (quoted, `E'…'` or\n * dollar-quoted), a quoted identifier, or a comment.\n */\ninterface SqlSegment {\n text: string;\n kind: \"code\" | \"literal\" | \"identifier\" | \"line comment\" | \"block comment\";\n}\n\n/** A character an unquoted identifier or keyword can hold, `$` included. */\nconst IDENTIFIER_CHARACTER = /[A-Za-z0-9_$]/;\n\n/**\n * Cut `sqlText` into code and the things in it whose text is data.\n *\n * A lexer, not a parser: it reads text the parser refuses as well, which is\n * most of what a person types while writing a query.\n */\nfunction splitSql(sqlText: string): SqlSegment[] {\n const segments: SqlSegment[] = [];\n let code = \"\";\n const push = (text: string, kind: SqlSegment[\"kind\"]) => {\n if (code) segments.push({ text: code, kind: \"code\" });\n code = \"\";\n segments.push({ text, kind });\n };\n let i = 0;\n while (i < sqlText.length) {\n const ch = sqlText[i];\n const next = sqlText[i + 1];\n if (ch === \"-\" && next === \"-\") {\n const newline = sqlText.indexOf(\"\\n\", i);\n const end = newline === -1 ? sqlText.length : newline + 1;\n push(sqlText.slice(i, end), \"line comment\");\n i = end;\n continue;\n }\n if (ch === \"/\" && next === \"*\") {\n // Block comments nest in Postgres.\n let depth = 1;\n let j = i + 2;\n while (j < sqlText.length && depth > 0) {\n if (sqlText[j] === \"/\" && sqlText[j + 1] === \"*\") {\n depth++;\n j += 2;\n } else if (sqlText[j] === \"*\" && sqlText[j + 1] === \"/\") {\n depth--;\n j += 2;\n } else {\n j++;\n }\n }\n push(sqlText.slice(i, j), \"block comment\");\n i = j;\n continue;\n }\n if (ch === \"'\" || ch === \"\\\"\") {\n // `E'…'` takes backslash escapes; every quoted text takes its\n // quote doubled.\n const backslashEscapes = ch === \"'\" && /(^|[^A-Za-z0-9_$])[eE]$/.test(code);\n let j = i + 1;\n while (j < sqlText.length) {\n if (backslashEscapes && sqlText[j] === \"\\\\\") {\n j += 2;\n } else if (sqlText[j] === ch && sqlText[j + 1] === ch) {\n j += 2;\n } else if (sqlText[j] === ch) {\n j++;\n break;\n } else {\n j++;\n }\n }\n push(sqlText.slice(i, j), ch === \"'\" ? \"literal\" : \"identifier\");\n i = j;\n continue;\n }\n if (ch === \"$\" && !IDENTIFIER_CHARACTER.test(code.slice(-1))) {\n // `$tag$…$tag$` — not `$1`, a parameter, whose tag would start\n // with a digit.\n const tag = /^\\$(?:[A-Za-z_][A-Za-z0-9_]*)?\\$/.exec(sqlText.slice(i));\n if (tag) {\n const close = sqlText.indexOf(tag[0], i + tag[0].length);\n const end = close === -1 ? sqlText.length : close + tag[0].length;\n push(sqlText.slice(i, end), \"literal\");\n i = end;\n continue;\n }\n }\n code += ch;\n i++;\n }\n if (code) segments.push({ text: code, kind: \"code\" });\n return segments;\n}\n\n/**\n * The console's \"Format SQL\": runs of whitespace become one space, a comma is\n * followed by one, and an `=` standing alone gets one on each side — in the\n * code only.\n *\n * A literal, a quoted identifier and a comment are copied as they are: their\n * text is data, and rewriting `'a,b'` to `'a, b'` changes the value the next\n * Run writes. A line comment keeps the line break that ends it, or it would\n * swallow the code after it. `>=`, `<=`, `!=`, `:=` and `=>` are operators of\n * their own and are left whole.\n */\nexport function formatSql(sqlText: string): string {\n const segments = splitSql(sqlText);\n return segments.map((segment, index) => {\n if (segment.kind !== \"code\") return segment.text;\n const tidied = segment.text\n .replace(/\\s+/g, \" \")\n .replace(/\\s*,\\s*/g, \", \")\n .replace(/(?<![<>!:=~*+\\-/%^&|#@?])\\s*=\\s*(?![=>~*<])/g, \" = \");\n return segments[index - 1]?.kind === \"line comment\" ? tidied.trimStart() : tidied;\n }).join(\"\").trim();\n}\n\n/**\n * `sqlText` with the console's automatic `LIMIT` on it, or `null` when it\n * takes none (see {@link acceptsAutoLimit}).\n *\n * The limit goes straight after the statement's last token — before a\n * trailing comment, which would otherwise swallow it, and in place of a\n * trailing `;`. A query that computes an aggregate is limited like any other:\n * the limit applies to the rows it returns, so a `count(*)` still counts every\n * row, and a window `count(*) OVER ()` is no longer a way past the cap.\n */\nexport function withAutoLimit(sqlText: string, limit: number): string | null {\n if (!acceptsAutoLimit(sqlText)) return null;\n const segments = splitSql(sqlText);\n const isComment = (segment: SqlSegment) => segment.kind === \"line comment\" || segment.kind === \"block comment\";\n const isFiller = (segment: SqlSegment) => isComment(segment) || (segment.kind === \"code\" && /^[\\s;]*$/.test(segment.text));\n let last = segments.length - 1;\n while (last >= 0 && isFiller(segments[last])) last--;\n if (last < 0) return null;\n\n const lastSegment = segments[last];\n const head = lastSegment.kind === \"code\" ? lastSegment.text.replace(/[\\s;]+$/, \"\") : lastSegment.text;\n const after = lastSegment.kind === \"code\" ? lastSegment.text.slice(head.length) : \"\";\n // What follows the statement is comments and the space between them; its\n // `;` are dropped, the limit brings its own.\n const tail = after.replace(/;/g, \"\") + segments.slice(last + 1)\n .map(segment => segment.kind === \"code\" ? segment.text.replace(/;/g, \"\") : segment.text)\n .join(\"\");\n const before = segments.slice(0, last).map(segment => segment.text).join(\"\");\n return `${before}${head} LIMIT ${limit};${tail.trimEnd()}`;\n}\n\n/**\n * Rows as CSV text: a header record of column names, then one record per\n * row, each value under its own column.\n *\n * RFC 4180 with every record ended by CRLF — byte for byte what\n * `POST /api/admin/sql/csv` streams for the same result, so \"Export CSV\" and\n * \"Download full result as CSV\" write one format. They used to differ in\n * the line break (LF here), which a diff, a checksum or a strict reader\n * notices.\n */\nexport function toCsv(columns: readonly string[], rows: readonly Record<string, unknown>[]): string {\n const records = [csvRecord(columns), ...rows.map(row => csvRecord(columns.map(column => row[column])))];\n return records.map(record => record + \"\\r\\n\").join(\"\");\n}\n\n/**\n * The rows on screen as CSV text — {@link toCsv} over the first row's\n * columns.\n *\n * A value was quoted only when it held a comma, and a quote in it was never\n * doubled nor a line break quoted, so `say \"hi\"` or a two-line note broke the\n * row it was in.\n */\nexport function resultsToCsv(rows: Record<string, unknown>[]): string {\n if (rows.length === 0) return \"\";\n return toCsv(Object.keys(rows[0]), rows);\n}\n\n/** Column widths per query, as the console keeps them: SQL text → column → width. */\nexport type ColumnWidthsByQuery = Record<string, Record<string, number>>;\n\n/** How many queries' column widths the console remembers. */\nexport const COLUMN_WIDTHS_REMEMBERED = 50;\n\n/**\n * The widths kept, at most `limit` queries' worth, the most recently resized\n * last.\n *\n * They are kept per query text, in `localStorage`, and used to be kept\n * forever: every query anybody ever resized a column of stayed, whole SQL\n * text and all, in an origin's storage — which the console's tabs, snippets\n * and history share, and which a full store refuses to write at all. The\n * oldest go first; resizing a query's column again makes it the newest.\n */\nexport function rememberColumnWidth(\n widths: ColumnWidthsByQuery,\n sql: string,\n column: string,\n width: number,\n limit: number = COLUMN_WIDTHS_REMEMBERED\n): ColumnWidthsByQuery {\n const { [sql]: current, ...others } = widths;\n return keepLatestColumnWidths({ ...others, [sql]: { ...current, [column]: width } }, limit);\n}\n\n/**\n * The `limit` most recent queries' widths — the last ones in insertion\n * order — and only entries that are a column → width record.\n */\nexport function keepLatestColumnWidths(widths: Record<string, unknown>, limit: number = COLUMN_WIDTHS_REMEMBERED): ColumnWidthsByQuery {\n const kept: ColumnWidthsByQuery = {};\n for (const [sql, value] of Object.entries(widths).slice(-limit)) {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) continue;\n const columns: Record<string, number> = {};\n for (const [column, width] of Object.entries(value)) {\n if (typeof width === \"number\" && Number.isFinite(width)) columns[column] = width;\n }\n kept[sql] = columns;\n }\n return kept;\n}\n\n/**\n * The schema browser's tables, by schema, from `information_schema.columns`\n * rows: each table in the order it first appears, its columns in row order.\n *\n * A table is found by its key, not looked up among the schema's tables: that\n * lookup ran once per row over every table so far — 142 ms at 2,000 tables,\n * 923 ms at 5,000, on every open of the console.\n */\nexport function groupSchemaRows(data: Record<string, unknown>[]): Record<string, TableInfo[]> {\n const grouped: Record<string, TableInfo[]> = {};\n const tables = new Map<string, TableInfo>();\n for (const curr of data) {\n const schema = (curr.schema || curr.SCHEMA || curr.table_schema || \"public\") as string;\n const table = (curr.table || curr.TABLE || curr.table_name) as string;\n const column = (curr.column || curr.COLUMN || curr.column_name) as string;\n const dataType = (curr.data_type || curr.DATA_TYPE || \"\") as string;\n const isPrimaryKey = curr.is_pk === true || curr.is_pk === \"true\";\n\n const key = `${schema}\\u0000${table}`;\n let tableInfo = tables.get(key);\n if (!tableInfo) {\n tableInfo = { schemaName: schema, tableName: table, columns: [] };\n tables.set(key, tableInfo);\n (grouped[schema] ??= []).push(tableInfo);\n }\n tableInfo.columns.push({ name: column, dataType, isPrimaryKey });\n }\n return grouped;\n}\n\nconst INTEGER_TYPES = new Set([\"smallint\", \"integer\", \"bigint\"]);\nconst FLOAT_TYPES = new Set([\"real\", \"double precision\"]);\n\n/** How many significant digits a plain decimal (`-0012.3400`) has. */\nfunction significantDigits(decimal: string): number {\n const digits = decimal.replace(/^-/, \"\").replace(\".\", \"\").replace(/^0+/, \"\");\n return digits.replace(/0+$/, \"\").length;\n}\n\n/**\n * One value of the console's result, read by its column's type: an integer a\n * double holds exactly, a float, a numeric of at most 15 significant digits,\n * a boolean (`t`/`f`), json. Anything else — and any value that would change\n * on the way (a bigint past 2^53, a 20-digit numeric, `NaN`) — stays the\n * database's text. A value that is not text (a backend that returned typed\n * rows) or a column with no type is left as it came.\n */\nfunction typedValue(value: unknown, type: string | undefined): unknown {\n if (typeof value !== \"string\" || !type) return value;\n const base = type.replace(/\\(.*\\)$/, \"\").trim();\n if (INTEGER_TYPES.has(base)) {\n const number = Number(value);\n return /^-?\\d+$/.test(value) && Number.isSafeInteger(number) ? number : value;\n }\n if (FLOAT_TYPES.has(base)) {\n const number = Number(value);\n return value.trim() !== \"\" && Number.isFinite(number) ? number : value;\n }\n if (base === \"numeric\") {\n return /^-?\\d+(\\.\\d+)?$/.test(value) && significantDigits(value) <= 15 ? Number(value) : value;\n }\n if (base === \"boolean\") {\n return value === \"t\" ? true : value === \"f\" ? false : value;\n }\n if (base === \"json\" || base === \"jsonb\") {\n try {\n return JSON.parse(value);\n } catch {\n return value;\n }\n }\n return value;\n}\n\n/**\n * The console's rows for a typed JSON export: each value read by the type of\n * the column it is in (see `typedValue`), where \"Export JSON\" writes the\n * database's text as the console holds it. A row holds the last of two\n * columns that share a name, so that column's type is the one read.\n */\nexport function typedJsonRows(\n rows: Record<string, unknown>[],\n columns: readonly { name: string; type?: string }[]\n): Record<string, unknown>[] {\n const typeByName = new Map<string, string | undefined>();\n for (const column of columns) typeByName.set(column.name, column.type);\n return rows.map(row => Object.fromEntries(\n Object.entries(row).map(([key, value]) => [key, typedValue(value, typeByName.get(key))])\n ));\n}\n"],"mappings":";;;;AAMA,SAAS,gBAAgB,SAAqC;CAC1D,IAAI;EACA,OAAO,MAAM,OAAO;CACxB,QAAQ;EACJ,OAAO;CACX;AACJ;;;;;;;;;;;;AAaA,SAAgB,gBAAgB,SAAgC;CAC5D,MAAM,YAAY,QAAQ,KAAK,CAAC,CAAC,QAAQ,OAAO,EAAE,CAAC,CAAC,KAAK;CACzD,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,aAAa,gBAAgB,SAAS;CAE5C,QADe,aAAa,WAAW,WAAW,IAAI,CAAC,UAAU,SAAS,GAAG,KAC7D,yBAAyB,cAAc;AAC3D;;;;;;;;;;;AAYA,SAAgB,iBAAiB,SAA0B;CACvD,MAAM,aAAa,gBAAgB,OAAO;CAC1C,IAAI,CAAC,cAAc,WAAW,WAAW,GAAG,OAAO;CACnD,MAAM,CAAC,aAAa;CACpB,OAAO,UAAU,SAAS,YAAY,CAAC,UAAU;AACrD;;AAGA,IAAM,sBAAsB;AAE5B,SAAS,uBAAuB,WAA+B;CAC3D,QAAQ,UAAU,MAAlB;EACI,KAAK;EACL,KAAK,UACD,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AK;EAC3B,OAAO,UAAU,KAAK,KAAK,KAAK,OAAO,cAAc,MAAM,IAAI,SAAS;CAC5E;CACA,IAAI,YAAY,IAAI,IAAI,GAAG;EACvB,MAAM,SAAS,OAAO,KAAK;EAC3B,OAAO,MAAM,KAAK,MAAM,MAAM,OAAO,SAAS,MAAM,IAAI,SAAS;CACrE;CACA,IAAI,SAAS,WACT,OAAO,kBAAkB,KAAK,KAAK,KAAK,kBAAkB,KAAK,KAAK,KAAK,OAAO,KAAK,IAAI;CAE7F,IAAI,SAAS,WACT,OAAO,UAAU,MAAM,OAAO,UAAU,MAAM,QAAQ;CAE1D,IAAI,SAAS,UAAU,SAAS,SAC5B,IAAI;EACA,OAAO,KAAK,MAAM,KAAK;CAC3B,QAAQ;EACJ,OAAO;CACX;CAEJ,OAAO;AACX;;;;;;;AAQA,SAAgB,cACZ,MACA,SACyB;CACzB,MAAM,6BAAa,IAAI,IAAgC;CACvD,KAAK,MAAM,UAAU,SAAS,WAAW,IAAI,OAAO,MAAM,OAAO,IAAI;CACrE,OAAO,KAAK,KAAI,QAAO,OAAO,YAC1B,OAAO,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,WAAW,OAAO,WAAW,IAAI,GAAG,CAAC,CAAC,CAAC,CAC3F,CAAC;AACL"}
@@ -1,5 +1,4 @@
1
- import type { AdminCollection } from "@rebasepro/cms-types";
2
- import type { SqlScriptResult } from "@rebasepro/types";
1
+ import type { SqlScriptResult, TableDescriptor } from "@rebasepro/types";
3
2
  import type { TableInfo } from "../components/SQLEditor/sql_editor_types.js";
4
3
  /**
5
4
  * The `EXPLAIN` for one statement, or `null` when `sqlText` is not exactly one.
@@ -111,27 +110,32 @@ export type CellEditResolution = {
111
110
  */
112
111
  export declare function resolveCellEdit(sqlText: string, provenance: ResultProvenance, resultColumn: string): CellEditResolution;
113
112
  /**
114
- * A collection whose records a query's rows can be opened as.
113
+ * A table whose records a query's rows can be opened as.
115
114
  */
116
- export interface ResolvedQueryCollection {
115
+ export interface ResolvedQueryCollection<C> {
117
116
  /** The table, as the database named it. */
118
117
  tableName: string;
119
118
  schemaName: string;
120
- /** The matched collection */
121
- collection: AdminCollection;
119
+ /** The table's slug, as the server declares it. */
120
+ slug: string;
121
+ /** What the record is opened with: the CMS collection the slug resolves to. */
122
+ collection: C;
122
123
  /** The result column that holds the table's primary key. */
123
124
  pkColumn: string;
124
125
  }
125
126
  /**
126
- * The collections a result's rows can be opened as: those whose table one of
127
- * the result's columns was read from, with the table's (single-column) primary
128
- * key read too, under a name no other column of the result has.
127
+ * The tables a result's rows can be opened as: those the server declares
128
+ * (`descriptors`, matched by SQL table and schema) whose table one of the
129
+ * result's columns was read from, with the table's (single-column) primary key
130
+ * read too, under a name no other column of the result has — and that
131
+ * `collectionFor` can open, by slug (the CMS's collection; nothing without a
132
+ * CMS on the page).
129
133
  *
130
134
  * Matched on the provenance the database reported. A text match took the
131
135
  * result's `id` for every table of a join: `SELECT p.id, a.name FROM posts p
132
136
  * JOIN authors a …` offered to open the author whose id was the post's.
133
137
  */
134
- export declare function resolveQueryCollections(provenance: ResultProvenance, collections: AdminCollection[]): ResolvedQueryCollection[];
138
+ export declare function resolveQueryCollections<C>(provenance: ResultProvenance, descriptors: readonly TableDescriptor[], collectionFor: (slug: string) => C | undefined): ResolvedQueryCollection<C>[];
135
139
  /**
136
140
  * The console's "Format SQL": runs of whitespace become one space, a comma is
137
141
  * followed by one, and an `=` standing alone gets one on each side — in the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebasepro/studio",
3
- "version": "0.30.0",
3
+ "version": "0.31.0-canary.g59cd6fd",
4
4
  "description": "Rebase Studio — the SQL editor, schema visualiser, RLS policy editor and API explorer.",
5
5
  "keywords": [
6
6
  "rebase",
@@ -35,19 +35,19 @@
35
35
  "pgsql-ast-parser": "12.0.2",
36
36
  "prism-react-renderer": "^2.4.1",
37
37
  "react-dropzone": "^19.1.1",
38
- "@rebasepro/cms-types": "0.30.0",
39
- "@rebasepro/client": "0.30.0",
40
- "@rebasepro/app": "0.30.0",
41
- "@rebasepro/common": "0.30.0",
42
- "@rebasepro/types": "0.30.0",
43
- "@rebasepro/ui": "0.30.0",
44
- "@rebasepro/utils": "0.30.0"
38
+ "@rebasepro/cms-types": "0.31.0-canary.g59cd6fd",
39
+ "@rebasepro/client": "0.31.0-canary.g59cd6fd",
40
+ "@rebasepro/app": "0.31.0-canary.g59cd6fd",
41
+ "@rebasepro/types": "0.31.0-canary.g59cd6fd",
42
+ "@rebasepro/ui": "0.31.0-canary.g59cd6fd",
43
+ "@rebasepro/utils": "0.31.0-canary.g59cd6fd",
44
+ "@rebasepro/common": "0.31.0-canary.g59cd6fd"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "react": "^19.2.7",
48
48
  "react-dom": "^19.2.7",
49
49
  "react-router": "^8.3.0",
50
- "@rebasepro/cms": "0.30.0"
50
+ "@rebasepro/cms": "0.31.0-canary.g59cd6fd"
51
51
  },
52
52
  "peerDependenciesMeta": {
53
53
  "@rebasepro/cms": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"ApiKeysView-Bqf6XYR1.js","names":[],"sources":["../src/components/ApiKeys/scopes.ts","../src/components/ApiKeys/scope-words.ts","../src/components/ApiKeys/CreateApiKeyDialog.tsx","../src/components/ApiKeys/ApiKeysView.tsx"],"sourcesContent":["/**\n * The pure half of the API-key panel: reading a key's scopes back as groups a\n * person can scan, and turning the create dialog's picker into the scope list\n * the server mints.\n *\n * The vocabulary itself — what a scope is, which ones take a target, which\n * plane each belongs to — is `@rebasepro/types`' `scopes.ts`, the same module\n * the server enforces with. Nothing here re-derives it; this file only shapes\n * it for the screen, so it can be tested without rendering one.\n *\n * @module\n */\n\nimport {\n describeScope,\n isAdminScope,\n isDataPlaneScope,\n KEY_MANAGEMENT_SCOPES,\n parseScope,\n scopeGrantsAny,\n scopeTargets,\n summarizeScopes,\n type ScopeSummary\n} from \"@rebasepro/types\";\n\n/** Which plane a scope belongs to, as `GET /auth/scopes` names it. */\nexport type ScopePlane = ScopeSummary[\"plane\"];\n\n/** The planes in the order the panel shows them. */\nexport const SCOPE_PLANES: readonly ScopePlane[] = [\"data\", \"admin\", \"app\"];\n\n/* ═══════════════════════════════════════════════════════════════\n Reading a key's scopes\n ═══════════════════════════════════════════════════════════════ */\n\n/** One scope a key holds, with every target it holds it on. */\nexport interface HeldScope {\n /** `resource:action`, without a target. */\n scope: string;\n label: string;\n description: string;\n plane: ScopePlane;\n /** What a target names — `collection`, `bucket`, `function`, or an app's own word. */\n targetKind?: string;\n /** `\"all\"` for the unqualified grant, otherwise the targets it is narrowed to. */\n targets: \"all\" | string[];\n}\n\nexport interface ScopeGroup {\n plane: ScopePlane;\n scopes: HeldScope[];\n}\n\nfunction planeOf(scope: string): ScopePlane {\n if (isDataPlaneScope(scope)) return \"data\";\n if (isAdminScope(scope)) return \"admin\";\n return \"app\";\n}\n\n/**\n * A key's scopes, grouped by plane and folded per scope: `data:read:posts` and\n * `data:read:authors` read as one \"Read data\" row narrowed to two collections,\n * and `data:read` beside them as the same row on every collection.\n *\n * Ordered the way the catalogue lists scopes; a scope the catalogue does not\n * know (an app scope removed since the key was minted) keeps its raw name and\n * lands at the end of the plane it would belong to.\n */\nexport function groupKeyScopes(\n scopes: readonly string[],\n catalogue: readonly ScopeSummary[] = summarizeScopes()\n): ScopeGroup[] {\n const bases: string[] = [];\n for (const entry of scopes) {\n const base = parseScope(entry)?.scope ?? entry;\n if (!bases.includes(base)) bases.push(base);\n }\n\n const position = (base: string): number => {\n const index = catalogue.findIndex(summary => summary.scope === base);\n return index < 0 ? catalogue.length + bases.indexOf(base) : index;\n };\n bases.sort((a, b) => position(a) - position(b));\n\n const held: HeldScope[] = bases.map(base => {\n const summary = catalogue.find(entry => entry.scope === base);\n const parsed = parseScope(base);\n const fallback = describeScope(base);\n return {\n scope: base,\n label: summary?.label ?? fallback.label,\n description: summary?.description ?? fallback.description,\n plane: summary?.plane ?? planeOf(base),\n ...(summary?.target ? { targetKind: summary.target } : {}),\n targets: parsed ? scopeTargets(scopes, base) : \"all\"\n };\n });\n\n return SCOPE_PLANES\n .map(plane => ({ plane, scopes: held.filter(entry => entry.plane === plane) }))\n .filter(group => group.scopes.length > 0);\n}\n\n/* ═══════════════════════════════════════════════════════════════\n What the create dialog may offer\n ═══════════════════════════════════════════════════════════════ */\n\n/** Never offered: a key that manages keys could mint its own successor. */\nexport function isKeyManagementScope(scope: string): boolean {\n return (KEY_MANAGEMENT_SCOPES as readonly string[]).includes(scope);\n}\n\n/**\n * The catalogue entries a caller may put on a key: the ones they hold, on at\n * least one target, minus key management. The server refuses anything else\n * (`SCOPE_EXCEEDS_CREATOR`, `KEY_MANAGEMENT_SCOPE`), so offering it would only\n * be a way to fail.\n */\nexport function grantableScopes(catalogue: readonly ScopeSummary[], held: readonly string[]): ScopeSummary[] {\n return catalogue.filter(summary => !isKeyManagementScope(summary.scope) && scopeGrantsAny(held, summary.scope));\n}\n\n/* ═══════════════════════════════════════════════════════════════\n Picker state\n ═══════════════════════════════════════════════════════════════ */\n\n/** For one chosen scope: every target, or only the listed ones. */\nexport type TargetChoice =\n | { mode: \"all\" }\n | { mode: \"some\"; targets: string[] };\n\n/** The chosen scopes, keyed by `resource:action`. A scope absent here is not chosen. */\nexport type ScopeSelection = Readonly<Record<string, TargetChoice>>;\n\n/** `data:read` on everything — the narrowest useful key, and what the dialog opens with. */\nexport function defaultSelection(grantable: readonly ScopeSummary[]): ScopeSelection {\n return grantable.some(summary => summary.scope === \"data:read\") ? { \"data:read\": { mode: \"all\" } } : {};\n}\n\nfunction cleanTargets(targets: readonly string[]): string[] {\n const out: string[] = [];\n for (const raw of targets) {\n const target = raw.trim();\n if (target && !/\\s/.test(target) && !out.includes(target)) out.push(target);\n }\n return out;\n}\n\n/**\n * The scope strings a selection mints, in catalogue order when one is given.\n *\n * A scope on every target is sent unqualified; one narrowed to targets is sent\n * once per target. A scope narrowed to no target at all grants nothing and is\n * left out — {@link incompleteScopes} is how the dialog says so.\n */\nexport function buildScopeList(selection: ScopeSelection, order: readonly string[] = []): string[] {\n const chosen = Object.keys(selection);\n const rank = (scope: string): number => {\n const index = order.indexOf(scope);\n return index < 0 ? order.length + chosen.indexOf(scope) : index;\n };\n const out: string[] = [];\n for (const scope of [...chosen].sort((a, b) => rank(a) - rank(b))) {\n const choice = selection[scope];\n if (choice.mode === \"all\") {\n out.push(scope);\n } else {\n for (const target of cleanTargets(choice.targets)) out.push(`${scope}:${target}`);\n }\n }\n return out;\n}\n\n/** Scopes switched to \"only some\" with nothing chosen yet. */\nexport function incompleteScopes(selection: ScopeSelection): string[] {\n return Object.entries(selection)\n .filter(([, choice]) => choice.mode === \"some\" && cleanTargets(choice.targets).length === 0)\n .map(([scope]) => scope);\n}\n\n/** Free text in a target field: commas or whitespace separate entries. */\nexport function splitList(text: string): string[] {\n return cleanTargets(text.split(/[\\s,]+/));\n}\n\n/* ═══════════════════════════════════════════════════════════════\n The roles a service key runs as\n ═══════════════════════════════════════════════════════════════ */\n\n/**\n * The roles a service key runs as beside `service`: the picked ones, then any\n * typed ones, deduplicated. `service` itself is every service key's identity\n * already, so listing it adds nothing and is dropped, as the server does.\n */\nexport function combineRoles(picked: readonly string[], typed: string): string[] {\n const out: string[] = [];\n for (const role of [...picked, ...splitList(typed)]) {\n const id = role.trim();\n if (id && id !== \"service\" && !out.includes(id)) out.push(id);\n }\n return out;\n}\n\n/* ═══════════════════════════════════════════════════════════════\n Limits\n ═══════════════════════════════════════════════════════════════ */\n\nexport const EXPIRY_CHOICES = [\"never\", \"7d\", \"30d\", \"90d\", \"1y\"] as const;\nexport type ExpiryChoice = (typeof EXPIRY_CHOICES)[number];\n\nconst EXPIRY_DAYS: Record<Exclude<ExpiryChoice, \"never\">, number> = { \"7d\": 7, \"30d\": 30, \"90d\": 90, \"1y\": 365 };\n\nexport function isExpiryChoice(value: string): value is ExpiryChoice {\n return (EXPIRY_CHOICES as readonly string[]).includes(value);\n}\n\n/** The `expires_at` an expiry choice sends: an ISO instant, or null for never. */\nexport function expiresAtFor(choice: ExpiryChoice, now: number = Date.now()): string | null {\n if (choice === \"never\") return null;\n return new Date(now + EXPIRY_DAYS[choice] * 86_400_000).toISOString();\n}\n\n/** The `rate_limit` a rate-limit field sends: a positive integer, or null for the server default. */\nexport function rateLimitFrom(text: string): number | null {\n const digits = text.replace(/\\D/g, \"\");\n if (!digits) return null;\n const value = parseInt(digits, 10);\n return value >= 1 ? value : null;\n}\n\n/* ═══════════════════════════════════════════════════════════════\n What the server answers\n ═══════════════════════════════════════════════════════════════ */\n\n/** The minting refusals the dialog names, beside the server's own message. */\nexport const KEY_ERROR_CODES = [\n \"INVALID_SCOPES\",\n \"SCOPE_EXCEEDS_CREATOR\",\n \"ROLE_EXCEEDS_CREATOR\",\n \"UNKNOWN_SCOPE_TARGET\",\n \"KEY_MANAGEMENT_SCOPE\"\n] as const;\nexport type KeyErrorCode = (typeof KEY_ERROR_CODES)[number];\n\nexport interface KeyError {\n /** One of {@link KEY_ERROR_CODES}, or null for anything else. */\n code: KeyErrorCode | null;\n /** The server's message, never re-worded. */\n message: string;\n}\n\nfunction codeOf(error: unknown): string | null {\n if (typeof error !== \"object\" || error === null || !(\"code\" in error)) return null;\n return typeof error.code === \"string\" ? error.code : null;\n}\n\nfunction isKeyErrorCode(code: string | null): code is KeyErrorCode {\n return code !== null && (KEY_ERROR_CODES as readonly string[]).includes(code);\n}\n\nexport function readKeyError(error: unknown): KeyError {\n const code = codeOf(error);\n return {\n code: isKeyErrorCode(code) ? code : null,\n message: error instanceof Error ? error.message : String(error)\n };\n}\n\n/** The backend answered `403 PERSONAL_KEYS_DISABLED`: the app has not switched them on. */\nexport function isPersonalKeysDisabled(error: unknown): boolean {\n return codeOf(error) === \"PERSONAL_KEYS_DISABLED\";\n}\n\nfunction isStringArray(value: unknown): value is string[] {\n return Array.isArray(value) && value.every(entry => typeof entry === \"string\");\n}\n\nfunction isPlane(value: unknown): value is ScopePlane {\n return value === \"data\" || value === \"admin\" || value === \"app\";\n}\n\nfunction readScopeSummary(value: unknown): ScopeSummary | null {\n if (typeof value !== \"object\" || value === null) return null;\n if (!(\"scope\" in value) || typeof value.scope !== \"string\") return null;\n if (!(\"plane\" in value) || !isPlane(value.plane)) return null;\n const label = \"label\" in value && typeof value.label === \"string\" ? value.label : value.scope;\n const description = \"description\" in value && typeof value.description === \"string\" ? value.description : \"\";\n const target = \"target\" in value && typeof value.target === \"string\" ? value.target : undefined;\n return { scope: value.scope, label, description, plane: value.plane, ...(target ? { target } : {}) };\n}\n\n/** What `GET /auth/scopes` answers. */\nexport interface ScopeListing {\n scopes: ScopeSummary[];\n held: string[];\n}\n\n\n/**\n * Read `GET /auth/scopes`. Null for anything that is not that shape — a backend\n * older than scopes answers this route with something else, and offering a\n * picker built from it would offer scopes the server does not know.\n */\nexport function readScopeListing(body: unknown): ScopeListing | null {\n if (typeof body !== \"object\" || body === null) return null;\n if (!(\"scopes\" in body) || !Array.isArray(body.scopes)) return null;\n if (!(\"held\" in body) || !isStringArray(body.held)) return null;\n const scopes: ScopeSummary[] = [];\n for (const entry of body.scopes) {\n const summary = readScopeSummary(entry);\n if (summary) scopes.push(summary);\n }\n return { scopes, held: body.held };\n}\n\n/** Function names out of `GET /functions` — `{ functions: [{ name }] }`. */\nexport function functionNamesFrom(body: unknown): string[] {\n if (typeof body !== \"object\" || body === null || !(\"functions\" in body) || !Array.isArray(body.functions)) return [];\n const names: string[] = [];\n for (const entry of body.functions) {\n if (typeof entry === \"object\" && entry !== null && \"name\" in entry && typeof entry.name === \"string\" && entry.name) {\n names.push(entry.name);\n }\n }\n return names;\n}\n","/**\n * How the key panel words scopes: plane headings, \"every collection\", the\n * title over a minting refusal. One place, so the detail panel, the create\n * dialog and the secret confirmation cannot drift apart.\n *\n * Every string is a translation key. A built-in scope's label and description\n * are keys too, derived from the scope (`data:read` →\n * `studio_scope_data_read_label`); an app's own scopes are worded as the app\n * declared them, in the server's catalogue (`GET /auth/scopes`).\n *\n * @module\n */\n\nimport { DEFAULT_STORAGE_SOURCE_KEY, isBuiltInScope, type ScopeSummary } from \"@rebasepro/types\";\n\nimport type { HeldScope, KeyErrorCode, ScopePlane } from \"./scopes\";\n\n/** The panel's `t`, from `useTranslation()`. */\nexport type Translate = (key: string, vars?: Record<string, string | number>) => string;\n\n/** `data:read` → `studio_scope_data_read_label`. */\nexport function scopeLabelKey(scope: string): string {\n return `studio_scope_${scope.replace(/[^a-z0-9]/g, \"_\")}_label`;\n}\n\n/** `data:read` → `studio_scope_data_read_description`. */\nexport function scopeDescriptionKey(scope: string): string {\n return `studio_scope_${scope.replace(/[^a-z0-9]/g, \"_\")}_description`;\n}\n\n/** The translation, or `fallback` when the catalogue has none — i18next answers a missing key with the key. */\nfunction translatedOr(t: Translate, key: string, fallback: string): string {\n const text = t(key);\n return text && text !== key ? text : fallback;\n}\n\n/**\n * The catalogue in the panel's language. Built-in scopes are translated; an\n * app scope keeps the label its app declared, and a built-in scope this panel\n * has no key for (one the server added since) keeps the server's wording\n * rather than rendering blank or as a key.\n */\nexport function localizeScopes(t: Translate, catalogue: readonly ScopeSummary[]): ScopeSummary[] {\n return catalogue.map(summary => isBuiltInScope(summary.scope)\n ? {\n ...summary,\n label: translatedOr(t, scopeLabelKey(summary.scope), summary.label),\n description: translatedOr(t, scopeDescriptionKey(summary.scope), summary.description)\n }\n : summary);\n}\n\nexport function planeLabel(t: Translate, plane: ScopePlane): string {\n switch (plane) {\n case \"data\": return t(\"studio_api_keys_plane_data\");\n case \"admin\": return t(\"studio_api_keys_plane_admin\");\n case \"app\": return t(\"studio_api_keys_plane_app\");\n }\n}\n\nexport function planeHint(t: Translate, plane: ScopePlane): string {\n switch (plane) {\n case \"data\": return t(\"studio_api_keys_plane_data_hint\");\n case \"admin\": return t(\"studio_api_keys_plane_admin_hint\");\n case \"app\": return t(\"studio_api_keys_plane_app_hint\");\n }\n}\n\n/** \"Every collection\", \"Every storage source\", \"Every function\", \"Any project\". */\nexport function everyTargetLabel(t: Translate, targetKind: string): string {\n switch (targetKind) {\n case \"collection\": return t(\"studio_api_keys_target_all_collection\");\n case \"bucket\": return t(\"studio_api_keys_target_all_bucket\");\n case \"function\": return t(\"studio_api_keys_target_all_function\");\n default: return t(\"studio_api_keys_target_all_other\", { kind: targetKind });\n }\n}\n\n/** One target as a person reads it: the default storage source is \"Default bucket\", not `(default)`. */\nexport function targetLabel(t: Translate, targetKind: string | undefined, target: string): string {\n if (targetKind === \"bucket\" && target === DEFAULT_STORAGE_SOURCE_KEY) return t(\"studio_api_keys_bucket_default\");\n return target;\n}\n\n/** A held scope as one line: \"Read data — posts, authors\", \"Read data — every collection\", \"Read server logs\". */\nexport function heldScopeLine(t: Translate, held: HeldScope): string {\n if (!held.targetKind && held.targets === \"all\") return held.label;\n const reach = held.targets === \"all\"\n ? everyTargetLabel(t, held.targetKind ?? \"\")\n : held.targets.map(target => targetLabel(t, held.targetKind, target)).join(\", \");\n return `${held.label} — ${reach}`;\n}\n\n/** The title over a refused create; the server's own message goes underneath. */\nexport function keyErrorTitle(t: Translate, code: KeyErrorCode | null): string {\n switch (code) {\n case \"INVALID_SCOPES\": return t(\"studio_api_keys_error_invalid_scopes\");\n case \"SCOPE_EXCEEDS_CREATOR\": return t(\"studio_api_keys_error_scope_exceeds_creator\");\n case \"ROLE_EXCEEDS_CREATOR\": return t(\"studio_api_keys_error_role_exceeds_creator\");\n case \"UNKNOWN_SCOPE_TARGET\": return t(\"studio_api_keys_error_unknown_scope_target\");\n case \"KEY_MANAGEMENT_SCOPE\": return t(\"studio_api_keys_error_key_management_scope\");\n case null: return t(\"studio_api_keys_error_generic\");\n }\n}\n","import React, { useEffect, useMemo, useState } from \"react\";\nimport {\n Alert,\n Button,\n Checkbox,\n CircularProgress,\n cls,\n DatabaseIcon,\n defaultBorderMixin,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n iconSize,\n Label,\n MultiSelect,\n MultiSelectItem,\n Select,\n SelectItem,\n ShieldIcon,\n TagIcon,\n TextField,\n Tooltip,\n Typography,\n WrenchIcon\n} from \"@rebasepro/ui\";\nimport {\n useApiBase,\n useApiConfig,\n useRebaseClient,\n useStorageSources,\n useStudioCollectionRegistry,\n useTranslation\n} from \"@rebasepro/app\";\nimport {\n DEFAULT_STORAGE_SOURCE_KEY,\n hasAdminRole,\n scopeTargets,\n type ApiKeyKind,\n type ApiKeyWithSecret,\n type RebaseClient,\n type RoleSummary,\n type ScopeSummary\n} from \"@rebasepro/types\";\n\nimport {\n buildScopeList,\n combineRoles,\n defaultSelection,\n EXPIRY_CHOICES,\n expiresAtFor,\n functionNamesFrom,\n grantableScopes,\n groupKeyScopes,\n incompleteScopes,\n isExpiryChoice,\n rateLimitFrom,\n readKeyError,\n SCOPE_PLANES,\n splitList,\n type ExpiryChoice,\n type KeyError,\n type ScopeListing,\n type ScopePlane,\n type ScopeSelection,\n type TargetChoice\n} from \"./scopes\";\nimport { everyTargetLabel, heldScopeLine, keyErrorTitle, localizeScopes, planeHint, planeLabel, type Translate } from \"./scope-words\";\n\n/** The scope catalogue as the panel holds it: still loading, read, or not readable. */\nexport type ScopeListingState =\n | { status: \"loading\" }\n | { status: \"ready\"; listing: ScopeListing }\n | { status: \"failed\"; message: string };\n\n/* ═══════════════════════════════════════════════════════════════\n Section heading\n ═══════════════════════════════════════════════════════════════ */\n\nfunction SectionLabel({ children, hint }: { children: React.ReactNode; hint?: React.ReactNode }) {\n return (\n <div className=\"flex items-baseline gap-2 mb-2\">\n <Typography\n variant=\"label\"\n className=\"text-2xs uppercase tracking-wider font-semibold text-surface-600 dark:text-surface-300\"\n gutterBottom={false}\n >\n {children}\n </Typography>\n {hint && (\n <Typography variant=\"caption\" color=\"secondary\" className=\"text-2xs\" gutterBottom={false}>\n {hint}\n </Typography>\n )}\n </div>\n );\n}\n\nexport function PlaneIcon({ plane, className }: { plane: ScopePlane; className?: string }) {\n const Component = plane === \"data\" ? DatabaseIcon : plane === \"admin\" ? WrenchIcon : TagIcon;\n return <Component size={iconSize.smallest} className={className}/>;\n}\n\n/* ═══════════════════════════════════════════════════════════════\n One scope in the picker\n ═══════════════════════════════════════════════════════════════ */\n\ninterface ScopeRowProps {\n summary: ScopeSummary;\n choice: TargetChoice | undefined;\n /** What the caller holds this scope on: every target, or only these. */\n reach: \"all\" | string[];\n /** The targets the panel can list for this scope's kind, or null to type them. */\n options: { value: string; label: string }[] | null;\n draft: string | undefined;\n onToggle: (on: boolean) => void;\n onChoice: (choice: TargetChoice) => void;\n onDraft: (text: string) => void;\n first: boolean;\n t: Translate;\n}\n\nfunction ScopeRow({ summary, choice, reach, options, draft, onToggle, onChoice, onDraft, first, t }: ScopeRowProps) {\n const id = `api-key-scope-${summary.scope.replace(/[^a-z0-9-]/gi, \"-\")}`;\n const targetKind = summary.target;\n const pickable = reach === \"all\" ? options : reach.map(value => ({ value, label: value }));\n return (\n <div className={cls(\"flex flex-col gap-2 px-3 py-2.5\", !first && cls(\"border-t\", defaultBorderMixin))}>\n <div className=\"flex items-start gap-3\">\n {/* The kit's checkbox sits in a 32px hit area; pulled up and left so\n the box lines up with the label's first line and the row's edge. */}\n <div className=\"-my-1.5 -ml-2 shrink-0\">\n <Checkbox id={id} size=\"small\" checked={!!choice} onCheckedChange={onToggle}/>\n </div>\n <Label htmlFor={id} className=\"flex-1 min-w-0 cursor-pointer\">\n <Typography variant=\"body2\" component=\"span\" gutterBottom={false} className=\"block text-[13px] font-medium\">\n {summary.label}\n </Typography>\n {summary.description && (\n <Typography variant=\"caption\" component=\"span\" color=\"secondary\" gutterBottom={false} className=\"block text-2xs leading-snug font-normal\">\n {summary.description}\n </Typography>\n )}\n </Label>\n <Typography variant=\"caption\" color=\"disabled\" gutterBottom={false} className=\"font-mono text-2xs shrink-0 pt-0.5\">\n {summary.scope}\n </Typography>\n </div>\n\n {choice && targetKind && (\n <div className=\"flex flex-wrap items-center gap-2 pl-9\">\n {reach === \"all\" && (\n <div className=\"w-52 shrink-0\">\n <Select\n size=\"small\"\n fullWidth\n position=\"popper\"\n value={choice.mode}\n aria-label={t(\"studio_api_keys_target_mode\")}\n onValueChange={(mode) => onChoice(mode === \"all\"\n ? { mode: \"all\" }\n : { mode: \"some\", targets: choice.mode === \"some\" ? choice.targets : [] })}\n renderValue={(mode) => mode === \"all\"\n ? everyTargetLabel(t, targetKind)\n : t(\"studio_api_keys_target_some\")}\n >\n <SelectItem value=\"all\">{everyTargetLabel(t, targetKind)}</SelectItem>\n <SelectItem value=\"some\">{t(\"studio_api_keys_target_some\")}</SelectItem>\n </Select>\n </div>\n )}\n {choice.mode === \"some\" && (pickable && pickable.length > 0\n ? (\n <div className=\"flex-1 min-w-[12rem]\">\n <MultiSelect\n size=\"small\"\n className=\"w-full\"\n value={choice.targets}\n placeholder={t(\"studio_api_keys_target_pick\")}\n onValueChange={(targets) => onChoice({ mode: \"some\", targets })}\n >\n {pickable.map(option => (\n <MultiSelectItem key={option.value} value={option.value}>\n {option.label}\n </MultiSelectItem>\n ))}\n </MultiSelect>\n </div>\n )\n : (\n <TextField\n size=\"small\"\n className=\"flex-1 min-w-[12rem]\"\n aria-label={t(\"studio_api_keys_target_typed_placeholder\", { kind: targetKind })}\n placeholder={t(\"studio_api_keys_target_typed_placeholder\", { kind: targetKind })}\n value={draft ?? (choice.mode === \"some\" ? choice.targets.join(\", \") : \"\")}\n onChange={(e) => {\n onDraft(e.target.value);\n onChoice({ mode: \"some\", targets: splitList(e.target.value) });\n }}\n />\n ))}\n </div>\n )}\n </div>\n );\n}\n\n/* ═══════════════════════════════════════════════════════════════\n Create API Key Dialog\n ═══════════════════════════════════════════════════════════════ */\n\nexport function CreateApiKeyDialog({\n kind,\n scopeListing,\n onRetryScopes,\n onClose,\n onCreated\n }: {\n /** A service key for the project, or a personal key for the signed-in account. */\n kind: ApiKeyKind;\n scopeListing: ScopeListingState;\n onRetryScopes: () => void;\n onClose: () => void;\n onCreated: (key: ApiKeyWithSecret) => void;\n}) {\n const client = useRebaseClient<RebaseClient>();\n const { t } = useTranslation();\n const collectionRegistry = useStudioCollectionRegistry();\n const storageSources = useStorageSources();\n const apiConfig = useApiConfig();\n const apiBase = useApiBase();\n\n const listing = scopeListing.status === \"ready\" ? scopeListing.listing : null;\n /** Built-in scopes in the panel's language; app scopes as the app declared them. */\n const catalogue = useMemo(() => listing ? localizeScopes(t, listing.scopes) : [], [listing, t]);\n const grantable = useMemo(() => listing ? grantableScopes(catalogue, listing.held) : [], [listing, catalogue]);\n const order = useMemo(() => catalogue.map(summary => summary.scope), [catalogue]);\n\n const [name, setName] = useState(\"\");\n /** Null until the person changes it: the default follows the catalogue once it arrives. */\n const [chosen, setChosen] = useState<ScopeSelection | null>(null);\n const [drafts, setDrafts] = useState<Record<string, string>>({});\n const [pickedRoles, setPickedRoles] = useState<string[]>([]);\n const [typedRoles, setTypedRoles] = useState(\"\");\n const [roleOptions, setRoleOptions] = useState<RoleSummary[]>([]);\n const [rolesUnavailable, setRolesUnavailable] = useState(false);\n const [rateLimit, setRateLimit] = useState(\"\");\n const [expiry, setExpiry] = useState<ExpiryChoice>(\"never\");\n const [creating, setCreating] = useState(false);\n const [error, setError] = useState<KeyError | null>(null);\n\n const selection = chosen ?? defaultSelection(grantable);\n\n /* ── What a target can name, for the scopes that take one ── */\n\n const collections = useMemo(\n () => (collectionRegistry?.collections ?? [])\n .map(col => col.slug)\n .filter((slug): slug is string => !!slug)\n .sort((a, b) => a.localeCompare(b)),\n [collectionRegistry?.collections]\n );\n\n const buckets = useMemo(() => {\n const keys = Object.keys(storageSources.sources);\n if (!keys.includes(DEFAULT_STORAGE_SOURCE_KEY)) keys.unshift(DEFAULT_STORAGE_SOURCE_KEY);\n return keys.map(key => ({\n value: key,\n label: storageSources.registry[key]?.label\n ?? (key === DEFAULT_STORAGE_SOURCE_KEY ? t(\"studio_api_keys_bucket_default\") : key)\n }));\n }, [storageSources.sources, storageSources.registry, t]);\n\n /**\n * Served functions, so a key can be narrowed to one by name. Best-effort:\n * a backend that serves none, or refuses the index, leaves the free-text\n * field — and the server refuses a name it does not serve.\n */\n const [functionNames, setFunctionNames] = useState<string[]>([]);\n useEffect(() => {\n if (!apiBase) return;\n let cancelled = false;\n (async () => {\n try {\n const token = await apiConfig?.getAuthToken?.();\n const res = await fetch(`${apiBase}/functions`, {\n headers: token ? { Authorization: `Bearer ${token}` } : undefined\n });\n if (!res.ok) return;\n const names = functionNamesFrom(await res.json());\n if (!cancelled) setFunctionNames(names);\n } catch {\n /* No listing available; the free-text field covers it. */\n }\n })();\n return () => { cancelled = true; };\n }, [apiBase, apiConfig]);\n\n const optionsFor = (summary: ScopeSummary): { value: string; label: string }[] | null => {\n switch (summary.target) {\n case \"collection\": return collections.map(slug => ({ value: slug, label: slug }));\n case \"bucket\": return buckets;\n case \"function\": return functionNames.map(fn => ({ value: fn, label: `${fn}()` }));\n default: return null;\n }\n };\n\n /* ── Roles a service key runs as ── */\n\n useEffect(() => {\n if (kind !== \"service\") return;\n const admin = client?.admin;\n if (!admin) {\n setRolesUnavailable(true);\n return;\n }\n let cancelled = false;\n admin.listRoles()\n .then(res => { if (!cancelled) setRoleOptions(res.roles); })\n .catch(() => { if (!cancelled) setRolesUnavailable(true); });\n return () => { cancelled = true; };\n }, [client, kind]);\n\n /* ── Picker edits ── */\n\n const toggle = (summary: ScopeSummary, on: boolean) => {\n setChosen(current => {\n const next: Record<string, TargetChoice> = { ...(current ?? defaultSelection(grantable)) };\n if (!on) {\n delete next[summary.scope];\n return next;\n }\n const reach = listing ? scopeTargets(listing.held, summary.scope) : \"all\";\n next[summary.scope] = reach === \"all\" ? { mode: \"all\" } : { mode: \"some\", targets: [] };\n return next;\n });\n };\n\n const setChoice = (scope: string, choice: TargetChoice) => {\n setChosen(current => ({ ...(current ?? defaultSelection(grantable)), [scope]: choice }));\n };\n\n /* ── What would be sent ── */\n\n const scopes = buildScopeList(selection, order);\n const incomplete = incompleteScopes(selection);\n const roles = kind === \"service\" ? combineRoles(pickedRoles, typedRoles) : [];\n const runsAsAdmin = hasAdminRole(roles);\n const granted = groupKeyScopes(scopes, catalogue);\n const labelOf = (scope: string) => catalogue.find(summary => summary.scope === scope)?.label ?? scope;\n\n const canSubmit = !!listing && !!name.trim() && scopes.length > 0 && incomplete.length === 0 && !creating;\n const submitBlockedReason = !name.trim()\n ? t(\"studio_api_keys_block_name\")\n : scopes.length === 0\n ? t(\"studio_api_keys_block_scopes\")\n : incomplete.length > 0\n ? t(\"studio_api_keys_block_targets\")\n : \"\";\n\n const handleCreate = async () => {\n if (!canSubmit || !client) return;\n setCreating(true);\n setError(null);\n try {\n const expires_at = expiresAtFor(expiry);\n const created = kind === \"service\"\n ? await client.apiKeys?.createKey({\n name: name.trim(),\n scopes,\n roles,\n rate_limit: rateLimitFrom(rateLimit),\n expires_at\n })\n : await client.personalKeys?.createKey({ name: name.trim(), scopes, expires_at });\n if (!created) {\n setError({ code: null, message: t(\"studio_api_keys_unsupported\") });\n return;\n }\n onCreated(created.key);\n } catch (e: unknown) {\n setError(readKeyError(e));\n } finally {\n setCreating(false);\n }\n };\n\n const planes = SCOPE_PLANES\n .map(plane => ({ plane, scopes: grantable.filter(summary => summary.plane === plane) }))\n .filter(group => group.scopes.length > 0);\n\n return (\n <Dialog open onOpenChange={(open) => { if (!open && !creating) onClose(); }} maxWidth=\"2xl\">\n\n <DialogTitle variant=\"subtitle1\" gutterBottom={false} className=\"font-semibold\">\n {kind === \"service\" ? t(\"studio_api_keys_create_title\") : t(\"studio_api_keys_create_personal_title\")}\n </DialogTitle>\n\n <DialogContent includeMargin={false} className=\"px-8 pt-2 pb-4 flex flex-col gap-6\">\n\n <Typography variant=\"body2\" color=\"secondary\" gutterBottom={false} className=\"text-[13px] max-w-[62ch]\">\n {kind === \"service\" ? t(\"studio_api_keys_create_intro\") : t(\"studio_api_keys_create_personal_intro\")}\n </Typography>\n\n <TextField\n label={t(\"studio_api_keys_field_name\")}\n value={name}\n onChange={(e) => setName(e.target.value)}\n placeholder={t(\"studio_api_keys_field_name_placeholder\")}\n size=\"small\"\n autoFocus\n />\n\n {/* ── Scopes ── */}\n <div>\n <SectionLabel hint={t(\"studio_api_keys_section_scopes_hint\")}>\n {t(\"studio_api_keys_scopes\")}\n </SectionLabel>\n\n {scopeListing.status === \"loading\" && (\n <div className=\"flex justify-center py-6\"><CircularProgress size=\"small\"/></div>\n )}\n\n {scopeListing.status === \"failed\" && (\n <Alert\n color=\"error\"\n size=\"small\"\n action={<Button size=\"small\" variant=\"text\" onClick={onRetryScopes}>{t(\"retry\")}</Button>}\n >\n <Typography variant=\"body2\" gutterBottom={false} className=\"font-medium\">\n {t(\"studio_api_keys_scopes_read_failed\")}\n </Typography>\n {scopeListing.message && (\n <Typography variant=\"caption\" gutterBottom={false} className=\"block font-mono break-all\">\n {scopeListing.message}\n </Typography>\n )}\n </Alert>\n )}\n\n {listing && (\n <div className=\"flex flex-col gap-4\">\n {planes.map(({ plane, scopes: offered }) => (\n <div key={plane}>\n <div className=\"flex items-center gap-2 mb-1.5\">\n <PlaneIcon plane={plane} className=\"text-surface-500 dark:text-surface-400\"/>\n <Typography variant=\"body2\" gutterBottom={false} className=\"text-[13px] font-medium\">\n {planeLabel(t, plane)}\n </Typography>\n <Typography variant=\"caption\" color=\"secondary\" gutterBottom={false} className=\"text-2xs truncate\">\n {planeHint(t, plane)}\n </Typography>\n </div>\n <div className={cls(\"rounded-lg border overflow-hidden\", defaultBorderMixin)}>\n {offered.map((summary, index) => (\n <ScopeRow\n key={summary.scope}\n summary={summary}\n choice={selection[summary.scope]}\n reach={scopeTargets(listing.held, summary.scope)}\n options={optionsFor(summary)}\n draft={drafts[summary.scope]}\n onToggle={(on) => toggle(summary, on)}\n onChoice={(choice) => setChoice(summary.scope, choice)}\n onDraft={(text) => setDrafts(current => ({ ...current, [summary.scope]: text }))}\n first={index === 0}\n t={t}\n />\n ))}\n </div>\n </div>\n ))}\n <Typography variant=\"caption\" color=\"secondary\" gutterBottom={false} className=\"text-2xs leading-snug max-w-[70ch]\">\n {t(\"studio_api_keys_scopes_offered_note\")}\n </Typography>\n </div>\n )}\n </div>\n\n {/* ── RLS roles ── */}\n {kind === \"service\" && (\n <div>\n <SectionLabel hint={t(\"studio_api_keys_roles_rows_hint\")}>\n {t(\"studio_api_keys_roles\")}\n </SectionLabel>\n <Typography variant=\"caption\" color=\"secondary\" gutterBottom={false} className=\"block mb-3 text-2xs leading-snug max-w-[70ch]\">\n {t(\"studio_api_keys_roles_explainer\")}\n </Typography>\n <div className=\"grid grid-cols-1 sm:grid-cols-2 gap-3 items-start\">\n {roleOptions.length > 0 && (\n <div>\n <MultiSelect\n size=\"small\"\n className=\"w-full\"\n label={t(\"roles\")}\n value={pickedRoles}\n onValueChange={setPickedRoles}\n >\n {roleOptions.map(role => (\n <MultiSelectItem key={role.id} value={role.id}>\n {role.name === role.id ? role.id : `${role.name} (${role.id})`}\n </MultiSelectItem>\n ))}\n </MultiSelect>\n </div>\n )}\n <TextField\n size=\"small\"\n label={t(\"studio_api_keys_roles_other\")}\n placeholder={t(\"studio_api_keys_roles_other_placeholder\")}\n value={typedRoles}\n onChange={(e) => setTypedRoles(e.target.value)}\n />\n </div>\n {rolesUnavailable && (\n <Typography variant=\"caption\" color=\"secondary\" gutterBottom={false} className=\"block mt-1.5 text-2xs\">\n {t(\"studio_api_keys_roles_unavailable\")}\n </Typography>\n )}\n {runsAsAdmin && (\n <Alert color=\"warning\" size=\"small\" outerClassName=\"mt-3\">\n {t(\"studio_api_keys_roles_admin_warning\")}\n </Alert>\n )}\n </div>\n )}\n\n {/* ── Limits ── */}\n <div>\n <SectionLabel>{t(\"studio_api_keys_section_limits\")}</SectionLabel>\n <div className=\"grid grid-cols-1 sm:grid-cols-2 gap-3 items-end\">\n {/* Each control gets its own cell: `Select.Root` renders no DOM\n node, so an unwrapped Select puts its label and its control\n into two separate grid items. */}\n <div>\n <Select\n label={t(\"studio_api_keys_stat_expires\")}\n value={expiry}\n onValueChange={(value) => { if (isExpiryChoice(value)) setExpiry(value); }}\n size=\"small\"\n fullWidth\n position=\"popper\"\n renderValue={(value) => expiryLabel(t, isExpiryChoice(value) ? value : \"never\")}\n >\n {EXPIRY_CHOICES.map(choice => (\n <SelectItem key={choice} value={choice}>{expiryLabel(t, choice)}</SelectItem>\n ))}\n </Select>\n </div>\n {kind === \"service\" && (\n <div>\n {/* Labelled above rather than floating inside, so it lines\n up with the Select beside it. */}\n <Label\n htmlFor=\"api-key-rate-limit\"\n className=\"block ml-3.5 mb-1 text-text-secondary dark:text-text-secondary-dark\"\n >\n {t(\"studio_api_keys_stat_rate_limit\")}\n </Label>\n <TextField\n id=\"api-key-rate-limit\"\n value={rateLimit}\n onChange={(e) => setRateLimit(e.target.value.replace(/\\D/g, \"\"))}\n placeholder=\"1000\"\n size=\"small\"\n endAdornment={\n <Typography variant=\"caption\" color=\"secondary\" component=\"span\" gutterBottom={false} className=\"text-2xs whitespace-nowrap\">\n {t(\"studio_api_keys_rate_limit_unit\")}\n </Typography>\n }\n />\n </div>\n )}\n </div>\n {kind === \"service\" && (\n <Typography variant=\"caption\" color=\"secondary\" gutterBottom={false} className=\"block mt-1.5 text-2xs\">\n {t(\"studio_api_keys_rate_limit_hint\")} {t(\"studio_api_keys_rate_limit_scope\")}\n </Typography>\n )}\n </div>\n\n {/* ── Plain-language read-back of the key being built ── */}\n {listing && (\n <div className={cls(\"rounded-lg border px-3 py-2.5 bg-surface-field\", defaultBorderMixin)}>\n <Typography\n variant=\"label\"\n gutterBottom={false}\n className=\"text-2xs uppercase tracking-wider font-semibold text-surface-600 dark:text-surface-300\"\n >\n {t(\"studio_api_keys_summary_title\")}\n </Typography>\n {granted.length === 0\n ? (\n <Typography variant=\"body2\" color=\"secondary\" gutterBottom={false} className=\"mt-1.5 text-[13px]\">\n {t(\"studio_api_keys_summary_empty\")}\n </Typography>\n )\n : (\n <div className=\"mt-1.5 flex flex-col gap-1\">\n {granted.flatMap(group => group.scopes.map(held => (\n <div key={held.scope} className=\"flex items-start gap-2\">\n <PlaneIcon plane={group.plane} className=\"mt-[3px] shrink-0 text-surface-500 dark:text-surface-400\"/>\n <Typography variant=\"body2\" gutterBottom={false} className=\"text-[13px] leading-snug\">\n {heldScopeLine(t, held)}\n </Typography>\n </div>\n )))}\n {kind === \"service\" && roles.length > 0 && (\n <div className=\"flex items-start gap-2\">\n <ShieldIcon\n size={iconSize.smallest}\n className={cls(\"mt-[3px] shrink-0\", runsAsAdmin\n ? \"text-amber-600 dark:text-amber-400\"\n : \"text-surface-500 dark:text-surface-400\")}\n />\n <Typography variant=\"body2\" gutterBottom={false} className=\"text-[13px] leading-snug\">\n {t(\"studio_api_keys_summary_roles\", { roles: [\"service\", ...roles].join(\", \") })}\n </Typography>\n </div>\n )}\n </div>\n )}\n {incomplete.length > 0 && (\n <Typography variant=\"caption\" color=\"secondary\" gutterBottom={false} className=\"block mt-2 text-2xs\">\n {incomplete.map(scope => t(\"studio_api_keys_target_missing\", { scope: labelOf(scope) })).join(\" \")}\n </Typography>\n )}\n </div>\n )}\n\n {error && (\n <Alert color=\"error\" size=\"small\">\n <Typography variant=\"body2\" gutterBottom={false} className=\"font-medium\">\n {keyErrorTitle(t, error.code)}\n </Typography>\n <Typography variant=\"caption\" gutterBottom={false} className=\"block leading-snug\">\n {error.message}\n </Typography>\n </Alert>\n )}\n\n </DialogContent>\n\n <DialogActions>\n <Button variant=\"text\" onClick={onClose} disabled={creating}>{t(\"cancel\")}</Button>\n <Tooltip title={submitBlockedReason}>\n <span>\n <Button\n color=\"primary\"\n onClick={handleCreate}\n disabled={!canSubmit}\n startIcon={creating ? <CircularProgress size=\"smallest\"/> : undefined}\n >\n {creating ? t(\"studio_api_keys_creating\") : t(\"studio_api_keys_create\")}\n </Button>\n </span>\n </Tooltip>\n </DialogActions>\n </Dialog>\n );\n}\n\nfunction expiryLabel(t: Translate, choice: ExpiryChoice): string {\n switch (choice) {\n case \"never\": return t(\"studio_api_keys_never\");\n case \"7d\": return t(\"studio_api_keys_expiry_7d\");\n case \"30d\": return t(\"studio_api_keys_expiry_30d\");\n case \"90d\": return t(\"studio_api_keys_expiry_90d\");\n case \"1y\": return t(\"studio_api_keys_expiry_1y\");\n }\n}\n","\nimport React, { useState, useEffect, useRef, useCallback, useMemo } from \"react\";\nimport {\n Alert,\n Button,\n Chip,\n CircularProgress,\n cls,\n defaultBorderMixin,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n IconButton,\n iconSize,\n KeyRoundIcon,\n RefreshCwIcon,\n ShieldIcon,\n Tab,\n Tabs,\n Tooltip,\n Typography,\n CopyIcon,\n PlusIcon as AddIcon,\n Trash2Icon as DeleteIcon,\n AlertCircleIcon,\n CheckCircleIcon\n} from \"@rebasepro/ui\";\nimport { useRebaseClient, useSnackbarController, useTranslation } from \"@rebasepro/app\";\nimport {\n ADMIN_ROLE,\n hasAdminRole,\n summarizeScopes,\n type ApiKeyKind,\n type ApiKeyMasked,\n type ApiKeyWithSecret,\n type RebaseClient,\n type ScopeSummary\n} from \"@rebasepro/types\";\n\nimport { CreateApiKeyDialog, PlaneIcon, type ScopeListingState } from \"./CreateApiKeyDialog\";\nimport { groupKeyScopes, isPersonalKeysDisabled, readScopeListing, type ScopeGroup } from \"./scopes\";\nimport { everyTargetLabel, heldScopeLine, localizeScopes, planeHint, planeLabel, targetLabel, type Translate } from \"./scope-words\";\nimport { classifyLoadFailure, type LoadFailure } from \"../load-failure\";\nimport { LoadFailureView } from \"../load-failure-view\";\n\n/* ═══════════════════════════════════════════════════════════════\n Helpers\n ═══════════════════════════════════════════════════════════════ */\n\n/** Within a day, relative and in the panel's language; beyond it, the date. */\nfunction formatRelative(iso: string | null | undefined, language: string): string {\n if (!iso) return \"—\";\n const date = new Date(iso);\n const diff = date.getTime() - Date.now();\n const abs = Math.abs(diff);\n try {\n if (abs >= 86_400_000) return date.toLocaleDateString(language);\n const format = new Intl.RelativeTimeFormat(language, { numeric: \"auto\", style: \"short\" });\n if (abs < 3_600_000) return format.format(Math.round(diff / 60_000), \"minute\");\n return format.format(Math.round(diff / 3_600_000), \"hour\");\n } catch {\n return date.toLocaleDateString();\n }\n}\n\nfunction isExpired(key: ApiKeyMasked): boolean {\n return !!(key.expires_at && new Date(key.expires_at) < new Date());\n}\n\ntype KeyStatusKind = \"active\" | \"expired\" | \"revoked\";\n\nfunction keyStatus(key: ApiKeyMasked): { kind: KeyStatusKind; color: string } {\n if (key.revoked_at) return { kind: \"revoked\", color: \"text-red-500\" };\n if (isExpired(key)) return { kind: \"expired\", color: \"text-amber-500\" };\n return { kind: \"active\", color: \"text-emerald-500\" };\n}\n\nfunction statusLabel(t: Translate, kind: KeyStatusKind): string {\n switch (kind) {\n case \"active\": return t(\"studio_api_keys_status_active\");\n case \"expired\": return t(\"studio_api_keys_status_expired\");\n case \"revoked\": return t(\"studio_api_keys_status_revoked\");\n }\n}\n\n/**\n * A service key that runs as `admin`: row-level security does not limit its\n * reads, writes or deletes, and it passes `admin` checks in functions and\n * storage. A personal key has no roles of its own.\n */\nfunction runsAsAdmin(key: ApiKeyMasked): boolean {\n return key.kind === \"service\" && hasAdminRole(key.roles);\n}\n\n/** One short phrase for a list row: the one scope a key holds, or how many. */\nfunction scopeBrief(t: Translate, groups: ScopeGroup[]): string {\n const held = groups.flatMap(group => group.scopes);\n if (held.length === 0) return \"—\";\n if (held.length === 1) return held[0].label;\n return t(\"studio_api_keys_scopes_count\", { count: held.length });\n}\n\n/**\n * The scope catalogue — every scope this backend knows, worded, and what the\n * signed-in account holds. The create dialog offers from it; the detail panel\n * labels a key's scopes with it, and falls back to the built-in wording while\n * it is loading or when this backend does not serve it.\n */\nfunction useScopeListing(client: RebaseClient | undefined): [ScopeListingState, () => void] {\n const [state, setState] = useState<ScopeListingState>({ status: \"loading\" });\n const [attempt, setAttempt] = useState(0);\n\n useEffect(() => {\n const api = client?.personalKeys;\n if (!api) {\n setState({ status: \"failed\", message: \"\" });\n return;\n }\n let cancelled = false;\n setState({ status: \"loading\" });\n (async () => {\n try {\n const listing = readScopeListing(await api.listScopes());\n if (!cancelled) setState(listing ? { status: \"ready\", listing } : { status: \"failed\", message: \"\" });\n } catch (e: unknown) {\n if (!cancelled) setState({ status: \"failed\", message: e instanceof Error ? e.message : String(e) });\n }\n })();\n return () => { cancelled = true; };\n }, [client, attempt]);\n\n const retry = useCallback(() => setAttempt(n => n + 1), []);\n return [state, retry];\n}\n\n/* ═══════════════════════════════════════════════════════════════\n Main Component\n ═══════════════════════════════════════════════════════════════ */\n\nexport function ApiKeysView() {\n const client = useRebaseClient<RebaseClient>();\n const { t } = useTranslation();\n const [kind, setKind] = useState<ApiKeyKind>(\"service\");\n const [scopeListing, retryScopes] = useScopeListing(client);\n\n const tabs = (\n <Tabs\n value={kind}\n onValueChange={(value) => setKind(value === \"personal\" ? \"personal\" : \"service\")}\n variant=\"boxy\"\n className=\"border-b border-hairline\"\n >\n <Tab value=\"service\">{t(\"studio_api_keys_tab_service\")}</Tab>\n <Tab value=\"personal\">{t(\"studio_api_keys_tab_personal\")}</Tab>\n </Tabs>\n );\n\n // Keyed by kind: each tab is its own list, selection and failure.\n return (\n <KeysPane\n key={kind}\n kind={kind}\n tabs={tabs}\n scopeListing={scopeListing}\n onRetryScopes={retryScopes}\n />\n );\n}\n\n/* ═══════════════════════════════════════════════════════════════\n One tab: service keys, or the signed-in account's own\n ═══════════════════════════════════════════════════════════════ */\n\nfunction KeysPane({\n kind,\n tabs,\n scopeListing,\n onRetryScopes\n }: {\n kind: ApiKeyKind;\n tabs: React.ReactNode;\n scopeListing: ScopeListingState;\n onRetryScopes: () => void;\n}) {\n const client = useRebaseClient<RebaseClient>();\n const snackbar = useSnackbarController();\n const { t } = useTranslation();\n const [keys, setKeys] = useState<ApiKeyMasked[]>([]);\n const [loading, setLoading] = useState(true);\n const [selectedId, setSelectedId] = useState<string | null>(null);\n const [showCreate, setShowCreate] = useState(false);\n const [showSecret, setShowSecret] = useState<ApiKeyWithSecret | null>(null);\n const [revoking, setRevoking] = useState<string | null>(null);\n const [confirmRevoke, setConfirmRevoke] = useState<ApiKeyMasked | null>(null);\n /** Why the key listing failed, classified — see `load-failure.ts`. */\n const [failure, setFailure] = useState<LoadFailure | null>(null);\n /** The backend answered PERSONAL_KEYS_DISABLED: a setting, not a failure. */\n const [personalOff, setPersonalOff] = useState(false);\n\n // Built-in scopes in the panel's language; app scopes as the app declared them.\n const catalogue: readonly ScopeSummary[] = useMemo(\n () => localizeScopes(t, scopeListing.status === \"ready\" ? scopeListing.listing.scopes : summarizeScopes()),\n [t, scopeListing]\n );\n\n const clientRef = useRef(client);\n clientRef.current = client;\n const snackbarRef = useRef(snackbar);\n snackbarRef.current = snackbar;\n\n const keysApi = useCallback(() => {\n const c = clientRef.current;\n return kind === \"service\" ? c?.apiKeys : c?.personalKeys;\n }, [kind]);\n\n const loadKeys = useCallback(async () => {\n const api = keysApi();\n if (!api) { setLoading(false); return; }\n try {\n const res = await api.listKeys();\n setKeys(res.keys);\n setFailure(null);\n setPersonalOff(false);\n } catch (e: unknown) {\n // \"No API keys yet\" is a claim about the project. A refused listing\n // is a claim about the caller, and only one of the two is an\n // invitation to create a key. Personal keys switched off is a third\n // thing: the app's own setting, explained rather than reported.\n if (kind === \"personal\" && isPersonalKeysDisabled(e)) {\n setPersonalOff(true);\n setFailure(null);\n } else {\n setFailure(classifyLoadFailure(e));\n }\n } finally {\n setLoading(false);\n }\n }, [keysApi, kind]);\n\n useEffect(() => { loadKeys(); }, [loadKeys]);\n\n const handleRevoke = async (id: string) => {\n const api = keysApi();\n if (!api) return;\n setRevoking(id);\n try {\n await api.revokeKey(id);\n snackbarRef.current.open({ type: \"success\", message: t(\"studio_api_keys_revoked\") });\n await loadKeys();\n if (selectedId === id) setSelectedId(null);\n } catch (e: unknown) {\n snackbarRef.current.open({ type: \"error\", message: e instanceof Error ? e.message : String(e) });\n } finally { setRevoking(null); }\n };\n\n const handleCreated = (keyWithSecret: ApiKeyWithSecret) => {\n setShowCreate(false);\n setShowSecret(keyWithSecret);\n loadKeys();\n };\n\n const selectedKey = keys.find(k => k.id === selectedId);\n const activeKeys = keys.filter(k => !k.revoked_at && !isExpired(k));\n const inactiveKeys = keys.filter(k => k.revoked_at || isExpired(k));\n\n return (\n <>\n <div className=\"flex h-full w-full overflow-hidden bg-surface-card\">\n {/* ── Key List ── */}\n <div className={cls(\"flex flex-col w-[340px] min-w-[280px] border-r h-full\", defaultBorderMixin)}>\n {tabs}\n <div className={cls(\"flex items-center justify-between px-4 py-2.5 border-b bg-surface-sheet min-h-[48px]\", defaultBorderMixin)}>\n <div className=\"flex items-center gap-2\">\n <KeyRoundIcon size={iconSize.smallest} className=\"text-primary\"/>\n <Typography variant=\"subtitle2\" className=\"font-semibold\">{t(\"studio_tool_api_keys\")}</Typography>\n <Chip size=\"smallest\" className=\"bg-surface-raised text-surface-600 dark:text-surface-300\">{activeKeys.length}</Chip>\n </div>\n <div className=\"flex items-center gap-1\">\n <IconButton aria-label={t(\"studio_api_keys_refresh\")} size=\"small\" onClick={loadKeys} title={t(\"studio_api_keys_refresh\")}><RefreshCwIcon size={iconSize.smallest}/></IconButton>\n <Button\n size=\"small\"\n color=\"primary\"\n disabled={personalOff}\n onClick={() => setShowCreate(true)}\n startIcon={<AddIcon size={iconSize.smallest}/>}\n >\n {t(\"studio_api_keys_new\")}\n </Button>\n </div>\n </div>\n <div className=\"flex-1 overflow-y-auto p-2 space-y-1\">\n {loading && (\n <div className=\"flex items-center justify-center h-full\"><CircularProgress/></div>\n )}\n {!loading && failure && (\n <LoadFailureView\n failure={failure}\n title={kind === \"service\" ? t(\"studio_api_keys_read_failed\") : t(\"studio_api_keys_personal_read_failed\")}\n deniedTitle={kind === \"service\" ? t(\"studio_api_keys_denied_title\") : t(\"studio_api_keys_personal_denied_title\")}\n deniedHint={kind === \"service\" ? t(\"studio_api_keys_denied_hint\") : t(\"studio_api_keys_personal_denied_hint\")}\n onRetry={loadKeys}\n />\n )}\n {!loading && personalOff && <PersonalKeysOff/>}\n {!loading && !failure && !personalOff && activeKeys.length === 0 && inactiveKeys.length === 0 && (\n <div className=\"flex flex-col items-center justify-center h-full gap-3 text-center p-6\">\n <KeyRoundIcon size={iconSize.medium} className=\"text-surface-300 dark:text-surface-600\"/>\n <Typography variant=\"body2\" color=\"secondary\">\n {kind === \"service\" ? t(\"studio_api_keys_empty_title\") : t(\"studio_api_keys_personal_empty_title\")}\n </Typography>\n <Typography variant=\"caption\" color=\"disabled\">\n {kind === \"service\" ? t(\"studio_api_keys_empty_hint\") : t(\"studio_api_keys_personal_empty_hint\")}\n </Typography>\n </div>\n )}\n {!loading && activeKeys.map(key => (\n <KeyListItem key={key.id} apiKey={key} catalogue={catalogue} selected={selectedId === key.id} onClick={() => setSelectedId(key.id)}/>\n ))}\n {!loading && inactiveKeys.length > 0 && (\n <>\n <div className=\"px-2 pt-3 pb-1\">\n <Typography variant=\"caption\" color=\"disabled\" className=\"text-[10px] uppercase tracking-wider font-medium\">{t(\"studio_api_keys_inactive_heading\")}</Typography>\n </div>\n {inactiveKeys.map(key => (\n <KeyListItem key={key.id} apiKey={key} catalogue={catalogue} selected={selectedId === key.id} onClick={() => setSelectedId(key.id)}/>\n ))}\n </>\n )}\n </div>\n </div>\n\n {/* ── Detail Panel ── */}\n <div className=\"flex-1 flex flex-col min-w-0 h-full overflow-hidden\">\n {!selectedKey ? (\n <div className=\"flex items-center justify-center h-full\">\n {!personalOff && (\n <Typography variant=\"body2\" color=\"disabled\">{t(\"studio_api_keys_select_hint\")}</Typography>\n )}\n </div>\n ) : (\n <KeyDetail\n apiKey={selectedKey}\n catalogue={catalogue}\n revoking={revoking === selectedKey.id}\n onRevoke={() => setConfirmRevoke(selectedKey)}\n />\n )}\n </div>\n </div>\n\n {/* Revoke Confirmation Dialog */}\n <Dialog\n open={confirmRevoke !== null}\n onOpenChange={(open) => {\n if (!open && !revoking) setConfirmRevoke(null);\n }}\n >\n <DialogTitle hidden>{t(\"studio_api_keys_revoke_confirmation\")}</DialogTitle>\n <DialogContent>\n <Typography variant=\"subtitle1\" className=\"font-semibold mb-2\">\n {t(\"studio_api_keys_revoke_title\", { name: confirmRevoke?.name ?? \"\" })}\n </Typography>\n <Typography variant=\"body2\" color=\"secondary\">\n {t(\"studio_api_keys_revoke_body\")}\n </Typography>\n </DialogContent>\n <DialogActions>\n <Button\n variant=\"text\"\n onClick={() => setConfirmRevoke(null)}\n disabled={revoking !== null}\n >\n {t(\"cancel\")}\n </Button>\n <Button\n color=\"error\"\n disabled={revoking !== null}\n startIcon={revoking !== null ? <CircularProgress size=\"smallest\"/> : <DeleteIcon size={iconSize.smallest}/>}\n onClick={async () => {\n if (!confirmRevoke) return;\n await handleRevoke(confirmRevoke.id);\n setConfirmRevoke(null);\n }}\n >\n {t(\"studio_api_keys_revoke\")}\n </Button>\n </DialogActions>\n </Dialog>\n\n {/* Create Dialog */}\n {showCreate && (\n <CreateApiKeyDialog\n kind={kind}\n scopeListing={scopeListing}\n onRetryScopes={onRetryScopes}\n onClose={() => setShowCreate(false)}\n onCreated={handleCreated}\n />\n )}\n\n {/* Secret Display Dialog */}\n {showSecret && (\n <SecretDisplayDialog\n keyWithSecret={showSecret}\n catalogue={catalogue}\n onClose={() => setShowSecret(null)}\n />\n )}\n </>\n );\n}\n\n/* ═══════════════════════════════════════════════════════════════\n Personal keys switched off\n ═══════════════════════════════════════════════════════════════ */\n\n/**\n * Not an error and not a refusal of this person: the app has not enabled\n * personal keys. Says what they are and where the switch is.\n */\nfunction PersonalKeysOff() {\n const { t } = useTranslation();\n return (\n <div className=\"flex flex-col items-center justify-center h-full gap-3 text-center p-6\">\n <KeyRoundIcon size={iconSize.medium} className=\"text-surface-300 dark:text-surface-600\"/>\n <Typography variant=\"body2\" color=\"secondary\">{t(\"studio_api_keys_personal_off_title\")}</Typography>\n <Typography variant=\"caption\" color=\"disabled\" className=\"max-w-[34ch]\">\n {t(\"studio_api_keys_personal_off_body\")}\n </Typography>\n <Typography variant=\"mono\" component=\"div\" className=\"text-[11px] px-2 py-1 rounded-md bg-surface-field\">\n {\"auth: { personalKeys: true }\"}\n </Typography>\n </div>\n );\n}\n\n/* ═══════════════════════════════════════════════════════════════\n List item\n ═══════════════════════════════════════════════════════════════ */\n\n/**\n * Marks a service key that runs as the admin role.\n *\n * Not cosmetic: such a key reads, changes and deletes every row its scopes\n * reach through the admin policies, and without this it is indistinguishable\n * in the list from a narrow one.\n */\nfunction AdminChip() {\n const { t } = useTranslation();\n return (\n <Tooltip title={t(\"studio_api_keys_admin_chip_tooltip\")}>\n <Chip size=\"smallest\" colorScheme=\"yellow\" className=\"shrink-0\" icon={<ShieldIcon size={10}/>}>\n {ADMIN_ROLE}\n </Chip>\n </Tooltip>\n );\n}\n\nfunction KeyListItem({ apiKey, catalogue, selected, onClick }: {\n apiKey: ApiKeyMasked;\n catalogue: readonly ScopeSummary[];\n selected: boolean;\n onClick: () => void;\n}) {\n const { t } = useTranslation();\n const status = keyStatus(apiKey);\n return (\n <div\n onClick={onClick}\n className={cls(\n \"flex items-center gap-3 px-3 py-2.5 rounded-lg cursor-pointer transition-all\",\n selected\n ? \"bg-primary/10 dark:bg-primary/15 ring-1 ring-primary/30\"\n : \"hover:bg-surface-hover\"\n )}\n >\n <div className={cls(\"w-2 h-2 rounded-full shrink-0\",\n status.kind === \"active\" ? \"bg-emerald-400\" :\n status.kind === \"expired\" ? \"bg-amber-400\" : \"bg-red-400\"\n )}/>\n <div className=\"flex-1 min-w-0\">\n <div className=\"flex items-center gap-1.5 min-w-0\">\n <Typography variant=\"body2\" className=\"truncate font-medium text-[13px]\">{apiKey.name}</Typography>\n {runsAsAdmin(apiKey) && <AdminChip/>}\n </div>\n <Typography variant=\"caption\" color=\"secondary\" className=\"truncate text-[11px] font-mono\">{apiKey.key_prefix}•••</Typography>\n </div>\n <div className=\"shrink-0\">\n <Typography variant=\"caption\" color=\"disabled\" className=\"text-[10px]\">\n {scopeBrief(t, groupKeyScopes(apiKey.scopes, catalogue))}\n </Typography>\n </div>\n </div>\n );\n}\n\n/* ═══════════════════════════════════════════════════════════════\n Detail\n ═══════════════════════════════════════════════════════════════ */\n\nfunction KeyDetail({ apiKey, catalogue, revoking, onRevoke }: {\n apiKey: ApiKeyMasked;\n catalogue: readonly ScopeSummary[];\n revoking: boolean;\n onRevoke: () => void;\n}) {\n const { t, i18n } = useTranslation();\n const language = i18n.language;\n const status = keyStatus(apiKey);\n const groups = groupKeyScopes(apiKey.scopes, catalogue);\n const service = apiKey.kind === \"service\";\n\n return (\n <>\n {/* Header */}\n <div className={cls(\"flex items-center justify-between px-5 py-3 border-b bg-surface-card min-h-[56px]\", defaultBorderMixin)}>\n <div className=\"flex items-center gap-3 min-w-0\">\n <KeyRoundIcon size={iconSize.small} className=\"text-primary shrink-0\"/>\n <div className=\"min-w-0\">\n <div className=\"flex items-center gap-2 min-w-0\">\n <Typography variant=\"subtitle1\" className=\"font-semibold truncate\">{apiKey.name}</Typography>\n {runsAsAdmin(apiKey) && <AdminChip/>}\n </div>\n <Typography variant=\"caption\" color=\"secondary\" className=\"font-mono text-[11px]\">{apiKey.key_prefix}•••</Typography>\n </div>\n </div>\n <div className=\"flex items-center gap-2 shrink-0\">\n {!apiKey.revoked_at && (\n <Button\n size=\"small\"\n color=\"error\"\n variant=\"outlined\"\n onClick={onRevoke}\n disabled={revoking}\n startIcon={revoking ? <CircularProgress size=\"smallest\"/> : <DeleteIcon size={iconSize.smallest}/>}\n >\n {t(\"studio_api_keys_revoke\")}\n </Button>\n )}\n </div>\n </div>\n\n {/* Stats */}\n <div className=\"px-5 py-4 bg-surface-sheet\">\n <div className=\"grid grid-cols-2 md:grid-cols-4 gap-3\">\n <StatCard label={t(\"studio_api_keys_stat_status\")} value={statusLabel(t, status.kind)} className={status.color}/>\n <StatCard label={t(\"created\")} value={formatRelative(apiKey.created_at, language)}/>\n <StatCard label={t(\"studio_api_keys_stat_last_used\")} value={formatRelative(apiKey.last_used_at, language)}/>\n <StatCard label={t(\"studio_api_keys_stat_expires\")} value={apiKey.expires_at ? formatRelative(apiKey.expires_at, language) : t(\"studio_api_keys_never\")}/>\n </div>\n <div className=\"grid grid-cols-2 md:grid-cols-3 gap-3 mt-3\">\n <StatCard\n label={t(\"studio_api_keys_stat_kind\")}\n value={service ? t(\"studio_api_keys_kind_service\") : t(\"studio_api_keys_kind_personal\")}\n />\n <StatCard\n label={t(\"studio_api_keys_stat_rate_limit\")}\n value={apiKey.rate_limit\n ? t(\"studio_api_keys_rate_limit_value\", { limit: apiKey.rate_limit })\n : t(\"studio_api_keys_rate_limit_default\")}\n />\n {service\n ? <StatCard label={t(\"studio_api_keys_stat_created_by\")} value={apiKey.created_by} mono/>\n : <StatCard label={t(\"studio_api_keys_stat_owner\")} value={apiKey.owner_uid ?? \"—\"} mono/>}\n </div>\n <Typography variant=\"caption\" color=\"secondary\" className=\"block mt-2 text-[11px] leading-snug\">\n {t(\"studio_api_keys_rate_limit_scope\")}\n </Typography>\n </div>\n\n {/* Scopes */}\n <div className={cls(\"flex items-center gap-2 px-5 py-2 border-y bg-surface-card\", defaultBorderMixin)}>\n <Typography variant=\"subtitle2\" className=\"font-semibold text-[13px]\">{t(\"studio_api_keys_scopes\")}</Typography>\n <Chip size=\"smallest\" className=\"bg-surface-raised text-surface-600 dark:text-surface-300\">\n {apiKey.scopes.length}\n </Chip>\n </div>\n <div className=\"flex-1 overflow-y-auto px-5 py-3 flex flex-col gap-5\">\n <RolesBlock apiKey={apiKey}/>\n {groups.length === 0\n ? <Typography variant=\"body2\" color=\"disabled\">{t(\"studio_api_keys_no_scopes\")}</Typography>\n : groups.map(group => (\n <div key={group.plane}>\n <BlockHeading\n icon={<PlaneIcon plane={group.plane} className=\"text-surface-500 dark:text-surface-400\"/>}\n label={planeLabel(t, group.plane)}\n hint={planeHint(t, group.plane)}\n />\n <div className=\"space-y-2\">\n {group.scopes.map(held => (\n <div key={held.scope} className={cls(\"flex items-center gap-3 px-3 py-2 rounded-lg border\", defaultBorderMixin)}>\n <div className=\"flex-1 min-w-0\">\n <div className=\"flex items-baseline gap-2 min-w-0\">\n <Typography variant=\"body2\" className=\"text-[13px] font-medium truncate\">\n {held.label}\n </Typography>\n <Typography variant=\"caption\" color=\"disabled\" className=\"font-mono text-[11px] shrink-0\">\n {held.scope}\n </Typography>\n </div>\n {held.description && (\n <Typography variant=\"caption\" color=\"secondary\" className=\"block text-[11px] leading-snug\">\n {held.description}\n </Typography>\n )}\n </div>\n {held.targetKind && (\n <div className=\"flex flex-wrap justify-end gap-1 shrink-0 max-w-[50%]\">\n {held.targets === \"all\"\n ? (\n <Chip size=\"smallest\" className=\"bg-surface-raised text-surface-600 dark:text-surface-300\">\n {everyTargetLabel(t, held.targetKind)}\n </Chip>\n )\n : held.targets.map(target => (\n <Chip key={target} size=\"smallest\" className=\"font-mono bg-surface-raised text-surface-700 dark:text-surface-200\">\n {targetLabel(t, held.targetKind, target)}\n </Chip>\n ))}\n </div>\n )}\n </div>\n ))}\n </div>\n </div>\n ))}\n </div>\n </>\n );\n}\n\nfunction BlockHeading({ icon, label, hint }: { icon: React.ReactNode; label: string; hint: string }) {\n return (\n <div className=\"flex items-center gap-2 mb-2 min-w-0\">\n {icon}\n <Typography variant=\"body2\" className=\"text-[13px] font-medium shrink-0\">{label}</Typography>\n <Typography variant=\"caption\" color=\"secondary\" className=\"text-[11px] truncate\">{hint}</Typography>\n </div>\n );\n}\n\n/**\n * Who the key runs as — which rows it reads. Scopes, below it, are which\n * endpoints it may call; the two are separate and both are shown.\n */\nfunction RolesBlock({ apiKey }: { apiKey: ApiKeyMasked }) {\n const { t } = useTranslation();\n const shield = <ShieldIcon size={iconSize.smallest} className=\"text-surface-500 dark:text-surface-400\"/>;\n\n if (apiKey.kind === \"personal\") {\n return (\n <div>\n <BlockHeading icon={shield} label={t(\"studio_api_keys_roles\")} hint={t(\"studio_api_keys_roles_rows_hint\")}/>\n <Typography variant=\"caption\" color=\"secondary\" className=\"block text-[12px] leading-snug\">\n {t(\"studio_api_keys_personal_roles\")}\n </Typography>\n </div>\n );\n }\n\n return (\n <div>\n <BlockHeading icon={shield} label={t(\"studio_api_keys_roles\")} hint={t(\"studio_api_keys_roles_rows_hint\")}/>\n <div className=\"flex flex-wrap gap-1.5\">\n <Chip size=\"small\" className=\"font-mono bg-surface-raised text-surface-600 dark:text-surface-300\">service</Chip>\n {apiKey.roles.map(role => (\n <Chip\n key={role}\n size=\"small\"\n colorScheme={role === ADMIN_ROLE ? \"yellow\" : undefined}\n className={cls(\"font-mono\", role !== ADMIN_ROLE && \"bg-surface-raised text-surface-700 dark:text-surface-200\")}\n >\n {role}\n </Chip>\n ))}\n </div>\n {runsAsAdmin(apiKey)\n ? (\n <Alert color=\"warning\" size=\"small\" outerClassName=\"mt-2\">\n {t(\"studio_api_keys_admin_bypasses_rls\")}\n </Alert>\n )\n : (\n <Typography variant=\"caption\" color=\"secondary\" className=\"block mt-1.5 text-[11px] leading-snug\">\n {apiKey.roles.length === 0 ? t(\"studio_api_keys_roles_service_only\") : t(\"studio_api_keys_roles_service_plus\")}\n </Typography>\n )}\n </div>\n );\n}\n\n/* ═══════════════════════════════════════════════════════════════\n Stat card\n ═══════════════════════════════════════════════════════════════ */\n\nfunction StatCard({ label, value, mono, className }: { label: string; value: string; mono?: boolean; className?: string }) {\n return (\n <div className={cls(\"px-3 py-2 rounded-lg border bg-surface-card\", defaultBorderMixin)}>\n <Typography variant=\"caption\" color=\"secondary\" className=\"text-[10px] uppercase tracking-wider font-medium\">{label}</Typography>\n <Typography variant=\"body2\" className={cls(\n \"mt-0.5 font-semibold text-[13px] truncate\",\n mono && \"font-mono\",\n className\n )}>{value}</Typography>\n </div>\n );\n}\n\n/* ═══════════════════════════════════════════════════════════════\n Secret Display Dialog — shown exactly once after creation\n ═══════════════════════════════════════════════════════════════ */\n\nfunction SecretDisplayDialog({ keyWithSecret, catalogue, onClose }: {\n keyWithSecret: ApiKeyWithSecret;\n catalogue: readonly ScopeSummary[];\n onClose: () => void;\n}) {\n const { t } = useTranslation();\n const snackbar = useSnackbarController();\n const [copied, setCopied] = useState(false);\n const granted = groupKeyScopes(keyWithSecret.scopes, catalogue).flatMap(group => group.scopes);\n\n const handleCopy = async () => {\n try {\n await navigator.clipboard.writeText(keyWithSecret.key);\n setCopied(true);\n snackbar.open({ type: \"success\", message: t(\"studio_api_keys_copied\") });\n setTimeout(() => setCopied(false), 2000);\n } catch {\n snackbar.open({ type: \"error\", message: t(\"studio_api_keys_copy_failed\") });\n }\n };\n\n return (\n <Dialog open onOpenChange={(open) => { if (!open) onClose(); }} maxWidth=\"md\">\n <DialogTitle>\n <div className=\"flex items-center gap-2\">\n <CheckCircleIcon size={iconSize.small} className=\"text-emerald-500\"/>\n {t(\"studio_api_keys_created_title\")}\n </div>\n </DialogTitle>\n <DialogContent>\n <div className=\"p-3 rounded-lg bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800/50 mb-4\">\n <div className=\"flex items-center gap-2 mb-1\">\n <AlertCircleIcon size={iconSize.smallest} className=\"text-amber-600 dark:text-amber-400\"/>\n <Typography variant=\"caption\" className=\"font-semibold text-amber-700 dark:text-amber-400\">\n {t(\"studio_api_keys_copy_now\")}\n </Typography>\n </div>\n <Typography variant=\"caption\" className=\"text-amber-600 dark:text-amber-300\">\n {t(\"studio_api_keys_copy_now_hint\")}\n </Typography>\n </div>\n\n <div className={cls(\"flex items-center gap-2 p-3 rounded-lg border bg-surface-sheet\", defaultBorderMixin)}>\n <code className=\"flex-1 text-[12px] font-mono break-all text-surface-700 dark:text-surface-300 select-all\">\n {keyWithSecret.key}\n </code>\n <Tooltip title={copied ? t(\"copied\") : t(\"copy\")}>\n <IconButton aria-label={copied ? t(\"copied\") : t(\"copy\")} size=\"small\" onClick={handleCopy}>\n {copied\n ? <CheckCircleIcon size={iconSize.smallest} className=\"text-emerald-500\"/>\n : <CopyIcon size={iconSize.smallest}/>\n }\n </IconButton>\n </Tooltip>\n </div>\n\n <div className=\"mt-4 space-y-1\">\n <Typography variant=\"caption\" color=\"secondary\" className=\"block\">\n <strong>{t(\"studio_api_keys_name_label\")}</strong> {keyWithSecret.name}\n </Typography>\n <Typography variant=\"caption\" color=\"secondary\" className=\"block\">\n <strong>{t(\"studio_api_keys_access_label\")}</strong>{\" \"}\n {granted.length > 0 ? granted.map(held => heldScopeLine(t, held)).join(\"; \") : \"—\"}\n </Typography>\n {runsAsAdmin(keyWithSecret) && (\n <Typography variant=\"caption\" className=\"flex items-center gap-1.5 text-amber-700 dark:text-amber-300\">\n <ShieldIcon size={iconSize.smallest} className=\"shrink-0\"/>\n <span><strong>{t(\"studio_api_keys_admin_granted\")}</strong> — {t(\"studio_api_keys_admin_granted_hint\")}</span>\n </Typography>\n )}\n </div>\n </DialogContent>\n <DialogActions>\n <Button color=\"primary\" onClick={onClose}>{t(\"studio_api_keys_done\")}</Button>\n </DialogActions>\n </Dialog>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA6BA,IAAa,eAAsC;CAAC;CAAQ;CAAS;AAAK;AAwB1E,SAAS,QAAQ,OAA2B;CACxC,IAAI,iBAAiB,KAAK,GAAG,OAAO;CACpC,IAAI,aAAa,KAAK,GAAG,OAAO;CAChC,OAAO;AACX;;;;;;;;;;AAWA,SAAgB,eACZ,QACA,YAAqC,gBAAgB,GACzC;CACZ,MAAM,QAAkB,CAAC;CACzB,KAAK,MAAM,SAAS,QAAQ;EACxB,MAAM,OAAO,WAAW,KAAK,CAAC,EAAE,SAAS;EACzC,IAAI,CAAC,MAAM,SAAS,IAAI,GAAG,MAAM,KAAK,IAAI;CAC9C;CAEA,MAAM,YAAY,SAAyB;EACvC,MAAM,QAAQ,UAAU,WAAU,YAAW,QAAQ,UAAU,IAAI;EACnE,OAAO,QAAQ,IAAI,UAAU,SAAS,MAAM,QAAQ,IAAI,IAAI;CAChE;CACA,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,IAAI,SAAS,CAAC,CAAC;CAE9C,MAAM,OAAoB,MAAM,KAAI,SAAQ;EACxC,MAAM,UAAU,UAAU,MAAK,UAAS,MAAM,UAAU,IAAI;EAC5D,MAAM,SAAS,WAAW,IAAI;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