nstantpage-agent 0.5.18 → 0.5.19
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/cli.js +1 -1
- package/dist/commands/start.js +1 -1
- package/dist/projectDb.js +52 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -25,7 +25,7 @@ const program = new Command();
|
|
|
25
25
|
program
|
|
26
26
|
.name('nstantpage')
|
|
27
27
|
.description('Local development agent for nstantpage.com — run projects on your machine, preview in the cloud')
|
|
28
|
-
.version('0.5.
|
|
28
|
+
.version('0.5.19');
|
|
29
29
|
program
|
|
30
30
|
.command('login')
|
|
31
31
|
.description('Authenticate with nstantpage.com')
|
package/dist/commands/start.js
CHANGED
|
@@ -25,7 +25,7 @@ import { TunnelClient } from '../tunnel.js';
|
|
|
25
25
|
import { LocalServer } from '../localServer.js';
|
|
26
26
|
import { PackageInstaller } from '../packageInstaller.js';
|
|
27
27
|
import { probeLocalPostgres, ensureLocalProjectDb, closeAdminPool, writeDatabaseUrlToEnv } from '../projectDb.js';
|
|
28
|
-
const VERSION = '0.5.
|
|
28
|
+
const VERSION = '0.5.19';
|
|
29
29
|
/**
|
|
30
30
|
* Resolve the backend API base URL.
|
|
31
31
|
* - If --backend is passed, use it
|
package/dist/projectDb.js
CHANGED
|
@@ -109,6 +109,58 @@ export async function ensureLocalProjectDb(projectId) {
|
|
|
109
109
|
await pool.query(`CREATE DATABASE ${name}`);
|
|
110
110
|
console.log(` [ProjectDb] Created database '${name}' for project ${projectId}`);
|
|
111
111
|
}
|
|
112
|
+
// Ensure the OS user has full access to all objects in the project database.
|
|
113
|
+
// Tables may have been created by 'postgres' (cloud migrations or container)
|
|
114
|
+
// but the agent connects as the OS user — grant privileges to prevent permission errors.
|
|
115
|
+
try {
|
|
116
|
+
const pg = await import('pg');
|
|
117
|
+
const projectPool = new pg.default.Pool({
|
|
118
|
+
host: PG_HOST,
|
|
119
|
+
port: parseInt(PG_PORT),
|
|
120
|
+
user: PG_USER,
|
|
121
|
+
password: PG_PASS,
|
|
122
|
+
database: name,
|
|
123
|
+
max: 1,
|
|
124
|
+
connectionTimeoutMillis: 5000,
|
|
125
|
+
});
|
|
126
|
+
try {
|
|
127
|
+
// Check if there are tables owned by someone else
|
|
128
|
+
const { rows: foreignTables } = await projectPool.query(`SELECT tablename, tableowner FROM pg_tables WHERE schemaname = 'public' AND tableowner != $1`, [PG_USER]);
|
|
129
|
+
if (foreignTables.length > 0) {
|
|
130
|
+
// Need to grant access — use the admin pool which connects to 'postgres' db,
|
|
131
|
+
// but we need a connection to the project db as the owner. Try via psql.
|
|
132
|
+
const adminProjectPool = new pg.default.Pool({
|
|
133
|
+
host: PG_HOST,
|
|
134
|
+
port: parseInt(PG_PORT),
|
|
135
|
+
user: foreignTables[0].tableowner, // connect as the table owner
|
|
136
|
+
password: '',
|
|
137
|
+
database: name,
|
|
138
|
+
max: 1,
|
|
139
|
+
connectionTimeoutMillis: 5000,
|
|
140
|
+
});
|
|
141
|
+
try {
|
|
142
|
+
await adminProjectPool.query(`GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO ${PG_USER}`);
|
|
143
|
+
await adminProjectPool.query(`GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO ${PG_USER}`);
|
|
144
|
+
await adminProjectPool.query(`ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO ${PG_USER}`);
|
|
145
|
+
await adminProjectPool.query(`ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO ${PG_USER}`);
|
|
146
|
+
console.log(` [ProjectDb] Granted ${PG_USER} access to tables in '${name}' (owned by ${foreignTables[0].tableowner})`);
|
|
147
|
+
}
|
|
148
|
+
catch (grantErr) {
|
|
149
|
+
console.warn(` [ProjectDb] Could not grant table permissions: ${grantErr.message}`);
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
await adminProjectPool.end();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
await projectPool.end();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch (permErr) {
|
|
161
|
+
// Non-fatal — permissions may or may not be an issue
|
|
162
|
+
console.warn(` [ProjectDb] Permission check skipped: ${permErr.message}`);
|
|
163
|
+
}
|
|
112
164
|
verifiedDbs.add(name);
|
|
113
165
|
return buildDatabaseUrl(name);
|
|
114
166
|
}
|
package/package.json
CHANGED