@pgplex/pgconsole 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.mjs CHANGED
@@ -41058,7 +41058,7 @@ async function loadConfig(configPath) {
41058
41058
  const path5 = configPath || "pgconsole.toml";
41059
41059
  if (!existsSync(path5)) {
41060
41060
  throw new Error(`Config file not found: ${path5}
41061
- See https://docs.pgconsole.com/configuration/toml-config`);
41061
+ See https://docs.pgconsole.com/configuration/config`);
41062
41062
  }
41063
41063
  const content = readFileSync(path5, "utf-8");
41064
41064
  const parsed = parse2(content);
@@ -41375,7 +41375,7 @@ See https://docs.pgconsole.com/configuration/toml-config`);
41375
41375
  }
41376
41376
  }
41377
41377
  const iam = [];
41378
- const validPermissions = ["read", "write", "ddl", "admin"];
41378
+ const validPermissions = ["read", "write", "ddl", "admin", "explain", "execute", "export"];
41379
41379
  const rawIAM = parsed.iam || [];
41380
41380
  for (let i2 = 0; i2 < rawIAM.length; i2++) {
41381
41381
  const rule = rawIAM[i2];
@@ -41395,10 +41395,13 @@ See https://docs.pgconsole.com/configuration/toml-config`);
41395
41395
  if (typeof perm !== "string") {
41396
41396
  throw new Error(`IAM rule ${ruleNum} has invalid permission: must be string`);
41397
41397
  }
41398
- if (!validPermissions.includes(perm)) {
41399
- throw new Error(`IAM rule ${ruleNum} has invalid permission: ${perm}. Must be one of: ${validPermissions.join(", ")}`);
41398
+ if (perm === "allPermissions") {
41399
+ permissions.push(...validPermissions);
41400
+ } else if (!validPermissions.includes(perm)) {
41401
+ throw new Error(`IAM rule ${ruleNum} has invalid permission: ${perm}. Must be one of: ${validPermissions.join(", ")}, allPermissions`);
41402
+ } else {
41403
+ permissions.push(perm);
41400
41404
  }
41401
- permissions.push(perm);
41402
41405
  }
41403
41406
  if (!Array.isArray(rule.members) || rule.members.length === 0) {
41404
41407
  throw new Error(`IAM rule ${ruleNum} missing required field: members (must be non-empty array)`);
@@ -41409,7 +41412,7 @@ See https://docs.pgconsole.com/configuration/toml-config`);
41409
41412
  throw new Error(`IAM rule ${ruleNum} has invalid member: must be non-empty string`);
41410
41413
  }
41411
41414
  const m2 = member.trim();
41412
- if (m2 === "allAuthenticatedUsers") {
41415
+ if (m2 === "allUsers") {
41413
41416
  members.push(m2);
41414
41417
  } else if (m2.startsWith("user:")) {
41415
41418
  const email = m2.slice(5);
@@ -41427,7 +41430,7 @@ See https://docs.pgconsole.com/configuration/toml-config`);
41427
41430
  }
41428
41431
  members.push(m2);
41429
41432
  } else {
41430
- throw new Error(`IAM rule ${ruleNum} has invalid member format: ${m2}. Must be "allAuthenticatedUsers", "user:xxx", or "group:xxx"`);
41433
+ throw new Error(`IAM rule ${ruleNum} has invalid member format: ${m2}. Must be "allUsers", "user:xxx", or "group:xxx"`);
41431
41434
  }
41432
41435
  }
41433
41436
  iam.push({ connection, permissions, members });
@@ -41452,13 +41455,6 @@ See https://docs.pgconsole.com/configuration/toml-config`);
41452
41455
  throw new Error(`Too many [[users]] entries: ${users.length} configured but current license only allows ${limit2}. Remove users or upgrade your license.`);
41453
41456
  }
41454
41457
  }
41455
- console.log(`Loaded ${users.length} user(s), ${groups.length} group(s), ${labels.length} label(s) and ${connections.length} connection(s) from ${path5}`);
41456
- if (ai) {
41457
- console.log(`AI configured with ${ai.providers.length} provider(s)`);
41458
- }
41459
- if (iam.length > 0) {
41460
- console.log(`IAM configured with ${iam.length} rule(s)`);
41461
- }
41462
41458
  }
