@agenticmail/enterprise 0.5.252 → 0.5.253
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/agent-heartbeat-RFXB2ADO.js +510 -0
- package/dist/agent-tools-3YCGMXCE.js +13871 -0
- package/dist/chunk-4IUA4QZE.js +4488 -0
- package/dist/chunk-BIPFPIDH.js +468 -0
- package/dist/chunk-J6QPL5WN.js +1224 -0
- package/dist/chunk-WXXG3LYY.js +3778 -0
- package/dist/cli-agent-3KZRZBZG.js +1768 -0
- package/dist/cli-serve-44IKCXDO.js +114 -0
- package/dist/cli.js +3 -3
- package/dist/index.js +17 -17
- package/dist/routes-GKC2Q6WI.js +13510 -0
- package/dist/runtime-NTCIQSJM.js +45 -0
- package/dist/server-Q4KBC33A.js +15 -0
- package/dist/setup-3XCPXDZE.js +20 -0
- package/dist/task-queue-QNWKF4GG.js +7 -0
- package/package.json +1 -1
- package/src/cli-agent.ts +39 -2
- package/src/runtime/hooks.ts +22 -0
|
@@ -0,0 +1,1224 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSupportedDatabases
|
|
3
|
+
} from "./chunk-ULRBF2T7.js";
|
|
4
|
+
|
|
5
|
+
// src/setup/index.ts
|
|
6
|
+
import { execSync as execSync2 } from "child_process";
|
|
7
|
+
import { createRequire } from "module";
|
|
8
|
+
import { join as join2 } from "path";
|
|
9
|
+
|
|
10
|
+
// src/setup/company.ts
|
|
11
|
+
function toSlug(name) {
|
|
12
|
+
return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 63);
|
|
13
|
+
}
|
|
14
|
+
function generateAlternatives(companyName) {
|
|
15
|
+
const base = toSlug(companyName);
|
|
16
|
+
const words = companyName.trim().split(/\s+/).map((w) => w.toLowerCase().replace(/[^a-z0-9]/g, "")).filter(Boolean);
|
|
17
|
+
const suggestions = /* @__PURE__ */ new Set();
|
|
18
|
+
suggestions.add(base);
|
|
19
|
+
if (words.length >= 2) {
|
|
20
|
+
const initials = words.map((w) => w[0]).join("");
|
|
21
|
+
if (initials.length >= 2) suggestions.add(initials);
|
|
22
|
+
}
|
|
23
|
+
if (words[0] && words[0] !== base) {
|
|
24
|
+
suggestions.add(words[0]);
|
|
25
|
+
}
|
|
26
|
+
if (words.length >= 3) {
|
|
27
|
+
suggestions.add(`${words[0]}-${words[words.length - 1]}`);
|
|
28
|
+
}
|
|
29
|
+
suggestions.add(`team-${base}`);
|
|
30
|
+
suggestions.add(`app-${base}`);
|
|
31
|
+
suggestions.add(`mail-${words[0] || base}`);
|
|
32
|
+
suggestions.add(`ai-${words[0] || base}`);
|
|
33
|
+
suggestions.add(`${words[0] || base}-hq`);
|
|
34
|
+
suggestions.delete(base);
|
|
35
|
+
return [...suggestions].map((s) => s.slice(0, 63)).slice(0, 5);
|
|
36
|
+
}
|
|
37
|
+
function validateSubdomain(v) {
|
|
38
|
+
const s = v.trim();
|
|
39
|
+
if (!s) return "Subdomain is required";
|
|
40
|
+
if (s.length < 2) return "Subdomain must be at least 2 characters";
|
|
41
|
+
if (s.length > 63) return "Subdomain must be 63 characters or fewer";
|
|
42
|
+
if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(s)) {
|
|
43
|
+
return "Subdomain must be lowercase letters, numbers, and hyphens (cannot start or end with a hyphen)";
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
async function promptCompanyInfo(inquirer, chalk) {
|
|
48
|
+
console.log(chalk.bold.cyan(" Step 1 of 5: Company Info"));
|
|
49
|
+
console.log(chalk.dim(" Tell us about your organization.\n"));
|
|
50
|
+
const { companyName, adminEmail, adminPassword } = await inquirer.prompt([
|
|
51
|
+
{
|
|
52
|
+
type: "input",
|
|
53
|
+
name: "companyName",
|
|
54
|
+
message: "Company name:",
|
|
55
|
+
validate: (v) => {
|
|
56
|
+
if (!v.trim()) return "Company name is required";
|
|
57
|
+
if (v.length > 100) return "Company name must be under 100 characters";
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
type: "input",
|
|
63
|
+
name: "adminEmail",
|
|
64
|
+
message: "Admin email:",
|
|
65
|
+
validate: (v) => {
|
|
66
|
+
if (!v.includes("@") || !v.includes(".")) return "Enter a valid email address";
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
type: "password",
|
|
72
|
+
name: "adminPassword",
|
|
73
|
+
message: "Admin password:",
|
|
74
|
+
mask: "*",
|
|
75
|
+
validate: (v) => {
|
|
76
|
+
if (v.length < 8) return "Password must be at least 8 characters";
|
|
77
|
+
if (!/[A-Z]/.test(v) && !/[0-9]/.test(v)) {
|
|
78
|
+
return "Password should contain at least one uppercase letter or number";
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
]);
|
|
84
|
+
const suggested = toSlug(companyName);
|
|
85
|
+
const alternatives = generateAlternatives(companyName);
|
|
86
|
+
console.log("");
|
|
87
|
+
console.log(chalk.bold(" Subdomain"));
|
|
88
|
+
console.log(chalk.dim(" Used for your dashboard URL and internal routing.\n"));
|
|
89
|
+
const choices = [
|
|
90
|
+
{ name: `${suggested} ${chalk.dim("(recommended)")}`, value: suggested },
|
|
91
|
+
...alternatives.map((alt) => ({ name: alt, value: alt })),
|
|
92
|
+
new inquirer.Separator(),
|
|
93
|
+
{ name: `${chalk.italic("Enter my own...")}`, value: "__custom__" },
|
|
94
|
+
{ name: `${chalk.italic("Generate more suggestions")}`, value: "__regenerate__" }
|
|
95
|
+
];
|
|
96
|
+
let subdomain = suggested;
|
|
97
|
+
let choosing = true;
|
|
98
|
+
while (choosing) {
|
|
99
|
+
const { subdomainChoice } = await inquirer.prompt([{
|
|
100
|
+
type: "list",
|
|
101
|
+
name: "subdomainChoice",
|
|
102
|
+
message: "Choose a subdomain:",
|
|
103
|
+
choices
|
|
104
|
+
}]);
|
|
105
|
+
if (subdomainChoice === "__custom__") {
|
|
106
|
+
const { custom } = await inquirer.prompt([{
|
|
107
|
+
type: "input",
|
|
108
|
+
name: "custom",
|
|
109
|
+
message: "Custom subdomain:",
|
|
110
|
+
suffix: chalk.dim(" (lowercase, letters/numbers/hyphens)"),
|
|
111
|
+
validate: validateSubdomain,
|
|
112
|
+
filter: (v) => v.trim().toLowerCase()
|
|
113
|
+
}]);
|
|
114
|
+
subdomain = custom;
|
|
115
|
+
choosing = false;
|
|
116
|
+
} else if (subdomainChoice === "__regenerate__") {
|
|
117
|
+
const base = toSlug(companyName);
|
|
118
|
+
const words = companyName.trim().split(/\s+/).map((w2) => w2.toLowerCase().replace(/[^a-z0-9]/g, "")).filter(Boolean);
|
|
119
|
+
const w = words[0] || base;
|
|
120
|
+
const rand = () => Math.random().toString(36).slice(2, 5);
|
|
121
|
+
const fresh = [
|
|
122
|
+
`${w}-${rand()}`,
|
|
123
|
+
`${base}-${rand()}`,
|
|
124
|
+
`${w}-agents`,
|
|
125
|
+
`${w}-mail`,
|
|
126
|
+
`${w}-platform`
|
|
127
|
+
];
|
|
128
|
+
choices.splice(
|
|
129
|
+
1,
|
|
130
|
+
alternatives.length,
|
|
131
|
+
...fresh.map((alt) => ({ name: alt, value: alt }))
|
|
132
|
+
);
|
|
133
|
+
} else {
|
|
134
|
+
subdomain = subdomainChoice;
|
|
135
|
+
choosing = false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
console.log(chalk.dim(` Your subdomain: ${chalk.white(subdomain)}
|
|
139
|
+
`));
|
|
140
|
+
return { companyName, adminEmail, adminPassword, subdomain };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// src/setup/database.ts
|
|
144
|
+
var CONNECTION_HINTS = {
|
|
145
|
+
postgres: "postgresql://user:pass@host:5432/dbname",
|
|
146
|
+
mysql: "mysql://user:pass@host:3306/dbname",
|
|
147
|
+
mongodb: "mongodb+srv://user:pass@cluster.mongodb.net/dbname",
|
|
148
|
+
supabase: "postgresql://postgres:pass@db.xxxx.supabase.co:5432/postgres",
|
|
149
|
+
neon: "postgresql://user:pass@ep-xxx.us-east-1.aws.neon.tech/dbname?sslmode=require",
|
|
150
|
+
planetscale: 'mysql://user:pass@aws.connect.psdb.cloud/dbname?ssl={"rejectUnauthorized":true}',
|
|
151
|
+
cockroachdb: "postgresql://user:pass@cluster.cockroachlabs.cloud:26257/dbname?sslmode=verify-full"
|
|
152
|
+
};
|
|
153
|
+
async function promptDatabase(inquirer, chalk) {
|
|
154
|
+
console.log("");
|
|
155
|
+
console.log(chalk.bold.cyan(" Step 2 of 4: Database"));
|
|
156
|
+
console.log(chalk.dim(" Where should your data live?\n"));
|
|
157
|
+
const databases = getSupportedDatabases();
|
|
158
|
+
const { dbType } = await inquirer.prompt([
|
|
159
|
+
{
|
|
160
|
+
type: "list",
|
|
161
|
+
name: "dbType",
|
|
162
|
+
message: "Database backend:",
|
|
163
|
+
choices: databases.map((d) => ({
|
|
164
|
+
name: `${d.label} ${chalk.dim(`(${d.group})`)}`,
|
|
165
|
+
value: d.type
|
|
166
|
+
}))
|
|
167
|
+
}
|
|
168
|
+
]);
|
|
169
|
+
if (dbType === "sqlite") {
|
|
170
|
+
const { dbPath } = await inquirer.prompt([{
|
|
171
|
+
type: "input",
|
|
172
|
+
name: "dbPath",
|
|
173
|
+
message: "Database file path:",
|
|
174
|
+
default: "./agenticmail-enterprise.db"
|
|
175
|
+
}]);
|
|
176
|
+
return { type: dbType, connectionString: dbPath };
|
|
177
|
+
}
|
|
178
|
+
if (dbType === "dynamodb") {
|
|
179
|
+
const answers = await inquirer.prompt([
|
|
180
|
+
{
|
|
181
|
+
type: "input",
|
|
182
|
+
name: "region",
|
|
183
|
+
message: "AWS Region:",
|
|
184
|
+
default: "us-east-1"
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
type: "input",
|
|
188
|
+
name: "accessKeyId",
|
|
189
|
+
message: "AWS Access Key ID:",
|
|
190
|
+
validate: (v) => v.length > 0 || "Required"
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
type: "password",
|
|
194
|
+
name: "secretAccessKey",
|
|
195
|
+
message: "AWS Secret Access Key:",
|
|
196
|
+
mask: "*",
|
|
197
|
+
validate: (v) => v.length > 0 || "Required"
|
|
198
|
+
}
|
|
199
|
+
]);
|
|
200
|
+
return { type: dbType, ...answers };
|
|
201
|
+
}
|
|
202
|
+
if (dbType === "turso") {
|
|
203
|
+
const answers = await inquirer.prompt([
|
|
204
|
+
{
|
|
205
|
+
type: "input",
|
|
206
|
+
name: "connectionString",
|
|
207
|
+
message: "Turso database URL:",
|
|
208
|
+
suffix: chalk.dim(" (e.g. libsql://db-org.turso.io)"),
|
|
209
|
+
validate: (v) => v.length > 0 || "Required"
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
type: "password",
|
|
213
|
+
name: "authToken",
|
|
214
|
+
message: "Turso auth token:",
|
|
215
|
+
mask: "*",
|
|
216
|
+
validate: (v) => v.length > 0 || "Required"
|
|
217
|
+
}
|
|
218
|
+
]);
|
|
219
|
+
return { type: dbType, connectionString: answers.connectionString, authToken: answers.authToken };
|
|
220
|
+
}
|
|
221
|
+
const hint = CONNECTION_HINTS[dbType] || "";
|
|
222
|
+
const { connectionString } = await inquirer.prompt([{
|
|
223
|
+
type: "input",
|
|
224
|
+
name: "connectionString",
|
|
225
|
+
message: "Connection string:",
|
|
226
|
+
suffix: hint ? chalk.dim(` (e.g. ${hint})`) : "",
|
|
227
|
+
validate: (v) => v.length > 0 || "Connection string is required"
|
|
228
|
+
}]);
|
|
229
|
+
return { type: dbType, connectionString };
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// src/setup/deployment.ts
|
|
233
|
+
import { execSync, exec as execCb } from "child_process";
|
|
234
|
+
import { promisify } from "util";
|
|
235
|
+
import { existsSync, writeFileSync } from "fs";
|
|
236
|
+
import { join } from "path";
|
|
237
|
+
import { homedir, platform, arch } from "os";
|
|
238
|
+
var execP = promisify(execCb);
|
|
239
|
+
async function promptDeployment(inquirer, chalk) {
|
|
240
|
+
console.log("");
|
|
241
|
+
console.log(chalk.bold.cyan(" Step 3 of 4: Deployment"));
|
|
242
|
+
console.log(chalk.dim(" Where should your dashboard run?\n"));
|
|
243
|
+
const { deployTarget } = await inquirer.prompt([{
|
|
244
|
+
type: "list",
|
|
245
|
+
name: "deployTarget",
|
|
246
|
+
message: "Deploy to:",
|
|
247
|
+
choices: [
|
|
248
|
+
{
|
|
249
|
+
name: `AgenticMail Cloud ${chalk.dim("(managed, instant URL)")}`,
|
|
250
|
+
value: "cloud"
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
name: `Cloudflare Tunnel ${chalk.green("\u2190 recommended")} ${chalk.dim("(self-hosted, free, no ports)")}`,
|
|
254
|
+
value: "cloudflare-tunnel"
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
name: `Fly.io ${chalk.dim("(your account)")}`,
|
|
258
|
+
value: "fly"
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
name: `Railway ${chalk.dim("(your account)")}`,
|
|
262
|
+
value: "railway"
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
name: `Docker ${chalk.dim("(self-hosted)")}`,
|
|
266
|
+
value: "docker"
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
name: `Local ${chalk.dim("(dev/testing, runs here)")}`,
|
|
270
|
+
value: "local"
|
|
271
|
+
}
|
|
272
|
+
]
|
|
273
|
+
}]);
|
|
274
|
+
if (deployTarget === "cloudflare-tunnel") {
|
|
275
|
+
const tunnel = await runTunnelSetup(inquirer, chalk);
|
|
276
|
+
return { target: deployTarget, tunnel };
|
|
277
|
+
}
|
|
278
|
+
return { target: deployTarget };
|
|
279
|
+
}
|
|
280
|
+
async function runTunnelSetup(inquirer, chalk) {
|
|
281
|
+
console.log("");
|
|
282
|
+
console.log(chalk.bold(" Cloudflare Tunnel Setup"));
|
|
283
|
+
console.log(chalk.dim(" Exposes your local server to the internet via Cloudflare."));
|
|
284
|
+
console.log(chalk.dim(" No open ports, free TLS, auto-DNS.\n"));
|
|
285
|
+
console.log(chalk.bold(" 1. Cloudflared CLI"));
|
|
286
|
+
let installed = false;
|
|
287
|
+
let version = "";
|
|
288
|
+
try {
|
|
289
|
+
version = execSync("cloudflared --version 2>&1", { encoding: "utf8", timeout: 5e3 }).trim();
|
|
290
|
+
installed = true;
|
|
291
|
+
} catch {
|
|
292
|
+
}
|
|
293
|
+
if (installed) {
|
|
294
|
+
console.log(chalk.green(` \u2713 Installed (${version})
|
|
295
|
+
`));
|
|
296
|
+
} else {
|
|
297
|
+
console.log(chalk.yellow(" Not installed."));
|
|
298
|
+
const { doInstall } = await inquirer.prompt([{
|
|
299
|
+
type: "confirm",
|
|
300
|
+
name: "doInstall",
|
|
301
|
+
message: "Install cloudflared now?",
|
|
302
|
+
default: true
|
|
303
|
+
}]);
|
|
304
|
+
if (!doInstall) {
|
|
305
|
+
console.log(chalk.red("\n cloudflared is required for tunnel deployment."));
|
|
306
|
+
console.log(chalk.dim(" Install it manually: https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/\n"));
|
|
307
|
+
process.exit(1);
|
|
308
|
+
}
|
|
309
|
+
console.log(chalk.dim(" Installing..."));
|
|
310
|
+
try {
|
|
311
|
+
await installCloudflared();
|
|
312
|
+
version = execSync("cloudflared --version 2>&1", { encoding: "utf8", timeout: 5e3 }).trim();
|
|
313
|
+
console.log(chalk.green(` \u2713 Installed (${version})
|
|
314
|
+
`));
|
|
315
|
+
} catch (err) {
|
|
316
|
+
console.log(chalk.red(` \u2717 Installation failed: ${err.message}`));
|
|
317
|
+
console.log(chalk.dim(" Install manually and re-run setup.\n"));
|
|
318
|
+
process.exit(1);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
console.log(chalk.bold(" 2. Cloudflare Authentication"));
|
|
322
|
+
const cfDir = join(homedir(), ".cloudflared");
|
|
323
|
+
const certPath = join(cfDir, "cert.pem");
|
|
324
|
+
const loggedIn = existsSync(certPath);
|
|
325
|
+
if (loggedIn) {
|
|
326
|
+
console.log(chalk.green(" \u2713 Already authenticated\n"));
|
|
327
|
+
} else {
|
|
328
|
+
console.log(chalk.dim(" This will open your browser to authorize Cloudflare.\n"));
|
|
329
|
+
const { doLogin } = await inquirer.prompt([{
|
|
330
|
+
type: "confirm",
|
|
331
|
+
name: "doLogin",
|
|
332
|
+
message: "Open browser to login to Cloudflare?",
|
|
333
|
+
default: true
|
|
334
|
+
}]);
|
|
335
|
+
if (!doLogin) {
|
|
336
|
+
console.log(chalk.red("\n Cloudflare auth is required. Run `cloudflared tunnel login` manually.\n"));
|
|
337
|
+
process.exit(1);
|
|
338
|
+
}
|
|
339
|
+
console.log(chalk.dim(" Waiting for browser authorization..."));
|
|
340
|
+
try {
|
|
341
|
+
await execP("cloudflared tunnel login", { timeout: 12e4 });
|
|
342
|
+
console.log(chalk.green(" \u2713 Authenticated\n"));
|
|
343
|
+
} catch (err) {
|
|
344
|
+
console.log(chalk.red(` \u2717 Login failed or timed out: ${err.message}`));
|
|
345
|
+
console.log(chalk.dim(" Complete the browser authorization and try again.\n"));
|
|
346
|
+
process.exit(1);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
console.log(chalk.bold(" 3. Tunnel Configuration"));
|
|
350
|
+
const { domain, port, tunnelName } = await inquirer.prompt([
|
|
351
|
+
{
|
|
352
|
+
type: "input",
|
|
353
|
+
name: "domain",
|
|
354
|
+
message: "Domain (e.g. dashboard.yourcompany.com):",
|
|
355
|
+
validate: (v) => v.includes(".") ? true : "Enter a valid domain"
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
type: "number",
|
|
359
|
+
name: "port",
|
|
360
|
+
message: "Local port:",
|
|
361
|
+
default: 3200
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
type: "input",
|
|
365
|
+
name: "tunnelName",
|
|
366
|
+
message: "Tunnel name:",
|
|
367
|
+
default: "agenticmail-enterprise"
|
|
368
|
+
}
|
|
369
|
+
]);
|
|
370
|
+
console.log("");
|
|
371
|
+
console.log(chalk.bold(" 4. Deploying"));
|
|
372
|
+
let tunnelId = "";
|
|
373
|
+
try {
|
|
374
|
+
console.log(chalk.dim(" Creating tunnel..."));
|
|
375
|
+
const out = execSync(`cloudflared tunnel create ${tunnelName} 2>&1`, { encoding: "utf8", timeout: 3e4 });
|
|
376
|
+
const match = out.match(/Created tunnel .+ with id ([a-f0-9-]+)/);
|
|
377
|
+
tunnelId = match?.[1] || "";
|
|
378
|
+
console.log(chalk.green(` \u2713 Tunnel created: ${tunnelName} (${tunnelId})`));
|
|
379
|
+
} catch (e) {
|
|
380
|
+
if (e.message?.includes("already exists") || e.stderr?.includes("already exists")) {
|
|
381
|
+
try {
|
|
382
|
+
const listOut = execSync("cloudflared tunnel list --output json 2>&1", { encoding: "utf8", timeout: 15e3 });
|
|
383
|
+
const tunnels = JSON.parse(listOut);
|
|
384
|
+
const existing = tunnels.find((t) => t.name === tunnelName);
|
|
385
|
+
if (existing) {
|
|
386
|
+
tunnelId = existing.id;
|
|
387
|
+
console.log(chalk.green(` \u2713 Using existing tunnel: ${tunnelName} (${tunnelId})`));
|
|
388
|
+
}
|
|
389
|
+
} catch {
|
|
390
|
+
console.log(chalk.red(` \u2717 Tunnel "${tunnelName}" exists but couldn't read its ID`));
|
|
391
|
+
process.exit(1);
|
|
392
|
+
}
|
|
393
|
+
} else {
|
|
394
|
+
console.log(chalk.red(` \u2717 Failed to create tunnel: ${e.message}`));
|
|
395
|
+
process.exit(1);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (!tunnelId) {
|
|
399
|
+
console.log(chalk.red(" \u2717 Could not determine tunnel ID"));
|
|
400
|
+
process.exit(1);
|
|
401
|
+
}
|
|
402
|
+
const config = [
|
|
403
|
+
`tunnel: ${tunnelId}`,
|
|
404
|
+
`credentials-file: ${join(cfDir, tunnelId + ".json")}`,
|
|
405
|
+
"",
|
|
406
|
+
"ingress:",
|
|
407
|
+
` - hostname: ${domain}`,
|
|
408
|
+
` service: http://localhost:${port}`,
|
|
409
|
+
" - service: http_status:404"
|
|
410
|
+
].join("\n");
|
|
411
|
+
writeFileSync(join(cfDir, "config.yml"), config);
|
|
412
|
+
console.log(chalk.green(` \u2713 Config written: ${domain} \u2192 localhost:${port}`));
|
|
413
|
+
try {
|
|
414
|
+
execSync(`cloudflared tunnel route dns ${tunnelId} ${domain} 2>&1`, { encoding: "utf8", timeout: 3e4 });
|
|
415
|
+
console.log(chalk.green(` \u2713 DNS CNAME created: ${domain}`));
|
|
416
|
+
} catch (e) {
|
|
417
|
+
if (e.message?.includes("already exists") || e.stderr?.includes("already exists")) {
|
|
418
|
+
console.log(chalk.green(` \u2713 DNS CNAME already exists for ${domain}`));
|
|
419
|
+
} else {
|
|
420
|
+
console.log(chalk.yellow(` \u26A0 DNS routing failed \u2014 add CNAME manually: ${domain} \u2192 ${tunnelId}.cfargotunnel.com`));
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
let started = false;
|
|
424
|
+
try {
|
|
425
|
+
execSync("which pm2", { timeout: 3e3 });
|
|
426
|
+
try {
|
|
427
|
+
execSync("pm2 delete cloudflared 2>/dev/null", { timeout: 5e3 });
|
|
428
|
+
} catch {
|
|
429
|
+
}
|
|
430
|
+
execSync(`pm2 start cloudflared --name cloudflared -- tunnel run`, { encoding: "utf8", timeout: 15e3 });
|
|
431
|
+
try {
|
|
432
|
+
execSync("pm2 save 2>/dev/null", { timeout: 5e3 });
|
|
433
|
+
} catch {
|
|
434
|
+
}
|
|
435
|
+
console.log(chalk.green(" \u2713 Tunnel running via PM2 (auto-restarts on crash)"));
|
|
436
|
+
started = true;
|
|
437
|
+
} catch {
|
|
438
|
+
}
|
|
439
|
+
if (!started) {
|
|
440
|
+
try {
|
|
441
|
+
console.log(chalk.dim(" Installing PM2 for process management..."));
|
|
442
|
+
execSync("npm install -g pm2", { timeout: 6e4, stdio: "pipe" });
|
|
443
|
+
try {
|
|
444
|
+
execSync("pm2 delete cloudflared 2>/dev/null", { timeout: 5e3 });
|
|
445
|
+
} catch {
|
|
446
|
+
}
|
|
447
|
+
execSync(`pm2 start cloudflared --name cloudflared -- tunnel run`, { encoding: "utf8", timeout: 15e3 });
|
|
448
|
+
try {
|
|
449
|
+
execSync("pm2 save 2>/dev/null", { timeout: 5e3 });
|
|
450
|
+
} catch {
|
|
451
|
+
}
|
|
452
|
+
console.log(chalk.green(" \u2713 PM2 installed + tunnel running (auto-restarts on crash)"));
|
|
453
|
+
started = true;
|
|
454
|
+
} catch {
|
|
455
|
+
console.log(chalk.yellow(" \u26A0 PM2 not available \u2014 tunnel started in background"));
|
|
456
|
+
console.log(chalk.dim(" Install PM2 for auto-restart: npm install -g pm2"));
|
|
457
|
+
try {
|
|
458
|
+
const { spawn } = await import("child_process");
|
|
459
|
+
const child = spawn("cloudflared", ["tunnel", "run"], { detached: true, stdio: "ignore" });
|
|
460
|
+
child.unref();
|
|
461
|
+
started = true;
|
|
462
|
+
} catch {
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
console.log("");
|
|
467
|
+
console.log(chalk.green.bold(` \u2713 Tunnel deployed! Your dashboard will be at https://${domain}`));
|
|
468
|
+
console.log("");
|
|
469
|
+
return { tunnelId, domain, port, tunnelName };
|
|
470
|
+
}
|
|
471
|
+
async function installCloudflared() {
|
|
472
|
+
const plat = platform();
|
|
473
|
+
const a = arch();
|
|
474
|
+
if (plat === "darwin") {
|
|
475
|
+
try {
|
|
476
|
+
execSync("which brew", { timeout: 3e3 });
|
|
477
|
+
execSync("brew install cloudflared 2>&1", { encoding: "utf8", timeout: 12e4 });
|
|
478
|
+
return;
|
|
479
|
+
} catch {
|
|
480
|
+
}
|
|
481
|
+
const cfArch = a === "arm64" ? "arm64" : "amd64";
|
|
482
|
+
execSync(
|
|
483
|
+
`curl -L -o /usr/local/bin/cloudflared https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-darwin-${cfArch} && chmod +x /usr/local/bin/cloudflared`,
|
|
484
|
+
{ timeout: 6e4 }
|
|
485
|
+
);
|
|
486
|
+
} else if (plat === "linux") {
|
|
487
|
+
const cfArch = a === "arm64" ? "arm64" : "amd64";
|
|
488
|
+
execSync(
|
|
489
|
+
`curl -L -o /usr/local/bin/cloudflared https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-${cfArch} && chmod +x /usr/local/bin/cloudflared`,
|
|
490
|
+
{ timeout: 6e4 }
|
|
491
|
+
);
|
|
492
|
+
} else {
|
|
493
|
+
throw new Error("Unsupported platform: " + plat);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// src/setup/domain.ts
|
|
498
|
+
async function promptDomain(inquirer, chalk, deployTarget) {
|
|
499
|
+
if (deployTarget === "local") {
|
|
500
|
+
return {};
|
|
501
|
+
}
|
|
502
|
+
console.log("");
|
|
503
|
+
console.log(chalk.bold.cyan(" Step 4 of 5: Custom Domain"));
|
|
504
|
+
console.log(chalk.dim(" Configure how your team will access the dashboard.\n"));
|
|
505
|
+
const targetHints = {
|
|
506
|
+
cloud: "By default, your dashboard is at <subdomain>.agenticmail.io. Add a custom domain for a branded URL.",
|
|
507
|
+
docker: "Configure your reverse proxy (nginx, Caddy, etc.) to route your domain to the Docker container.",
|
|
508
|
+
fly: "After deploying, run `fly certs add <domain>` to provision TLS for your domain.",
|
|
509
|
+
railway: "Add your domain in Railway project settings after deploying."
|
|
510
|
+
};
|
|
511
|
+
if (targetHints[deployTarget]) {
|
|
512
|
+
console.log(chalk.dim(` ${targetHints[deployTarget]}`));
|
|
513
|
+
console.log("");
|
|
514
|
+
}
|
|
515
|
+
const { domainMode } = await inquirer.prompt([{
|
|
516
|
+
type: "list",
|
|
517
|
+
name: "domainMode",
|
|
518
|
+
message: "Domain setup:",
|
|
519
|
+
choices: [
|
|
520
|
+
{
|
|
521
|
+
name: `Use default subdomain only ${chalk.dim("(<subdomain>.agenticmail.io)")}`,
|
|
522
|
+
value: "subdomain_only"
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
name: `Add a custom subdomain ${chalk.dim("(e.g. agents.yourcompany.com)")}`,
|
|
526
|
+
value: "custom_subdomain"
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
name: `Deploy on my root domain ${chalk.dim("(e.g. yourcompany.com \u2014 no subdomain)")}`,
|
|
530
|
+
value: "root_domain"
|
|
531
|
+
}
|
|
532
|
+
]
|
|
533
|
+
}]);
|
|
534
|
+
if (domainMode === "subdomain_only") {
|
|
535
|
+
return {};
|
|
536
|
+
}
|
|
537
|
+
const isRoot = domainMode === "root_domain";
|
|
538
|
+
const { domain } = await inquirer.prompt([{
|
|
539
|
+
type: "input",
|
|
540
|
+
name: "domain",
|
|
541
|
+
message: isRoot ? "Your domain:" : "Custom domain:",
|
|
542
|
+
suffix: isRoot ? chalk.dim(" (e.g. yourcompany.com)") : chalk.dim(" (e.g. agents.yourcompany.com)"),
|
|
543
|
+
validate: (v) => {
|
|
544
|
+
const d = v.trim().toLowerCase();
|
|
545
|
+
if (!d.includes(".")) return "Enter a valid domain (e.g. yourcompany.com)";
|
|
546
|
+
if (d.startsWith("http")) return "Enter just the domain, not a URL";
|
|
547
|
+
if (d.endsWith(".")) return "Do not include a trailing dot";
|
|
548
|
+
return true;
|
|
549
|
+
},
|
|
550
|
+
filter: (v) => v.trim().toLowerCase()
|
|
551
|
+
}]);
|
|
552
|
+
if (isRoot) {
|
|
553
|
+
console.log("");
|
|
554
|
+
console.log(chalk.bold(" Root Domain Deployment"));
|
|
555
|
+
console.log(chalk.dim(` Your dashboard will be accessible at: ${chalk.white("https://" + domain)}`));
|
|
556
|
+
console.log(chalk.dim(" This means the entire domain is dedicated to your AgenticMail deployment."));
|
|
557
|
+
console.log("");
|
|
558
|
+
}
|
|
559
|
+
console.log("");
|
|
560
|
+
console.log(chalk.dim(" After setup, you will need DNS records for this domain:"));
|
|
561
|
+
console.log("");
|
|
562
|
+
if (isRoot) {
|
|
563
|
+
console.log(chalk.dim(` 1. ${chalk.white("A record")} \u2014 point ${domain} to your server IP`));
|
|
564
|
+
console.log(chalk.dim(` (or CNAME if your provider allows it at the apex)`));
|
|
565
|
+
} else {
|
|
566
|
+
console.log(chalk.dim(` 1. ${chalk.white("CNAME or A record")} \u2014 routes traffic to your server`));
|
|
567
|
+
}
|
|
568
|
+
console.log(chalk.dim(` 2. ${chalk.white("TXT record")} \u2014 proves domain ownership (next step)`));
|
|
569
|
+
console.log("");
|
|
570
|
+
return {
|
|
571
|
+
customDomain: domain,
|
|
572
|
+
useRootDomain: isRoot || void 0
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// src/setup/registration.ts
|
|
577
|
+
import { randomBytes } from "crypto";
|
|
578
|
+
var REGISTRY_BASE_URL = process.env.AGENTICMAIL_REGISTRY_URL || "https://agenticmail.io/enterprise/v1";
|
|
579
|
+
async function promptRegistration(inquirer, chalk, ora, domain, companyName, adminEmail) {
|
|
580
|
+
if (!domain) {
|
|
581
|
+
return { registered: false, verificationStatus: "skipped" };
|
|
582
|
+
}
|
|
583
|
+
console.log("");
|
|
584
|
+
console.log(chalk.bold.cyan(" Step 5 of 5: Domain Registration"));
|
|
585
|
+
console.log(chalk.dim(" Protect your deployment from unauthorized duplication.\n"));
|
|
586
|
+
const { wantsRegistration } = await inquirer.prompt([{
|
|
587
|
+
type: "confirm",
|
|
588
|
+
name: "wantsRegistration",
|
|
589
|
+
message: `Register ${chalk.bold(domain)} with AgenticMail?`,
|
|
590
|
+
default: true
|
|
591
|
+
}]);
|
|
592
|
+
if (!wantsRegistration) {
|
|
593
|
+
console.log(chalk.dim(" Skipped. You can register later from the dashboard.\n"));
|
|
594
|
+
return { registered: false, verificationStatus: "skipped" };
|
|
595
|
+
}
|
|
596
|
+
const spinner = ora("Generating deployment key...").start();
|
|
597
|
+
const { createHash } = await import("crypto");
|
|
598
|
+
const plaintextKey = randomBytes(32).toString("hex");
|
|
599
|
+
const keyHash = createHash("sha256").update(plaintextKey).digest("hex");
|
|
600
|
+
spinner.succeed("Deployment key generated");
|
|
601
|
+
spinner.start("Registering domain with AgenticMail registry...");
|
|
602
|
+
const registryUrl = REGISTRY_BASE_URL.replace(/\/$/, "");
|
|
603
|
+
let registrationId;
|
|
604
|
+
let dnsChallenge;
|
|
605
|
+
try {
|
|
606
|
+
const res = await fetch(`${registryUrl}/domains/register`, {
|
|
607
|
+
method: "POST",
|
|
608
|
+
headers: { "Content-Type": "application/json" },
|
|
609
|
+
body: JSON.stringify({
|
|
610
|
+
domain: domain.toLowerCase().trim(),
|
|
611
|
+
keyHash,
|
|
612
|
+
sha256Hash: keyHash,
|
|
613
|
+
orgName: companyName,
|
|
614
|
+
contactEmail: adminEmail
|
|
615
|
+
}),
|
|
616
|
+
signal: AbortSignal.timeout(15e3)
|
|
617
|
+
});
|
|
618
|
+
const data = await res.json().catch(() => ({}));
|
|
619
|
+
if (res.status === 409) {
|
|
620
|
+
spinner.info("Domain already registered \u2014 verifying ownership");
|
|
621
|
+
console.log("");
|
|
622
|
+
console.log(chalk.yellow(" This domain is already registered and verified."));
|
|
623
|
+
console.log(chalk.dim(" Enter your deployment key to prove ownership and continue.\n"));
|
|
624
|
+
const { deploymentKey } = await inquirer.prompt([{
|
|
625
|
+
type: "password",
|
|
626
|
+
name: "deploymentKey",
|
|
627
|
+
message: "Deployment key:",
|
|
628
|
+
mask: "*",
|
|
629
|
+
validate: (v) => v.length === 64 || "Deployment key should be 64 hex characters"
|
|
630
|
+
}]);
|
|
631
|
+
const recoverSpinner = ora("Verifying deployment key...").start();
|
|
632
|
+
try {
|
|
633
|
+
const recoverRes = await fetch(`${registryUrl}/domains/recover`, {
|
|
634
|
+
method: "POST",
|
|
635
|
+
headers: { "Content-Type": "application/json" },
|
|
636
|
+
body: JSON.stringify({
|
|
637
|
+
domain: domain.toLowerCase().trim(),
|
|
638
|
+
deploymentKey
|
|
639
|
+
}),
|
|
640
|
+
signal: AbortSignal.timeout(15e3)
|
|
641
|
+
});
|
|
642
|
+
const recoverData = await recoverRes.json().catch(() => ({}));
|
|
643
|
+
if (recoverRes.status === 403) {
|
|
644
|
+
recoverSpinner.fail("Invalid deployment key");
|
|
645
|
+
console.log("");
|
|
646
|
+
console.log(chalk.red(" The deployment key does not match this domain."));
|
|
647
|
+
console.log("");
|
|
648
|
+
const { continueAnyway } = await inquirer.prompt([{
|
|
649
|
+
type: "confirm",
|
|
650
|
+
name: "continueAnyway",
|
|
651
|
+
message: "Continue setup without registration?",
|
|
652
|
+
default: true
|
|
653
|
+
}]);
|
|
654
|
+
if (continueAnyway) {
|
|
655
|
+
return { registered: false, verificationStatus: "skipped" };
|
|
656
|
+
}
|
|
657
|
+
process.exit(1);
|
|
658
|
+
}
|
|
659
|
+
if (!recoverRes.ok) {
|
|
660
|
+
throw new Error(recoverData.error || `HTTP ${recoverRes.status}`);
|
|
661
|
+
}
|
|
662
|
+
recoverSpinner.succeed("Ownership verified \u2014 domain recovered");
|
|
663
|
+
registrationId = recoverData.registrationId;
|
|
664
|
+
dnsChallenge = recoverData.dnsChallenge;
|
|
665
|
+
const verifyRes = await fetch(`${registryUrl}/domains/verify`, {
|
|
666
|
+
method: "POST",
|
|
667
|
+
headers: { "Content-Type": "application/json" },
|
|
668
|
+
body: JSON.stringify({ domain: domain.toLowerCase().trim() }),
|
|
669
|
+
signal: AbortSignal.timeout(15e3)
|
|
670
|
+
});
|
|
671
|
+
const verifyData = await verifyRes.json().catch(() => ({}));
|
|
672
|
+
const { createHash: createHash2 } = await import("crypto");
|
|
673
|
+
const localKeyHash = createHash2("sha256").update(deploymentKey).digest("hex");
|
|
674
|
+
return {
|
|
675
|
+
registered: true,
|
|
676
|
+
deploymentKeyHash: localKeyHash,
|
|
677
|
+
dnsChallenge,
|
|
678
|
+
registrationId,
|
|
679
|
+
verificationStatus: verifyData?.verified ? "verified" : "pending_dns"
|
|
680
|
+
};
|
|
681
|
+
} catch (err) {
|
|
682
|
+
recoverSpinner.fail(`Recovery failed: ${err.message}`);
|
|
683
|
+
const { continueAnyway } = await inquirer.prompt([{
|
|
684
|
+
type: "confirm",
|
|
685
|
+
name: "continueAnyway",
|
|
686
|
+
message: "Continue setup without registration?",
|
|
687
|
+
default: true
|
|
688
|
+
}]);
|
|
689
|
+
if (continueAnyway) {
|
|
690
|
+
return { registered: false, verificationStatus: "skipped" };
|
|
691
|
+
}
|
|
692
|
+
process.exit(1);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
if (!res.ok) {
|
|
696
|
+
throw new Error(data.error || `HTTP ${res.status}`);
|
|
697
|
+
}
|
|
698
|
+
registrationId = data.registrationId;
|
|
699
|
+
dnsChallenge = data.dnsChallenge;
|
|
700
|
+
spinner.succeed("Domain registered");
|
|
701
|
+
} catch (err) {
|
|
702
|
+
spinner.warn("Registry unavailable");
|
|
703
|
+
console.log("");
|
|
704
|
+
console.log(chalk.yellow(` Could not reach registry: ${err.message}`));
|
|
705
|
+
console.log(chalk.dim(" You can register later with: npx @agenticmail/enterprise verify-domain"));
|
|
706
|
+
console.log("");
|
|
707
|
+
const { continueAnyway } = await inquirer.prompt([{
|
|
708
|
+
type: "confirm",
|
|
709
|
+
name: "continueAnyway",
|
|
710
|
+
message: "Continue setup without registration?",
|
|
711
|
+
default: true
|
|
712
|
+
}]);
|
|
713
|
+
if (continueAnyway) {
|
|
714
|
+
return { registered: false, verificationStatus: "skipped" };
|
|
715
|
+
}
|
|
716
|
+
process.exit(1);
|
|
717
|
+
}
|
|
718
|
+
console.log("");
|
|
719
|
+
console.log(chalk.red.bold(" \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557"));
|
|
720
|
+
console.log(chalk.red.bold(" \u2551") + chalk.white.bold(" DEPLOYMENT KEY \u2014 SAVE THIS NOW ") + chalk.red.bold("\u2551"));
|
|
721
|
+
console.log(chalk.red.bold(" \u2551") + " " + chalk.red.bold("\u2551"));
|
|
722
|
+
console.log(chalk.red.bold(" \u2551") + ` ${chalk.green.bold(plaintextKey)} ` + chalk.red.bold("\u2551"));
|
|
723
|
+
console.log(chalk.red.bold(" \u2551") + " " + chalk.red.bold("\u2551"));
|
|
724
|
+
console.log(chalk.red.bold(" \u2551") + chalk.dim(" This key is shown ONCE. Store it securely (password manager, ") + chalk.red.bold("\u2551"));
|
|
725
|
+
console.log(chalk.red.bold(" \u2551") + chalk.dim(" vault, printed backup). You need it to recover this domain. ") + chalk.red.bold("\u2551"));
|
|
726
|
+
console.log(chalk.red.bold(" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"));
|
|
727
|
+
console.log("");
|
|
728
|
+
console.log(chalk.bold(" Add this DNS TXT record to prove domain ownership:"));
|
|
729
|
+
console.log("");
|
|
730
|
+
console.log(` ${chalk.bold("Host:")} ${chalk.cyan(`_agenticmail-verify.${domain}`)}`);
|
|
731
|
+
console.log(` ${chalk.bold("Type:")} ${chalk.cyan("TXT")}`);
|
|
732
|
+
console.log(` ${chalk.bold("Value:")} ${chalk.cyan(dnsChallenge)}`);
|
|
733
|
+
console.log("");
|
|
734
|
+
console.log(chalk.dim(" DNS changes can take up to 48 hours to propagate."));
|
|
735
|
+
console.log("");
|
|
736
|
+
await inquirer.prompt([{
|
|
737
|
+
type: "confirm",
|
|
738
|
+
name: "keySaved",
|
|
739
|
+
message: "I have saved my deployment key",
|
|
740
|
+
default: false
|
|
741
|
+
}]);
|
|
742
|
+
const { checkNow } = await inquirer.prompt([{
|
|
743
|
+
type: "confirm",
|
|
744
|
+
name: "checkNow",
|
|
745
|
+
message: "Check DNS verification now?",
|
|
746
|
+
default: false
|
|
747
|
+
}]);
|
|
748
|
+
let verificationStatus = "pending_dns";
|
|
749
|
+
if (checkNow) {
|
|
750
|
+
for (let attempt = 1; attempt <= 5; attempt++) {
|
|
751
|
+
spinner.start(`Checking DNS (attempt ${attempt}/5)...`);
|
|
752
|
+
try {
|
|
753
|
+
const res = await fetch(`${registryUrl}/domains/verify`, {
|
|
754
|
+
method: "POST",
|
|
755
|
+
headers: { "Content-Type": "application/json" },
|
|
756
|
+
body: JSON.stringify({ domain: domain.toLowerCase().trim() }),
|
|
757
|
+
signal: AbortSignal.timeout(15e3)
|
|
758
|
+
});
|
|
759
|
+
const data = await res.json().catch(() => ({}));
|
|
760
|
+
if (data.verified) {
|
|
761
|
+
spinner.succeed("Domain verified!");
|
|
762
|
+
verificationStatus = "verified";
|
|
763
|
+
break;
|
|
764
|
+
}
|
|
765
|
+
} catch {
|
|
766
|
+
}
|
|
767
|
+
if (attempt < 5) {
|
|
768
|
+
spinner.text = `DNS record not found yet. Retrying in 10s (attempt ${attempt}/5)...`;
|
|
769
|
+
await new Promise((r) => setTimeout(r, 1e4));
|
|
770
|
+
} else {
|
|
771
|
+
spinner.info("DNS record not found yet");
|
|
772
|
+
console.log(chalk.dim(" Run later: npx @agenticmail/enterprise verify-domain"));
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
} else {
|
|
776
|
+
console.log(chalk.dim(" Run when ready: npx @agenticmail/enterprise verify-domain"));
|
|
777
|
+
}
|
|
778
|
+
console.log("");
|
|
779
|
+
return {
|
|
780
|
+
registered: true,
|
|
781
|
+
deploymentKeyHash: keyHash,
|
|
782
|
+
dnsChallenge,
|
|
783
|
+
registrationId,
|
|
784
|
+
verificationStatus
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
// src/setup/provision.ts
|
|
789
|
+
import { randomUUID, randomBytes as randomBytes2 } from "crypto";
|
|
790
|
+
function generateOrgId() {
|
|
791
|
+
const chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
792
|
+
const bytes = randomBytes2(10);
|
|
793
|
+
let id = "";
|
|
794
|
+
for (let i = 0; i < 10; i++) id += chars[bytes[i] % chars.length];
|
|
795
|
+
return id;
|
|
796
|
+
}
|
|
797
|
+
async function provision(config, ora, chalk) {
|
|
798
|
+
const spinner = ora("Connecting to database...").start();
|
|
799
|
+
const jwtSecret = randomUUID() + randomUUID();
|
|
800
|
+
const vaultKey = randomUUID() + randomUUID();
|
|
801
|
+
try {
|
|
802
|
+
const { createAdapter } = await import("./factory-672W7A5B.js");
|
|
803
|
+
const db = await createAdapter({
|
|
804
|
+
type: config.database.type,
|
|
805
|
+
connectionString: config.database.connectionString,
|
|
806
|
+
region: config.database.region,
|
|
807
|
+
accessKeyId: config.database.accessKeyId,
|
|
808
|
+
secretAccessKey: config.database.secretAccessKey,
|
|
809
|
+
authToken: config.database.authToken
|
|
810
|
+
});
|
|
811
|
+
spinner.text = "Running migrations...";
|
|
812
|
+
await db.migrate();
|
|
813
|
+
spinner.succeed("Database ready");
|
|
814
|
+
const engineDbInterface = db.getEngineDB();
|
|
815
|
+
if (engineDbInterface) {
|
|
816
|
+
spinner.start("Initializing engine...");
|
|
817
|
+
const { EngineDatabase } = await import("./db-adapter-FBLIO7QY.js");
|
|
818
|
+
const dialectMap = {
|
|
819
|
+
sqlite: "sqlite",
|
|
820
|
+
postgres: "postgres",
|
|
821
|
+
supabase: "postgres",
|
|
822
|
+
neon: "postgres",
|
|
823
|
+
cockroachdb: "postgres",
|
|
824
|
+
mysql: "mysql",
|
|
825
|
+
planetscale: "mysql",
|
|
826
|
+
turso: "turso"
|
|
827
|
+
};
|
|
828
|
+
const engineDialect = dialectMap[db.getDialect()] || db.getDialect();
|
|
829
|
+
const engineDb = new EngineDatabase(engineDbInterface, engineDialect);
|
|
830
|
+
const migResult = await engineDb.migrate();
|
|
831
|
+
spinner.succeed(`Engine ready (${migResult.applied} migrations applied)`);
|
|
832
|
+
}
|
|
833
|
+
spinner.start("Creating company...");
|
|
834
|
+
const orgId = generateOrgId();
|
|
835
|
+
const corsOrigins = [];
|
|
836
|
+
if (config.domain.customDomain) {
|
|
837
|
+
corsOrigins.push(`https://${config.domain.customDomain}`);
|
|
838
|
+
}
|
|
839
|
+
if (config.company.subdomain) {
|
|
840
|
+
corsOrigins.push(`https://${config.company.subdomain}.agenticmail.io`);
|
|
841
|
+
}
|
|
842
|
+
if (config.deployTarget === "local") {
|
|
843
|
+
corsOrigins.push("http://localhost:3000", "http://localhost:8080", "http://127.0.0.1:3000", "http://127.0.0.1:8080");
|
|
844
|
+
}
|
|
845
|
+
await db.updateSettings({
|
|
846
|
+
name: config.company.companyName,
|
|
847
|
+
subdomain: config.company.subdomain,
|
|
848
|
+
domain: config.domain.customDomain,
|
|
849
|
+
orgId,
|
|
850
|
+
...corsOrigins.length > 0 ? {
|
|
851
|
+
firewallConfig: {
|
|
852
|
+
network: { corsOrigins }
|
|
853
|
+
}
|
|
854
|
+
} : {}
|
|
855
|
+
});
|
|
856
|
+
spinner.succeed(`Company created (org: ${orgId})`);
|
|
857
|
+
if (config.registration?.registered) {
|
|
858
|
+
spinner.start("Saving domain registration...");
|
|
859
|
+
await db.updateSettings({
|
|
860
|
+
deploymentKeyHash: config.registration.deploymentKeyHash,
|
|
861
|
+
domainRegistrationId: config.registration.registrationId,
|
|
862
|
+
domainDnsChallenge: config.registration.dnsChallenge,
|
|
863
|
+
domainRegisteredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
864
|
+
domainStatus: config.registration.verificationStatus === "verified" ? "verified" : "pending_dns",
|
|
865
|
+
...config.registration.verificationStatus === "verified" ? { domainVerifiedAt: (/* @__PURE__ */ new Date()).toISOString() } : {}
|
|
866
|
+
});
|
|
867
|
+
spinner.succeed("Domain registration saved");
|
|
868
|
+
}
|
|
869
|
+
spinner.start("Creating admin account...");
|
|
870
|
+
let admin;
|
|
871
|
+
try {
|
|
872
|
+
admin = await db.createUser({
|
|
873
|
+
email: config.company.adminEmail,
|
|
874
|
+
name: "Admin",
|
|
875
|
+
role: "owner",
|
|
876
|
+
password: config.company.adminPassword
|
|
877
|
+
});
|
|
878
|
+
} catch (err) {
|
|
879
|
+
if (err.message?.includes("duplicate key") || err.message?.includes("UNIQUE constraint") || err.code === "23505") {
|
|
880
|
+
admin = await db.getUserByEmail(config.company.adminEmail);
|
|
881
|
+
if (!admin) throw err;
|
|
882
|
+
spinner.text = "Admin account already exists, reusing...";
|
|
883
|
+
} else {
|
|
884
|
+
throw err;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
await db.logEvent({
|
|
888
|
+
actor: admin.id,
|
|
889
|
+
actorType: "system",
|
|
890
|
+
action: "setup.complete",
|
|
891
|
+
resource: `company:${config.company.subdomain}`,
|
|
892
|
+
details: {
|
|
893
|
+
dbType: config.database.type,
|
|
894
|
+
deployTarget: config.deployTarget,
|
|
895
|
+
companyName: config.company.companyName
|
|
896
|
+
}
|
|
897
|
+
});
|
|
898
|
+
spinner.succeed("Admin account created");
|
|
899
|
+
try {
|
|
900
|
+
const { writeFileSync: writeFileSync2, existsSync: existsSync2, mkdirSync } = await import("fs");
|
|
901
|
+
const { join: join3 } = await import("path");
|
|
902
|
+
const { homedir: homedir2 } = await import("os");
|
|
903
|
+
const envDir = join3(homedir2(), ".agenticmail");
|
|
904
|
+
if (!existsSync2(envDir)) mkdirSync(envDir, { recursive: true });
|
|
905
|
+
const port = config.tunnel?.port || (config.deployTarget === "local" ? 3e3 : void 0) || (config.deployTarget === "docker" ? 3e3 : void 0) || 3200;
|
|
906
|
+
const envContent = [
|
|
907
|
+
"# AgenticMail Enterprise \u2014 auto-generated by setup wizard",
|
|
908
|
+
`DATABASE_URL=${config.database.connectionString || ""}`,
|
|
909
|
+
`JWT_SECRET=${jwtSecret}`,
|
|
910
|
+
`AGENTICMAIL_VAULT_KEY=${vaultKey}`,
|
|
911
|
+
`PORT=${port}`
|
|
912
|
+
].join("\n") + "\n";
|
|
913
|
+
writeFileSync2(join3(envDir, ".env"), envContent, { mode: 384 });
|
|
914
|
+
spinner.succeed(`Config saved to ~/.agenticmail/.env`);
|
|
915
|
+
} catch {
|
|
916
|
+
}
|
|
917
|
+
const result = await deploy(config, db, jwtSecret, vaultKey, spinner, chalk);
|
|
918
|
+
return {
|
|
919
|
+
success: true,
|
|
920
|
+
url: result.url,
|
|
921
|
+
jwtSecret,
|
|
922
|
+
db,
|
|
923
|
+
serverClose: result.close
|
|
924
|
+
};
|
|
925
|
+
} catch (err) {
|
|
926
|
+
spinner.fail(`Setup failed: ${err.message}`);
|
|
927
|
+
return {
|
|
928
|
+
success: false,
|
|
929
|
+
error: err.message,
|
|
930
|
+
jwtSecret,
|
|
931
|
+
db: null
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
async function deploy(config, db, jwtSecret, vaultKey, spinner, chalk) {
|
|
936
|
+
const { deployTarget, company, database, domain, tunnel } = config;
|
|
937
|
+
if (deployTarget === "cloudflare-tunnel" && tunnel) {
|
|
938
|
+
spinner.start(`Starting local server on port ${tunnel.port}...`);
|
|
939
|
+
const { createServer: createServer2 } = await import("./server-Q4KBC33A.js");
|
|
940
|
+
const server2 = createServer2({ port: tunnel.port, db, jwtSecret });
|
|
941
|
+
const handle2 = await server2.start();
|
|
942
|
+
spinner.succeed("Server running");
|
|
943
|
+
console.log("");
|
|
944
|
+
console.log(chalk.green.bold(" AgenticMail Enterprise is live!"));
|
|
945
|
+
console.log("");
|
|
946
|
+
console.log(` ${chalk.bold("Public URL:")} ${chalk.cyan("https://" + tunnel.domain)}`);
|
|
947
|
+
console.log(` ${chalk.bold("Local:")} ${chalk.cyan("http://localhost:" + tunnel.port)}`);
|
|
948
|
+
console.log(` ${chalk.bold("Tunnel:")} ${tunnel.tunnelName} (${tunnel.tunnelId})`);
|
|
949
|
+
console.log(` ${chalk.bold("Admin:")} ${company.adminEmail}`);
|
|
950
|
+
console.log("");
|
|
951
|
+
console.log(chalk.dim(" Tunnel is managed by PM2 \u2014 auto-restarts on crash."));
|
|
952
|
+
console.log(chalk.dim(" Manage: pm2 status | pm2 logs cloudflared | pm2 restart cloudflared"));
|
|
953
|
+
console.log(chalk.dim(" Press Ctrl+C to stop the server"));
|
|
954
|
+
return { url: "https://" + tunnel.domain, close: handle2.close };
|
|
955
|
+
}
|
|
956
|
+
if (deployTarget === "cloud") {
|
|
957
|
+
spinner.start("Deploying to AgenticMail Cloud...");
|
|
958
|
+
const { deployToCloud } = await import("./managed-AP6ZSDYJ.js");
|
|
959
|
+
const result = await deployToCloud({
|
|
960
|
+
subdomain: company.subdomain,
|
|
961
|
+
plan: "free",
|
|
962
|
+
dbType: database.type,
|
|
963
|
+
dbConnectionString: database.connectionString || "",
|
|
964
|
+
jwtSecret
|
|
965
|
+
});
|
|
966
|
+
spinner.succeed(`Deployed to ${result.url}`);
|
|
967
|
+
printCloudSuccess(chalk, result.url, company.adminEmail, domain.customDomain, company.subdomain);
|
|
968
|
+
return { url: result.url };
|
|
969
|
+
}
|
|
970
|
+
if (deployTarget === "docker") {
|
|
971
|
+
const { generateDockerCompose, generateEnvFile } = await import("./managed-AP6ZSDYJ.js");
|
|
972
|
+
const compose = generateDockerCompose({ port: 3e3 });
|
|
973
|
+
const envFile = generateEnvFile({
|
|
974
|
+
dbType: database.type,
|
|
975
|
+
dbConnectionString: database.connectionString || "",
|
|
976
|
+
jwtSecret,
|
|
977
|
+
vaultKey
|
|
978
|
+
});
|
|
979
|
+
const { writeFileSync: writeFileSync2, existsSync: existsSync2, appendFileSync } = await import("fs");
|
|
980
|
+
writeFileSync2("docker-compose.yml", compose);
|
|
981
|
+
writeFileSync2(".env", envFile);
|
|
982
|
+
if (existsSync2(".gitignore")) {
|
|
983
|
+
const content = await import("fs").then((f) => f.readFileSync(".gitignore", "utf-8"));
|
|
984
|
+
if (!content.includes(".env")) {
|
|
985
|
+
appendFileSync(".gitignore", "\n# Secrets\n.env\n");
|
|
986
|
+
}
|
|
987
|
+
} else {
|
|
988
|
+
writeFileSync2(".gitignore", "# Secrets\n.env\nnode_modules/\n");
|
|
989
|
+
}
|
|
990
|
+
spinner.succeed("docker-compose.yml + .env generated");
|
|
991
|
+
console.log("");
|
|
992
|
+
console.log(chalk.green.bold(" Docker deployment ready!"));
|
|
993
|
+
console.log("");
|
|
994
|
+
console.log(` Run: ${chalk.cyan("docker compose up -d")}`);
|
|
995
|
+
console.log(` Dashboard: ${chalk.cyan("http://localhost:3000")}`);
|
|
996
|
+
console.log(chalk.dim(" Secrets stored in .env \u2014 do not commit to git"));
|
|
997
|
+
if (domain.customDomain) {
|
|
998
|
+
printCustomDomainInstructions(chalk, domain.customDomain, "docker");
|
|
999
|
+
}
|
|
1000
|
+
return { url: "http://localhost:3000" };
|
|
1001
|
+
}
|
|
1002
|
+
if (deployTarget === "fly") {
|
|
1003
|
+
const { generateFlyToml } = await import("./managed-AP6ZSDYJ.js");
|
|
1004
|
+
const flyToml = generateFlyToml(`am-${company.subdomain}`, "iad");
|
|
1005
|
+
const { writeFileSync: writeFileSync2 } = await import("fs");
|
|
1006
|
+
writeFileSync2("fly.toml", flyToml);
|
|
1007
|
+
spinner.succeed("fly.toml generated");
|
|
1008
|
+
console.log("");
|
|
1009
|
+
console.log(chalk.green.bold(" Fly.io deployment ready!"));
|
|
1010
|
+
console.log("");
|
|
1011
|
+
console.log(` 1. ${chalk.cyan("fly launch --copy-config")}`);
|
|
1012
|
+
console.log(` 2. ${chalk.cyan(`fly secrets set DATABASE_URL="${database.connectionString}" JWT_SECRET="${jwtSecret}" AGENTICMAIL_VAULT_KEY="${vaultKey}"`)}`);
|
|
1013
|
+
console.log(` 3. ${chalk.cyan("fly deploy")}`);
|
|
1014
|
+
if (domain.customDomain) {
|
|
1015
|
+
console.log(` 4. ${chalk.cyan(`fly certs add ${domain.customDomain}`)}`);
|
|
1016
|
+
printCustomDomainInstructions(chalk, domain.customDomain, "fly", `am-${company.subdomain}.fly.dev`);
|
|
1017
|
+
}
|
|
1018
|
+
return {};
|
|
1019
|
+
}
|
|
1020
|
+
if (deployTarget === "railway") {
|
|
1021
|
+
const { generateRailwayConfig } = await import("./managed-AP6ZSDYJ.js");
|
|
1022
|
+
const railwayConfig = generateRailwayConfig();
|
|
1023
|
+
const { writeFileSync: writeFileSync2 } = await import("fs");
|
|
1024
|
+
writeFileSync2("railway.toml", railwayConfig);
|
|
1025
|
+
spinner.succeed("railway.toml generated");
|
|
1026
|
+
console.log("");
|
|
1027
|
+
console.log(chalk.green.bold(" Railway deployment ready!"));
|
|
1028
|
+
console.log("");
|
|
1029
|
+
console.log(` 1. ${chalk.cyan("railway init")}`);
|
|
1030
|
+
console.log(` 2. ${chalk.cyan("railway link")}`);
|
|
1031
|
+
console.log(` 3. ${chalk.cyan("railway up")}`);
|
|
1032
|
+
if (domain.customDomain) {
|
|
1033
|
+
printCustomDomainInstructions(chalk, domain.customDomain, "railway");
|
|
1034
|
+
}
|
|
1035
|
+
return {};
|
|
1036
|
+
}
|
|
1037
|
+
spinner.start("Starting local server...");
|
|
1038
|
+
const { createServer } = await import("./server-Q4KBC33A.js");
|
|
1039
|
+
const server = createServer({ port: 3e3, db, jwtSecret });
|
|
1040
|
+
const handle = await server.start();
|
|
1041
|
+
spinner.succeed("Server running");
|
|
1042
|
+
console.log("");
|
|
1043
|
+
console.log(chalk.green.bold(" AgenticMail Enterprise is running!"));
|
|
1044
|
+
console.log("");
|
|
1045
|
+
console.log(` ${chalk.bold("Dashboard:")} ${chalk.cyan("http://localhost:3000")}`);
|
|
1046
|
+
console.log(` ${chalk.bold("API:")} ${chalk.cyan("http://localhost:3000/api")}`);
|
|
1047
|
+
console.log(` ${chalk.bold("Admin:")} ${company.adminEmail}`);
|
|
1048
|
+
console.log("");
|
|
1049
|
+
console.log(chalk.dim(" Press Ctrl+C to stop"));
|
|
1050
|
+
return { url: "http://localhost:3000", close: handle.close };
|
|
1051
|
+
}
|
|
1052
|
+
function printCloudSuccess(chalk, url, adminEmail, customDomain, subdomain) {
|
|
1053
|
+
console.log("");
|
|
1054
|
+
console.log(chalk.green.bold(" Your dashboard is live!"));
|
|
1055
|
+
console.log("");
|
|
1056
|
+
console.log(` ${chalk.bold("URL:")} ${chalk.cyan(url)}`);
|
|
1057
|
+
console.log(` ${chalk.bold("Admin:")} ${adminEmail}`);
|
|
1058
|
+
console.log(` ${chalk.bold("Password:")} (the one you just set)`);
|
|
1059
|
+
if (customDomain) {
|
|
1060
|
+
printCustomDomainInstructions(chalk, customDomain, "cloud", `${subdomain}.agenticmail.io`);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
function printCustomDomainInstructions(chalk, domain, target, cnameTarget) {
|
|
1064
|
+
console.log("");
|
|
1065
|
+
console.log(chalk.bold(" Custom Domain DNS Setup"));
|
|
1066
|
+
console.log(chalk.dim(` Route ${chalk.white(domain)} to your deployment.
|
|
1067
|
+
`));
|
|
1068
|
+
if (target === "cloud" && cnameTarget) {
|
|
1069
|
+
console.log(chalk.bold(" Add this DNS record at your domain registrar:"));
|
|
1070
|
+
console.log("");
|
|
1071
|
+
console.log(` ${chalk.bold("Type:")} ${chalk.cyan("CNAME")}`);
|
|
1072
|
+
console.log(` ${chalk.bold("Host:")} ${chalk.cyan(domain)}`);
|
|
1073
|
+
console.log(` ${chalk.bold("Value:")} ${chalk.cyan(cnameTarget)}`);
|
|
1074
|
+
} else if (target === "fly" && cnameTarget) {
|
|
1075
|
+
console.log(chalk.bold(" Add this DNS record at your domain registrar:"));
|
|
1076
|
+
console.log("");
|
|
1077
|
+
console.log(` ${chalk.bold("Type:")} ${chalk.cyan("CNAME")}`);
|
|
1078
|
+
console.log(` ${chalk.bold("Host:")} ${chalk.cyan(domain)}`);
|
|
1079
|
+
console.log(` ${chalk.bold("Value:")} ${chalk.cyan(cnameTarget)}`);
|
|
1080
|
+
console.log("");
|
|
1081
|
+
console.log(chalk.dim(" Fly.io will automatically provision a TLS certificate."));
|
|
1082
|
+
} else if (target === "railway") {
|
|
1083
|
+
console.log(chalk.bold(" After deploying:"));
|
|
1084
|
+
console.log("");
|
|
1085
|
+
console.log(` 1. Open your Railway project dashboard`);
|
|
1086
|
+
console.log(` 2. Go to ${chalk.bold("Settings")} \u2192 ${chalk.bold("Domains")}`);
|
|
1087
|
+
console.log(` 3. Add ${chalk.cyan(domain)} as a custom domain`);
|
|
1088
|
+
console.log(` 4. Railway will show you a ${chalk.bold("CNAME")} target \u2014 add it at your DNS provider`);
|
|
1089
|
+
} else if (target === "docker") {
|
|
1090
|
+
console.log(chalk.bold(" Configure your reverse proxy to route traffic:"));
|
|
1091
|
+
console.log("");
|
|
1092
|
+
console.log(` ${chalk.bold("Domain:")} ${chalk.cyan(domain)}`);
|
|
1093
|
+
console.log(` ${chalk.bold("Target:")} ${chalk.cyan("localhost:3000")} ${chalk.dim("(or your Docker host IP)")}`);
|
|
1094
|
+
console.log("");
|
|
1095
|
+
console.log(chalk.dim(" Example with nginx:"));
|
|
1096
|
+
console.log(chalk.dim(""));
|
|
1097
|
+
console.log(chalk.dim(" server {"));
|
|
1098
|
+
console.log(chalk.dim(` server_name ${domain};`));
|
|
1099
|
+
console.log(chalk.dim(" location / {"));
|
|
1100
|
+
console.log(chalk.dim(" proxy_pass http://localhost:3000;"));
|
|
1101
|
+
console.log(chalk.dim(" proxy_set_header Host $host;"));
|
|
1102
|
+
console.log(chalk.dim(" proxy_set_header X-Real-IP $remote_addr;"));
|
|
1103
|
+
console.log(chalk.dim(" }"));
|
|
1104
|
+
console.log(chalk.dim(" }"));
|
|
1105
|
+
console.log("");
|
|
1106
|
+
console.log(chalk.dim(" Then add a DNS A record pointing to your server IP,"));
|
|
1107
|
+
console.log(chalk.dim(" or a CNAME if you have an existing hostname."));
|
|
1108
|
+
}
|
|
1109
|
+
console.log("");
|
|
1110
|
+
console.log(chalk.dim(" Note: This CNAME/A record routes traffic. A separate TXT record"));
|
|
1111
|
+
console.log(chalk.dim(" for domain verification was (or will be) configured in Step 5."));
|
|
1112
|
+
console.log("");
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
// src/setup/index.ts
|
|
1116
|
+
var DB_DRIVER_MAP = {
|
|
1117
|
+
postgres: ["pg"],
|
|
1118
|
+
supabase: ["pg"],
|
|
1119
|
+
neon: ["pg"],
|
|
1120
|
+
cockroachdb: ["pg"],
|
|
1121
|
+
mysql: ["mysql2"],
|
|
1122
|
+
planetscale: ["mysql2"],
|
|
1123
|
+
mongodb: ["mongodb"],
|
|
1124
|
+
sqlite: ["better-sqlite3"],
|
|
1125
|
+
turso: ["@libsql/client"],
|
|
1126
|
+
dynamodb: ["@aws-sdk/client-dynamodb", "@aws-sdk/lib-dynamodb"]
|
|
1127
|
+
};
|
|
1128
|
+
async function ensureDbDriver(dbType, ora, chalk) {
|
|
1129
|
+
const packages = DB_DRIVER_MAP[dbType];
|
|
1130
|
+
if (!packages?.length) return;
|
|
1131
|
+
const missing = [];
|
|
1132
|
+
for (const pkg of packages) {
|
|
1133
|
+
let found = false;
|
|
1134
|
+
try {
|
|
1135
|
+
await import(pkg);
|
|
1136
|
+
found = true;
|
|
1137
|
+
} catch {
|
|
1138
|
+
}
|
|
1139
|
+
if (!found) {
|
|
1140
|
+
try {
|
|
1141
|
+
const req = createRequire(join2(process.cwd(), "index.js"));
|
|
1142
|
+
req.resolve(pkg);
|
|
1143
|
+
found = true;
|
|
1144
|
+
} catch {
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
if (!found) {
|
|
1148
|
+
try {
|
|
1149
|
+
const globalPrefix = execSync2("npm prefix -g", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }).trim();
|
|
1150
|
+
const req = createRequire(join2(globalPrefix, "lib", "node_modules", ".package-lock.json"));
|
|
1151
|
+
req.resolve(pkg);
|
|
1152
|
+
found = true;
|
|
1153
|
+
} catch {
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
if (!found) missing.push(pkg);
|
|
1157
|
+
}
|
|
1158
|
+
if (!missing.length) return;
|
|
1159
|
+
const spinner = ora(`Installing database driver: ${missing.join(", ")}...`).start();
|
|
1160
|
+
try {
|
|
1161
|
+
execSync2(`npm install --no-save ${missing.join(" ")}`, {
|
|
1162
|
+
stdio: "pipe",
|
|
1163
|
+
timeout: 12e4,
|
|
1164
|
+
cwd: process.cwd()
|
|
1165
|
+
});
|
|
1166
|
+
spinner.succeed(`Database driver installed: ${missing.join(", ")}`);
|
|
1167
|
+
} catch (err) {
|
|
1168
|
+
spinner.fail(`Failed to install ${missing.join(", ")}`);
|
|
1169
|
+
console.error(chalk.red(`
|
|
1170
|
+
Run manually: npm install ${missing.join(" ")}
|
|
1171
|
+
`));
|
|
1172
|
+
process.exit(1);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
async function runSetupWizard() {
|
|
1176
|
+
const { default: inquirer } = await import("inquirer");
|
|
1177
|
+
const { default: ora } = await import("ora");
|
|
1178
|
+
const { default: chalk } = await import("chalk");
|
|
1179
|
+
console.log("");
|
|
1180
|
+
console.log(chalk.bold(" AgenticMail Enterprise"));
|
|
1181
|
+
console.log(chalk.dim(" AI Agent Identity & Email for Organizations"));
|
|
1182
|
+
console.log("");
|
|
1183
|
+
console.log(chalk.dim(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
|
|
1184
|
+
console.log("");
|
|
1185
|
+
const company = await promptCompanyInfo(inquirer, chalk);
|
|
1186
|
+
const database = await promptDatabase(inquirer, chalk);
|
|
1187
|
+
const deploymentResult = await promptDeployment(inquirer, chalk);
|
|
1188
|
+
const deployTarget = deploymentResult.target;
|
|
1189
|
+
const domain = deploymentResult.tunnel ? { customDomain: deploymentResult.tunnel.domain } : await promptDomain(inquirer, chalk, deployTarget);
|
|
1190
|
+
const registration = deploymentResult.tunnel ? { registered: true, verificationStatus: "verified" } : await promptRegistration(
|
|
1191
|
+
inquirer,
|
|
1192
|
+
chalk,
|
|
1193
|
+
ora,
|
|
1194
|
+
domain.customDomain,
|
|
1195
|
+
company.companyName,
|
|
1196
|
+
company.adminEmail
|
|
1197
|
+
);
|
|
1198
|
+
await ensureDbDriver(database.type, ora, chalk);
|
|
1199
|
+
console.log("");
|
|
1200
|
+
console.log(chalk.dim(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
|
|
1201
|
+
console.log("");
|
|
1202
|
+
const result = await provision(
|
|
1203
|
+
{ company, database, deployTarget, domain, registration, tunnel: deploymentResult.tunnel },
|
|
1204
|
+
ora,
|
|
1205
|
+
chalk
|
|
1206
|
+
);
|
|
1207
|
+
if (!result.success) {
|
|
1208
|
+
console.error("");
|
|
1209
|
+
console.error(chalk.red(` Setup failed: ${result.error}`));
|
|
1210
|
+
console.error(chalk.dim(" Check your database connection and try again."));
|
|
1211
|
+
process.exit(1);
|
|
1212
|
+
}
|
|
1213
|
+
console.log("");
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
export {
|
|
1217
|
+
promptCompanyInfo,
|
|
1218
|
+
promptDatabase,
|
|
1219
|
+
promptDeployment,
|
|
1220
|
+
promptDomain,
|
|
1221
|
+
promptRegistration,
|
|
1222
|
+
provision,
|
|
1223
|
+
runSetupWizard
|
|
1224
|
+
};
|