@agenticmail/enterprise 0.5.344 → 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.
- package/dist/{chunk-AA6OVVQD.js → chunk-WV6DLTYP.js} +70 -41
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/dist/setup-PIBCCQVU.js +20 -0
- package/package.json +1 -1
|
@@ -1046,8 +1046,9 @@ async function promptRegistration(inquirer, chalk, ora, domain, companyName, adm
|
|
|
1046
1046
|
// src/setup/provision.ts
|
|
1047
1047
|
import { randomUUID, randomBytes as randomBytes2 } from "crypto";
|
|
1048
1048
|
import { execSync as execSync2, spawn } from "child_process";
|
|
1049
|
-
import { statSync } from "fs";
|
|
1049
|
+
import { statSync, readFileSync as readFileSync2 } from "fs";
|
|
1050
1050
|
import { join as join2 } from "path";
|
|
1051
|
+
import { homedir as homedir2 } from "os";
|
|
1051
1052
|
function generateOrgId() {
|
|
1052
1053
|
const chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
1053
1054
|
const bytes = randomBytes2(10);
|
|
@@ -1160,8 +1161,8 @@ async function provision(config, ora, chalk) {
|
|
|
1160
1161
|
try {
|
|
1161
1162
|
const { writeFileSync: writeFileSync2, existsSync: existsSync2, mkdirSync } = await import("fs");
|
|
1162
1163
|
const { join: join4 } = await import("path");
|
|
1163
|
-
const { homedir:
|
|
1164
|
-
const envDir = join4(
|
|
1164
|
+
const { homedir: homedir3 } = await import("os");
|
|
1165
|
+
const envDir = join4(homedir3(), ".agenticmail");
|
|
1165
1166
|
if (!existsSync2(envDir)) mkdirSync(envDir, { recursive: true });
|
|
1166
1167
|
const port = config.tunnel?.port || (config.deployTarget === "local" ? 3e3 : void 0) || (config.deployTarget === "docker" ? 3e3 : void 0) || 3200;
|
|
1167
1168
|
let existingEnv = "";
|
|
@@ -1297,24 +1298,65 @@ async function deploy(config, db, jwtSecret, vaultKey, spinner, chalk) {
|
|
|
1297
1298
|
}
|
|
1298
1299
|
}
|
|
1299
1300
|
if (!cfPath) throw new Error("cloudflared not found \u2014 install it first");
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1301
|
+
const amDir = join2(homedir2(), ".agenticmail");
|
|
1302
|
+
const { writeFileSync: writeFileSync2, mkdirSync } = await import("fs");
|
|
1303
|
+
try {
|
|
1304
|
+
mkdirSync(amDir, { recursive: true });
|
|
1305
|
+
} catch {
|
|
1306
|
+
}
|
|
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");
|
|
1312
1353
|
}
|
|
1313
1354
|
}
|
|
1355
|
+
} catch {
|
|
1314
1356
|
}
|
|
1315
|
-
execSync2(`pm2 start "${
|
|
1357
|
+
execSync2(`pm2 start "${startScript}" --name enterprise`, {
|
|
1316
1358
|
stdio: "pipe",
|
|
1317
|
-
timeout:
|
|
1359
|
+
timeout: 3e4,
|
|
1318
1360
|
env: {
|
|
1319
1361
|
...process.env,
|
|
1320
1362
|
PORT: String(cloud.port || 8080),
|
|
@@ -1324,7 +1366,7 @@ async function deploy(config, db, jwtSecret, vaultKey, spinner, chalk) {
|
|
|
1324
1366
|
AGENTICMAIL_DOMAIN: cloud.fqdn
|
|
1325
1367
|
}
|
|
1326
1368
|
});
|
|
1327
|
-
await new Promise((r) => setTimeout(r,
|
|
1369
|
+
await new Promise((r) => setTimeout(r, 5e3));
|
|
1328
1370
|
const jlist = execSync2("pm2 jlist", { encoding: "utf8", timeout: 1e4 });
|
|
1329
1371
|
const procs = JSON.parse(jlist);
|
|
1330
1372
|
const cfOnline = procs.find((p) => p.name === "cloudflared")?.pm2_env?.status === "online";
|
|
@@ -1348,18 +1390,18 @@ async function deploy(config, db, jwtSecret, vaultKey, spinner, chalk) {
|
|
|
1348
1390
|
} catch (e) {
|
|
1349
1391
|
spinner.warn(`PM2 setup failed: ${e.message}`);
|
|
1350
1392
|
console.log(chalk.dim(" Starting processes directly instead...\n"));
|
|
1351
|
-
let
|
|
1393
|
+
let fallbackCfPath = "";
|
|
1352
1394
|
try {
|
|
1353
1395
|
const whichBin = process.platform === "win32" ? "where" : "which";
|
|
1354
|
-
|
|
1396
|
+
fallbackCfPath = execSync2(`${whichBin} cloudflared`, { encoding: "utf8", timeout: 5e3 }).trim().split("\n")[0].trim();
|
|
1355
1397
|
} catch {
|
|
1356
1398
|
}
|
|
1357
|
-
if (!
|
|
1399
|
+
if (!fallbackCfPath && process.platform === "win32") {
|
|
1358
1400
|
const localAppData = process.env.LOCALAPPDATA || `${process.env.USERPROFILE}\\AppData\\Local`;
|
|
1359
1401
|
const candidate = `${localAppData}\\cloudflared\\cloudflared.exe`;
|
|
1360
1402
|
try {
|
|
1361
1403
|
statSync(candidate);
|
|
1362
|
-
|
|
1404
|
+
fallbackCfPath = candidate;
|
|
1363
1405
|
} catch {
|
|
1364
1406
|
}
|
|
1365
1407
|
}
|
|
@@ -1371,36 +1413,23 @@ async function deploy(config, db, jwtSecret, vaultKey, spinner, chalk) {
|
|
|
1371
1413
|
AGENTICMAIL_VAULT_KEY: vaultKey,
|
|
1372
1414
|
AGENTICMAIL_DOMAIN: cloud.fqdn
|
|
1373
1415
|
};
|
|
1374
|
-
if (
|
|
1375
|
-
const cfProc = spawn(
|
|
1416
|
+
if (fallbackCfPath) {
|
|
1417
|
+
const cfProc = spawn(fallbackCfPath, ["tunnel", "--no-autoupdate", "run", "--token", cloud.tunnelToken], {
|
|
1376
1418
|
detached: true,
|
|
1377
1419
|
stdio: "ignore",
|
|
1378
1420
|
env: process.env
|
|
1379
1421
|
});
|
|
1380
1422
|
cfProc.unref();
|
|
1381
1423
|
}
|
|
1382
|
-
|
|
1383
|
-
if (process.platform === "win32") {
|
|
1384
|
-
for (const candidate of [
|
|
1385
|
-
join2(process.env.APPDATA || "", "npm", "npx.cmd"),
|
|
1386
|
-
join2(process.env.ProgramFiles || "", "nodejs", "npx.cmd")
|
|
1387
|
-
]) {
|
|
1388
|
-
try {
|
|
1389
|
-
statSync(candidate);
|
|
1390
|
-
npxCmd = candidate;
|
|
1391
|
-
break;
|
|
1392
|
-
} catch {
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
}
|
|
1396
|
-
const entProc = spawn(npxCmd, ["@agenticmail/enterprise", "start"], {
|
|
1424
|
+
const entProc = spawn("npx", ["@agenticmail/enterprise", "start"], {
|
|
1397
1425
|
detached: true,
|
|
1398
1426
|
stdio: "ignore",
|
|
1399
1427
|
env: serverEnv,
|
|
1400
|
-
shell:
|
|
1428
|
+
shell: true
|
|
1429
|
+
// Required on Windows for npx
|
|
1401
1430
|
});
|
|
1402
1431
|
entProc.unref();
|
|
1403
|
-
await new Promise((r) => setTimeout(r,
|
|
1432
|
+
await new Promise((r) => setTimeout(r, 8e3));
|
|
1404
1433
|
spinner.succeed(`Live at https://${cloud.fqdn}`);
|
|
1405
1434
|
console.log(chalk.yellow(" Note: Processes running in background. They will stop when you close this terminal."));
|
|
1406
1435
|
console.log(chalk.dim(" For persistence, install PM2: npm install -g pm2"));
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -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
|
+
};
|