dialog-survey 1.6.2 → 1.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dialog-survey",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "type": "module",
5
5
  "description": "AI-powered interview robot that conducts async multi-turn interviews via DingTalk",
6
6
  "repository": {
@@ -13,7 +13,8 @@
13
13
  "src/views/",
14
14
  "public/",
15
15
  "prisma/",
16
- "ecosystem.config.cjs"
16
+ "ecosystem.config.cjs",
17
+ "package-lock.json"
17
18
  ],
18
19
  "bin": {
19
20
  "dialog-survey": "scripts/cli.mjs"
package/scripts/cli.mjs CHANGED
@@ -15,6 +15,7 @@ import { homedir, tmpdir } from "node:os";
15
15
  import { join, dirname } from "node:path";
16
16
  import { fileURLToPath } from "node:url";
17
17
  import http from "node:http";
18
+ import net from "node:net";
18
19
 
19
20
  // ─── Constants ───────────────────────────────────────────────────────────────
20
21
 
@@ -197,19 +198,35 @@ export function checkNodeVersion(version = process.versions.node) {
197
198
 
198
199
  /**
199
200
  * Check if PostgreSQL is reachable using the given DATABASE_URL.
201
+ * Uses a TCP socket connect instead of pg_isready for cross-platform
202
+ * support (pg_isready is unavailable on Windows by default).
200
203
  * @param {string} databaseUrl
201
- * @returns {{ ok: boolean, message: string }}
204
+ * @param {number} [timeoutMs=3000]
205
+ * @returns {Promise<{ ok: boolean, message: string }>}
202
206
  */
203
- export function checkPostgres(databaseUrl) {
207
+ export async function checkPostgres(databaseUrl, timeoutMs = 3000) {
204
208
  if (!databaseUrl) {
205
209
  return { ok: false, message: "DATABASE_URL not provided" };
206
210
  }
207
211
  try {
208
- // Extract host and port from postgresql:// URL
209
212
  const url = new URL(databaseUrl);
210
213
  const host = url.hostname;
211
214
  const port = url.port || "5432";
212
- exec(`pg_isready -h ${host} -p ${port} -q`);
215
+
216
+ await new Promise((resolve, reject) => {
217
+ const socket = new net.Socket();
218
+ let settled = false;
219
+ const cleanup = () => {
220
+ settled = true;
221
+ socket.destroy();
222
+ };
223
+ socket.setTimeout(timeoutMs);
224
+ socket.on("connect", () => { cleanup(); resolve(); });
225
+ socket.on("error", (err) => { cleanup(); reject(err); });
226
+ socket.on("timeout", () => { cleanup(); reject(new Error("timeout")); });
227
+ socket.connect(Number(port), host);
228
+ });
229
+
213
230
  return { ok: true, message: `PostgreSQL ${host}:${port} ✓` };
214
231
  } catch {
215
232
  return {
@@ -259,7 +276,7 @@ export async function checkPrerequisites(databaseUrl) {
259
276
  messages.push(nodeCheck.message);
260
277
  if (!nodeCheck.ok) allOk = false;
261
278
 
262
- const pgCheck = checkPostgres(databaseUrl);
279
+ const pgCheck = await checkPostgres(databaseUrl);
263
280
  messages.push(pgCheck.message);
264
281
  if (!pgCheck.ok) allOk = false;
265
282
 
@@ -805,11 +822,14 @@ export async function main(argv) {
805
822
  }
806
823
 
807
824
  // Run if invoked directly
825
+ // Use path-based check instead of import.meta.resolve() which may return
826
+ // non-file URLs on Node.js >= 26, causing ERR_INVALID_URL_SCHEME.
808
827
  const isMain =
809
- process.argv[1] &&
810
- (fileURLToPath(import.meta.resolve(__filename)) ===
811
- fileURLToPath(import.meta.resolve(process.argv[1])) ||
812
- process.argv[1].endsWith("cli.mjs"));
828
+ process.argv[1] && (
829
+ process.argv[1].endsWith("cli.mjs") ||
830
+ process.argv[1].endsWith("dialog-survey") ||
831
+ process.argv[1].endsWith(`dialog-survey${process.platform === "win32" ? ".cmd" : ""}`)
832
+ );
813
833
 
814
834
  if (isMain) {
815
835
  main(process.argv.slice(2));
package/scripts/deploy.sh CHANGED
@@ -44,7 +44,7 @@ log_info "✓ Node.js $(node -v)"
44
44
  if ! command -v psql &>/dev/null; then
45
45
  log_warn "psql not found — skipping database check"
46
46
  elif [ -n "${DATABASE_URL:-}" ]; then
47
- if ! pg_isready -d "$DATABASE_URL" 2>/dev/null; then
47
+ if ! psql "$DATABASE_URL" -c "SELECT 1" 2>/dev/null; then
48
48
  log_error "PostgreSQL not reachable at DATABASE_URL"
49
49
  exit 1
50
50
  fi