@agenticmail/enterprise 0.5.343 → 0.5.345

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.
@@ -1,9 +1,6 @@
1
1
  import {
2
2
  getSupportedDatabases
3
3
  } from "./chunk-Z3I6GNTS.js";
4
- import {
5
- __require
6
- } from "./chunk-KFQGP6VL.js";
7
4
 
8
5
  // src/setup/index.ts
9
6
  import { execSync as execSync3 } from "child_process";
@@ -262,8 +259,8 @@ async function promptDatabase(inquirer, chalk) {
262
259
  import { execSync, exec as execCb } from "child_process";
263
260
  import { promisify } from "util";
264
261
  import { existsSync, writeFileSync, readFileSync } from "fs";
265
- import { join as join2 } from "path";
266
- import { homedir as homedir2, platform, arch } from "os";
262
+ import { join } from "path";
263
+ import { homedir, platform, arch } from "os";
267
264
  var execP = promisify(execCb);
268
265
  function whichCmd(bin) {
269
266
  const cmd = platform() === "win32" ? `where ${bin}` : `which ${bin}`;
@@ -488,7 +485,7 @@ async function runCloudSetup(inquirer, chalk, existingSubdomain) {
488
485
  console.log(` ${chalk.cyan("npx @agenticmail/enterprise start")}`);
489
486
  console.log("");
490
487
  console.log(chalk.dim(" Or let the setup wizard start them with PM2 (next step).\n"));
491
- const envPath = join2(homedir2(), ".agenticmail", ".env");
488
+ const envPath = join(homedir(), ".agenticmail", ".env");
492
489
  try {
493
490
  let envContent = "";
494
491
  if (existsSync(envPath)) {
@@ -508,7 +505,7 @@ CLOUDFLARED_TOKEN=${tunnelToken}
508
505
  `;
509
506
  }
510
507
  const { mkdirSync } = await import("fs");
511
- mkdirSync(join2(homedir2(), ".agenticmail"), { recursive: true });
508
+ mkdirSync(join(homedir(), ".agenticmail"), { recursive: true });
512
509
  writeFileSync(envPath, envContent, { mode: 384 });
513
510
  } catch {
514
511
  }
@@ -562,8 +559,8 @@ async function runTunnelSetup(inquirer, chalk) {
562
559
  }
563
560
  }
564
561
  console.log(chalk.bold(" 2. Cloudflare Authentication"));
565
- const cfDir = join2(homedir2(), ".cloudflared");
566
- const certPath = join2(cfDir, "cert.pem");
562
+ const cfDir = join(homedir(), ".cloudflared");
563
+ const certPath = join(cfDir, "cert.pem");
567
564
  const loggedIn = existsSync(certPath);
568
565
  if (loggedIn) {
569
566
  console.log(chalk.green(" \u2713 Already authenticated\n"));
@@ -644,14 +641,14 @@ async function runTunnelSetup(inquirer, chalk) {
644
641
  }
645
642
  const config = [
646
643
  `tunnel: ${tunnelId}`,
647
- `credentials-file: ${join2(cfDir, tunnelId + ".json")}`,
644
+ `credentials-file: ${join(cfDir, tunnelId + ".json")}`,
648
645
  "",
649
646
  "ingress:",
650
647
  ` - hostname: ${domain}`,
651
648
  ` service: http://localhost:${port}`,
652
649
  " - service: http_status:404"
653
650
  ].join("\n");
654
- writeFileSync(join2(cfDir, "config.yml"), config);
651
+ writeFileSync(join(cfDir, "config.yml"), config);
655
652
  console.log(chalk.green(` \u2713 Config written: ${domain} \u2192 localhost:${port}`));
656
653
  try {
657
654
  execSync(`cloudflared tunnel route dns ${tunnelId} ${domain} 2>&1`, { encoding: "utf8", timeout: 3e4 });
@@ -716,8 +713,8 @@ async function runTunnelSetup(inquirer, chalk) {
716
713
  console.log(chalk.yellow(" \u26A0 PM2 not available \u2014 tunnel started in background"));
717
714
  console.log(chalk.dim(" Install PM2 for auto-restart: npm install -g pm2"));
718
715
  try {
719
- const { spawn } = await import("child_process");
720
- const child = spawn("cloudflared", ["tunnel", "run"], { detached: true, stdio: "ignore" });
716
+ const { spawn: spawn2 } = await import("child_process");
717
+ const child = spawn2("cloudflared", ["tunnel", "run"], { detached: true, stdio: "ignore" });
721
718
  child.unref();
722
719
  started = true;
723
720
  } catch {
@@ -1048,7 +1045,10 @@ async function promptRegistration(inquirer, chalk, ora, domain, companyName, adm
1048
1045
 
1049
1046
  // src/setup/provision.ts
1050
1047
  import { randomUUID, randomBytes as randomBytes2 } from "crypto";
1051
- import { execSync as execSync2 } from "child_process";
1048
+ import { execSync as execSync2, spawn } from "child_process";
1049
+ import { statSync, readFileSync as readFileSync2 } from "fs";
1050
+ import { join as join2 } from "path";
1051
+ import { homedir as homedir2 } from "os";
1052
1052
  function generateOrgId() {
1053
1053
  const chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
1054
1054
  const bytes = randomBytes2(10);
@@ -1282,27 +1282,81 @@ async function deploy(config, db, jwtSecret, vaultKey, spinner, chalk) {
1282
1282
  execSync2("pm2 delete enterprise 2>&1", { stdio: "pipe", timeout: 1e4 });
1283
1283
  } catch {
1284
1284
  }
1285
- let cfPath = "cloudflared";
1285
+ let cfPath = "";
1286
1286
  try {
1287
1287
  const whichBin = process.platform === "win32" ? "where" : "which";
1288
1288
  cfPath = execSync2(`${whichBin} cloudflared`, { encoding: "utf8", timeout: 5e3 }).trim().split("\n")[0].trim();
1289
1289
  } catch {
1290
1290
  }
1291
- execSync2(`pm2 start "${cfPath}" --name cloudflared --interpreter none -- tunnel --no-autoupdate run --token ${cloud.tunnelToken}`, { stdio: "pipe", timeout: 15e3 });
1292
- const envFile = join(homedir(), ".agenticmail", ".env");
1293
- const entryPoint = join(__require.resolve("@agenticmail/enterprise/package.json"), "..", "bin", "agenticmail-enterprise.cjs");
1294
- let startCmd;
1291
+ if (!cfPath && process.platform === "win32") {
1292
+ const localAppData = process.env.LOCALAPPDATA || `${process.env.USERPROFILE}\\AppData\\Local`;
1293
+ const candidate = `${localAppData}\\cloudflared\\cloudflared.exe`;
1294
+ try {
1295
+ statSync(candidate);
1296
+ cfPath = candidate;
1297
+ } catch {
1298
+ }
1299
+ }
1300
+ if (!cfPath) throw new Error("cloudflared not found \u2014 install it first");
1301
+ const amDir = join2(homedir2(), ".agenticmail");
1302
+ const { writeFileSync: writeFileSync2, mkdirSync } = await import("fs");
1295
1303
  try {
1296
- const { statSync } = __require("fs");
1297
- statSync(entryPoint);
1298
- startCmd = `pm2 start "${process.execPath}" --name enterprise -- "${entryPoint}" start`;
1304
+ mkdirSync(amDir, { recursive: true });
1299
1305
  } catch {
1300
- const npxPath = process.platform === "win32" ? join(process.env.APPDATA || "", "npm", "npx.cmd") : "npx";
1301
- startCmd = `pm2 start "${npxPath}" --name enterprise -- @agenticmail/enterprise start`;
1302
1306
  }
1303
- execSync2(startCmd, {
1307
+ const startScript = join2(amDir, "start.cjs");
1308
+ writeFileSync2(startScript, [
1309
+ `// Auto-generated by AgenticMail setup \u2014 do not edit`,
1310
+ `const { execFileSync } = require('child_process');`,
1311
+ `const { readFileSync } = require('fs');`,
1312
+ `const { join } = require('path');`,
1313
+ `// Load .env`,
1314
+ `try {`,
1315
+ ` const envFile = join(__dirname, '.env');`,
1316
+ ` const lines = readFileSync(envFile, 'utf8').split('\\n');`,
1317
+ ` for (const line of lines) {`,
1318
+ ` const m = line.match(/^([A-Z_]+)=(.*)$/);`,
1319
+ ` if (m) process.env[m[1]] = m[2];`,
1320
+ ` }`,
1321
+ `} catch {}`,
1322
+ `// Run the CLI`,
1323
+ `const { spawnSync } = require('child_process');`,
1324
+ `const r = spawnSync(process.execPath, [require.resolve('@agenticmail/enterprise/dist/cli.js'), 'start'], {`,
1325
+ ` stdio: 'inherit', env: process.env`,
1326
+ `});`,
1327
+ `process.exit(r.status || 0);`
1328
+ ].join("\n"));
1329
+ const cfScript = join2(amDir, "cloudflared.cjs");
1330
+ writeFileSync2(cfScript, [
1331
+ `// Auto-generated by AgenticMail setup \u2014 do not edit`,
1332
+ `const { spawnSync } = require('child_process');`,
1333
+ `const r = spawnSync(${JSON.stringify(cfPath)}, process.argv.slice(2), {`,
1334
+ ` stdio: 'inherit'`,
1335
+ `});`,
1336
+ `process.exit(r.status || 0);`
1337
+ ].join("\n"));
1338
+ execSync2(`pm2 start "${cfScript}" --name cloudflared -- tunnel --no-autoupdate run --token ${cloud.tunnelToken}`, { stdio: "pipe", timeout: 15e3 });
1339
+ const envLines = [
1340
+ `PORT=${cloud.port || 8080}`,
1341
+ `DATABASE_URL=${database.connectionString || ""}`,
1342
+ `JWT_SECRET=${jwtSecret}`,
1343
+ `AGENTICMAIL_VAULT_KEY=${vaultKey}`,
1344
+ `AGENTICMAIL_DOMAIN=${cloud.fqdn}`
1345
+ ];
1346
+ const envFile = join2(amDir, ".env");
1347
+ try {
1348
+ const existing = readFileSync2(envFile, "utf8");
1349
+ for (const line of envLines) {
1350
+ const key = line.split("=")[0];
1351
+ if (!existing.includes(`${key}=`)) {
1352
+ writeFileSync2(envFile, existing.trimEnd() + "\n" + line + "\n");
1353
+ }
1354
+ }
1355
+ } catch {
1356
+ }
1357
+ execSync2(`pm2 start "${startScript}" --name enterprise`, {
1304
1358
  stdio: "pipe",
1305
- timeout: 15e3,
1359
+ timeout: 3e4,
1306
1360
  env: {
1307
1361
  ...process.env,
1308
1362
  PORT: String(cloud.port || 8080),
@@ -1312,21 +1366,12 @@ async function deploy(config, db, jwtSecret, vaultKey, spinner, chalk) {
1312
1366
  AGENTICMAIL_DOMAIN: cloud.fqdn
1313
1367
  }
1314
1368
  });
1315
- await new Promise((r) => setTimeout(r, 3e3));
1316
- try {
1317
- const jlist = execSync2("pm2 jlist", { encoding: "utf8", timeout: 1e4 });
1318
- const procs = JSON.parse(jlist);
1319
- const cfProc = procs.find((p) => p.name === "cloudflared");
1320
- const entProc = procs.find((p) => p.name === "enterprise");
1321
- if (cfProc?.pm2_env?.status !== "online") {
1322
- throw new Error("cloudflared not running");
1323
- }
1324
- if (entProc?.pm2_env?.status !== "online") {
1325
- throw new Error("enterprise server not running");
1326
- }
1327
- } catch (verifyErr) {
1328
- throw new Error(`Processes not healthy: ${verifyErr.message}`);
1329
- }
1369
+ await new Promise((r) => setTimeout(r, 5e3));
1370
+ const jlist = execSync2("pm2 jlist", { encoding: "utf8", timeout: 1e4 });
1371
+ const procs = JSON.parse(jlist);
1372
+ const cfOnline = procs.find((p) => p.name === "cloudflared")?.pm2_env?.status === "online";
1373
+ const entOnline = procs.find((p) => p.name === "enterprise")?.pm2_env?.status === "online";
1374
+ if (!cfOnline || !entOnline) throw new Error(`cloudflared=${cfOnline ? "ok" : "down"}, enterprise=${entOnline ? "ok" : "down"}`);
1330
1375
  try {
1331
1376
  execSync2("pm2 save", { timeout: 1e4, stdio: "pipe" });
1332
1377
  } catch {
@@ -1345,38 +1390,46 @@ async function deploy(config, db, jwtSecret, vaultKey, spinner, chalk) {
1345
1390
  } catch (e) {
1346
1391
  spinner.warn(`PM2 setup failed: ${e.message}`);
1347
1392
  console.log(chalk.dim(" Starting processes directly instead...\n"));
1348
- const { spawn } = __require("child_process");
1349
- let cfPath = "cloudflared";
1393
+ let fallbackCfPath = "";
1350
1394
  try {
1351
1395
  const whichBin = process.platform === "win32" ? "where" : "which";
1352
- cfPath = execSync2(`${whichBin} cloudflared`, { encoding: "utf8", timeout: 5e3 }).trim().split("\n")[0].trim();
1396
+ fallbackCfPath = execSync2(`${whichBin} cloudflared`, { encoding: "utf8", timeout: 5e3 }).trim().split("\n")[0].trim();
1353
1397
  } catch {
1354
1398
  }
1355
- const cfProc = spawn(cfPath, ["tunnel", "--no-autoupdate", "run", "--token", cloud.tunnelToken], {
1399
+ if (!fallbackCfPath && process.platform === "win32") {
1400
+ const localAppData = process.env.LOCALAPPDATA || `${process.env.USERPROFILE}\\AppData\\Local`;
1401
+ const candidate = `${localAppData}\\cloudflared\\cloudflared.exe`;
1402
+ try {
1403
+ statSync(candidate);
1404
+ fallbackCfPath = candidate;
1405
+ } catch {
1406
+ }
1407
+ }
1408
+ const serverEnv = {
1409
+ ...process.env,
1410
+ PORT: String(cloud.port || 8080),
1411
+ DATABASE_URL: database.connectionString || "",
1412
+ JWT_SECRET: jwtSecret,
1413
+ AGENTICMAIL_VAULT_KEY: vaultKey,
1414
+ AGENTICMAIL_DOMAIN: cloud.fqdn
1415
+ };
1416
+ if (fallbackCfPath) {
1417
+ const cfProc = spawn(fallbackCfPath, ["tunnel", "--no-autoupdate", "run", "--token", cloud.tunnelToken], {
1418
+ detached: true,
1419
+ stdio: "ignore",
1420
+ env: process.env
1421
+ });
1422
+ cfProc.unref();
1423
+ }
1424
+ const entProc = spawn("npx", ["@agenticmail/enterprise", "start"], {
1356
1425
  detached: true,
1357
1426
  stdio: "ignore",
1358
- env: process.env
1359
- });
1360
- cfProc.unref();
1361
- const entProc = spawn(process.execPath, [
1362
- "-e",
1363
- `process.env.PORT='${cloud.port || 8080}';process.env.DATABASE_URL='${(database.connectionString || "").replace(/'/g, "\\'")}';process.env.JWT_SECRET='${jwtSecret}';process.env.AGENTICMAIL_VAULT_KEY='${vaultKey}';process.env.AGENTICMAIL_DOMAIN='${cloud.fqdn}';require('@agenticmail/enterprise/dist/cli.js');`,
1364
- "--",
1365
- "start"
1366
- ], {
1367
- detached: true,
1368
- stdio: "ignore",
1369
- env: {
1370
- ...process.env,
1371
- PORT: String(cloud.port || 8080),
1372
- DATABASE_URL: database.connectionString || "",
1373
- JWT_SECRET: jwtSecret,
1374
- AGENTICMAIL_VAULT_KEY: vaultKey,
1375
- AGENTICMAIL_DOMAIN: cloud.fqdn
1376
- }
1427
+ env: serverEnv,
1428
+ shell: true
1429
+ // Required on Windows for npx
1377
1430
  });
1378
1431
  entProc.unref();
1379
- await new Promise((r) => setTimeout(r, 5e3));
1432
+ await new Promise((r) => setTimeout(r, 8e3));
1380
1433
  spinner.succeed(`Live at https://${cloud.fqdn}`);
1381
1434
  console.log(chalk.yellow(" Note: Processes running in background. They will stop when you close this terminal."));
1382
1435
  console.log(chalk.dim(" For persistence, install PM2: npm install -g pm2"));
package/dist/cli.js CHANGED
@@ -64,7 +64,7 @@ Skill Development:
64
64
  break;
65
65
  case "setup":
66
66
  default:
67
- import("./setup-KHWRJILU.js").then((m) => m.runSetupWizard()).catch(fatal);
67
+ import("./setup-PIBCCQVU.js").then((m) => m.runSetupWizard()).catch(fatal);
68
68
  break;
69
69
  }
70
70
  function fatal(err) {
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  import {
14
14
  provision,
15
15
  runSetupWizard
16
- } from "./chunk-FWGDL7KF.js";
16
+ } from "./chunk-WV6DLTYP.js";
17
17
  import {
18
18
  AgentRuntime,
19
19
  EmailChannel,
@@ -0,0 +1,20 @@
1
+ import {
2
+ promptCompanyInfo,
3
+ promptDatabase,
4
+ promptDeployment,
5
+ promptDomain,
6
+ promptRegistration,
7
+ provision,
8
+ runSetupWizard
9
+ } from "./chunk-AA6OVVQD.js";
10
+ import "./chunk-Z3I6GNTS.js";
11
+ import "./chunk-KFQGP6VL.js";
12
+ export {
13
+ promptCompanyInfo,
14
+ promptDatabase,
15
+ promptDeployment,
16
+ promptDomain,
17
+ promptRegistration,
18
+ provision,
19
+ runSetupWizard
20
+ };
@@ -0,0 +1,20 @@
1
+ import {
2
+ promptCompanyInfo,
3
+ promptDatabase,
4
+ promptDeployment,
5
+ promptDomain,
6
+ promptRegistration,
7
+ provision,
8
+ runSetupWizard
9
+ } from "./chunk-WV6DLTYP.js";
10
+ import "./chunk-Z3I6GNTS.js";
11
+ import "./chunk-KFQGP6VL.js";
12
+ export {
13
+ promptCompanyInfo,
14
+ promptDatabase,
15
+ promptDeployment,
16
+ promptDomain,
17
+ promptRegistration,
18
+ provision,
19
+ runSetupWizard
20
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agenticmail/enterprise",
3
- "version": "0.5.343",
3
+ "version": "0.5.345",
4
4
  "description": "AgenticMail Enterprise — cloud-hosted AI agent identity, email, auth & compliance for organizations",
5
5
  "type": "module",
6
6
  "bin": {