41463
41459
  function getLabels() {
41464
41460
  return loadedConfig.labels;
@@ -57497,7 +57493,7 @@ function extractPostgresVersion(versionString) {
57497
57493
  }
57498
57494
 
57499
57495
  // server/lib/iam.ts
57500
- var ALL_PERMISSIONS = ["read", "write", "ddl", "admin"];
57496
+ var ALL_PERMISSIONS = ["read", "write", "ddl", "admin", "explain", "execute", "export"];
57501
57497
  function requirePermission(user, connectionId, permission, action) {
57502
57498
  if (!user) {
57503
57499
  throw new ConnectError("Authentication required", Code.Unauthenticated);
@@ -57542,7 +57538,7 @@ function getUserPermissions(email, connectionId) {
57542
57538
  continue;
57543
57539
  }
57544
57540
  const matches = rule.members.some((member) => {
57545
- if (member === "allAuthenticatedUsers") {
57541
+ if (member === "allUsers") {
57546
57542
  return true;
57547
57543
  }
57548
57544
  if (member.startsWith("user:")) {
@@ -57757,6 +57753,7 @@ function transformStatement(node, source) {
57757
57753
  if ("AlterPublicationStmt" in obj) return { kind: "alter_publication", source };
57758
57754
  if ("ReassignOwnedStmt" in obj) return { kind: "reassign_owned", source };
57759
57755
  if ("DropOwnedStmt" in obj) return { kind: "drop_owned", source };
57756
+ if ("CallStmt" in obj) return { kind: "call", source };
57760
57757
  return { kind: "unknown", raw: node, source };
57761
57758
  }
57762
57759
  function transformSelect(raw) {
@@ -62078,9 +62075,14 @@ function getRequiredPermission(kind) {
62078
62075
  switch (kind) {
62079
62076
  // Read-only
62080
62077
  case "select":
62081
- case "explain":
62082
62078
  case "show":
62083
62079
  return "read";
62080
+ // Explain
62081
+ case "explain":
62082
+ return "explain";
62083
+ // Execute (stored procedures)
62084
+ case "call":
62085
+ return "execute";
62084
62086
  // DML (data modification)
62085
62087
  case "insert":
62086
62088
  case "update":
@@ -62105,7 +62107,7 @@ function getRequiredPermission(kind) {
62105
62107
  case "revoke":
62106
62108
  case "refresh_matview":
62107
62109
  return "ddl";
62108
- // COPY depends on direction
62110
+ // COPY (data import/export via server filesystem)
62109
62111
  case "copy":
62110
62112
  return "write";
62111
62113
  // Session/transaction control - safe operations
@@ -92527,8 +92529,9 @@ app.use((req, res, next) => {
92527
92529
  async function start() {
92528
92530
  const args = parseArgs();
92529
92531
  const port = args.port || process.env.PORT || 9876;
92532
+ const configPath = args.config || "pgconsole.toml";
92530
92533
  try {
92531
- await loadConfig(args.config);
92534
+ await loadConfig(configPath);
92532
92535
  } catch (error) {
92533
92536
  console.error("Failed to load config:", error instanceof Error ? error.message : error);
92534
92537
  process.exit(1);
@@ -92546,9 +92549,40 @@ async function start() {
92546
92549
  console.error("\nConnection test failed:", error instanceof Error ? error.message : error);
92547
92550
  process.exit(1);
92548
92551
  }
92549
- app.listen(port, () => {
92552
+ const server = app.listen(port, () => {
92553
+ console.log(`
92554
+ ___
92555
+ /\\_ \\
92556
+ _____ __ ___ ___ ___ ____ ___\\//\\ \\ __
92557
+ /\\ '__\`\\ /'_ \`\\ /'___\\ / __\`\\ /' _ \`\\ /',__\\ / __\`\\\\ \\ \\ /'__\`\\
92558
+ \\ \\ \\L\\ \\/\\ \\L\\ \\/\\ \\__//\\ \\L\\ \\/\\ \\/\\ \\/\\__, \`\\/\\ \\L\\ \\\\_\\ \\_/\\ __/
92559
+ \\ \\ ,__/\\ \\____ \\ \\____\\ \\____/\\ \\_\\ \\_\\/\\____/\\ \\____//\\____\\ \\____\\
92560
+ \\ \\ \\/ \\/___L\\ \\/____/\\/___/ \\/_/\\/_/\\/___/ \\/___/ \\/____/\\/____/
92561
+ \\ \\_\\ /\\____/
92562
+ \\/_/ \\_/__/
92563
+
92564
+ Version ${"0.0.4"}
92565
+ `);
92550
92566
  console.log(`Server running on http://localhost:${port}`);
92567
+ const browserUrl = false ? `http://localhost:5173` : getExternalUrl() || `http://localhost:${port}`;
92568
+ console.log(`Open in browser: ${browserUrl}`);
92551
92569
  });
92570
+ server.on("error", (err) => {
92571
+ if (err.code === "EADDRINUSE") {
92572
+ console.error(`Error: Port ${port} is already in use.`);
92573
+ } else {
92574
+ console.error(`Error starting server: ${err.message}`);
92575
+ }
92576
+ process.exit(1);
92577
+ });
92578
+ const shutdown = () => {
92579
+ console.log("\nShutting down...");
92580
+ server.close(() => {
92581
+ process.exit(0);
92582
+ });
92583
+ };
92584
+ process.on("SIGTERM", shutdown);
92585
+ process.on("SIGINT", shutdown);
92552
92586
  }
92553
92587
  start();
92554
92588
  /*! Bundled license information: