Fix lint warnings and tighten test mocks

This commit is contained in:
Peter Steinberger
2025-11-25 00:10:34 +01:00
parent 73a3463ec8
commit 52e0c8de25
8 changed files with 1081 additions and 56 deletions

48
src/commands/up.ts Normal file
View File

@@ -0,0 +1,48 @@
import type { CliDeps, RuntimeEnv } from "../index.js";
import { waitForever as defaultWaitForever } from "../index.js";
export async function upCommand(
opts: { port: string; path: string; verbose?: boolean; yes?: boolean },
deps: CliDeps,
runtime: RuntimeEnv,
waiter: typeof defaultWaitForever = defaultWaitForever,
) {
const port = Number.parseInt(opts.port, 10);
if (Number.isNaN(port) || port <= 0 || port >= 65536) {
throw new Error("Port must be between 1 and 65535");
}
await deps.ensurePortAvailable(port);
const env = deps.readEnv(runtime);
await deps.ensureBinary("tailscale", undefined, runtime);
await deps.ensureFunnel(port, undefined, runtime);
const host = await deps.getTailnetHostname();
const publicUrl = `https://${host}${opts.path}`;
runtime.log(`🌐 Public webhook URL (via Funnel): ${publicUrl}`);
const server = await deps.startWebhook(
port,
opts.path,
undefined,
Boolean(opts.verbose),
runtime,
);
if (!deps.createClient) {
throw new Error("Twilio client dependency missing");
}
const twilioClient = deps.createClient(env);
const senderSid = await deps.findWhatsappSenderSid(
twilioClient,
env.whatsappFrom,
env.whatsappSenderSid,
runtime,
);
await deps.updateWebhook(twilioClient, senderSid, publicUrl, "POST", runtime);
runtime.log(
"\nSetup complete. Leave this process running to keep the webhook online. Ctrl+C to stop.",
);
return { server, publicUrl, senderSid, waiter };
}