error-mom 0.3.1 → 0.4.0

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.
Files changed (2) hide show
  1. package/dist/cli.js +19 -20
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -10,7 +10,7 @@ import { Command } from "commander";
10
10
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
11
11
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
12
12
  import { z } from "zod";
13
- var VERSION = "0.3.1";
13
+ var VERSION = "0.4.0";
14
14
  var CONFIG_DIR = join(homedir(), ".error-mom");
15
15
  var CONFIG_FILE = join(CONFIG_DIR, "config.json");
16
16
  var program = new Command().name("error-mom").description("Query and operate a self-hosted Error Mom incident desk").version(VERSION);
@@ -120,7 +120,7 @@ program.command("init").description("Create/select a project, install the SDK, a
120
120
  }
121
121
  const framework = detectFramework(packageJson);
122
122
  if (!options.skipInstall) installSdk(detectPackageManager(process.cwd()));
123
- const setupPath = await writeSetup(framework);
123
+ const setupPath = await writeSetup(framework, config.server, project.ingestKey);
124
124
  await writeFile(
125
125
  join(process.cwd(), ".error-mom.json"),
126
126
  `${JSON.stringify({ server: config.server, projectId: project.id, projectName: project.name, framework: framework.id }, null, 2)}
@@ -134,7 +134,7 @@ program.command("init").description("Create/select a project, install the SDK, a
134
134
  setupFile: setupPath,
135
135
  verified: false,
136
136
  wiring: framework.wiring,
137
- nextAction: `Wire it up: ${framework.wiring} For handlers where a framework catches errors itself (queue/cron jobs, webhooks, MCP tools), wrap each with errorMom.wrap(fn, { culprit: "<name>" }). Then run error-mom doctor --project-key <key>.`
137
+ nextAction: `Wire it up: ${framework.wiring} If the app routes caught errors through a central handler or error-broadcast function, call errorMom.captureError(err) inside it \u2014 that is where framework-caught and LLM errors surface. For handlers where a framework catches errors itself (queue/cron jobs, webhooks, MCP tools), wrap each with errorMom.wrap(fn, { culprit: "<name>" }). The setup file has the write-only project key baked in so production builds report without any CI configuration. Then run error-mom doctor --project-key <key>.`
138
138
  });
139
139
  });
140
140
  program.command("mcp").description("Run Error Mom tools over MCP stdio for coding agents").action(async () => {
@@ -406,47 +406,46 @@ function installSdk(packageManager) {
406
406
  stdio: "inherit"
407
407
  });
408
408
  }
409
- async function writeSetup(framework) {
409
+ async function writeSetup(framework, server, ingestKey) {
410
410
  const sourceDirectory = existsSync(join(process.cwd(), "src")) ? "src" : ".";
411
411
  const relativePath = join(sourceDirectory, "error-mom.ts");
412
- if (framework.id === "next") await writeNextInstrumentation(sourceDirectory);
412
+ if (framework.id === "next") await writeNextInstrumentation(sourceDirectory, server, ingestKey);
413
413
  const environment = framework.envStyle === "next" ? "process.env.NEXT_PUBLIC_" : framework.envStyle === "vite" ? "import.meta.env.VITE_" : "process.env.";
414
414
  const moduleName = framework.envStyle === "node" ? "@kenkaiiii/error-mom/node" : "@kenkaiiii/error-mom";
415
415
  const contents = `${framework.id === "next" ? '"use client";\n\n' : ""}import { initErrorMom } from "${moduleName}";
416
416
 
417
- const server = ${environment}ERROR_MOM_SERVER;
418
- const projectKey = ${environment}ERROR_MOM_PROJECT_KEY;
417
+ // The project key is write-only (submit errors, read nothing), so committing
418
+ // it is safe \u2014 same model as a Sentry DSN. Env vars override when present.
419
+ const server = ${environment}ERROR_MOM_SERVER ?? ${JSON.stringify(server)};
420
+ const projectKey = ${environment}ERROR_MOM_PROJECT_KEY ?? ${JSON.stringify(ingestKey)};
419
421
  const release = ${environment}ERROR_MOM_RELEASE;
420
422
 
421
- export const errorMom =
422
- server && projectKey
423
- ? initErrorMom({
424
- server,
425
- projectKey,
426
- environment: ${environment}ERROR_MOM_ENVIRONMENT ?? "production",
427
- ...(release ? { release } : {}),
428
- })
429
- : undefined;
423
+ export const errorMom = initErrorMom({
424
+ server,
425
+ projectKey,
426
+ environment: ${environment}ERROR_MOM_ENVIRONMENT ?? "production",
427
+ ...(release ? { release } : {}),
428
+ });
430
429
  `;
431
430
  await writeFile(join(process.cwd(), relativePath), contents);
432
431
  return relativePath;
433
432
  }
434
- async function writeNextInstrumentation(sourceDirectory) {
433
+ async function writeNextInstrumentation(sourceDirectory, configuredServer, ingestKey) {
435
434
  const file = join(process.cwd(), sourceDirectory, "instrumentation.ts");
436
435
  if (existsSync(file)) return;
437
436
  const contents = `import type { Instrumentation } from "next";
438
437
 
439
438
  // Reports server-side errors (API routes, SSR, server actions, middleware)
440
439
  // that Next.js catches before they can become uncaught exceptions.
440
+ // The baked-in project key is write-only, so committing it is safe.
441
441
  export const onRequestError: Instrumentation.onRequestError = async (
442
442
  error,
443
443
  request,
444
444
  context,
445
445
  ) => {
446
446
  if (process.env.NEXT_RUNTIME !== "nodejs") return;
447
- const server = process.env.NEXT_PUBLIC_ERROR_MOM_SERVER;
448
- const projectKey = process.env.NEXT_PUBLIC_ERROR_MOM_PROJECT_KEY;
449
- if (!server || !projectKey) return;
447
+ const server = process.env.NEXT_PUBLIC_ERROR_MOM_SERVER ?? ${JSON.stringify(configuredServer)};
448
+ const projectKey = process.env.NEXT_PUBLIC_ERROR_MOM_PROJECT_KEY ?? ${JSON.stringify(ingestKey)};
450
449
  const { initErrorMom } = await import("@kenkaiiii/error-mom/node");
451
450
  initErrorMom({
452
451
  server,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "error-mom",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Agent-first CLI and MCP tools for self-hosted Error Mom",
5
5
  "type": "module",
6
6
  "bin": {