snapfail 0.0.20 → 0.0.21

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/index.js CHANGED
@@ -95,7 +95,9 @@ import { readFileSync, writeFileSync, existsSync } from "fs";
95
95
  import { resolve } from "path";
96
96
  var DEFAULT_ENDPOINT = "https://app.snapfail.com";
97
97
  var ENV_FILE = ".env";
98
- function loadConfig(cwd = process.cwd()) {
98
+ function loadConfig(cwd = process.cwd(), pk) {
99
+ if (pk)
100
+ return { projectKey: pk, endpoint: DEFAULT_ENDPOINT };
99
101
  const fromEnv = process.env["SNAPFAIL_PROJECT_KEY"];
100
102
  if (fromEnv)
101
103
  return { projectKey: fromEnv, endpoint: DEFAULT_ENDPOINT };
@@ -127,6 +129,37 @@ ${line}
127
129
  }
128
130
  }
129
131
 
132
+ // src/session.ts
133
+ import { readFileSync as readFileSync2, writeFileSync as writeFileSync2, mkdirSync, existsSync as existsSync2, rmSync } from "fs";
134
+ import { join } from "path";
135
+ import { homedir } from "os";
136
+ var SESSION_DIR = join(homedir(), ".snapfail");
137
+ var SESSION_FILE = join(SESSION_DIR, "auth.json");
138
+ function readSession() {
139
+ try {
140
+ if (!existsSync2(SESSION_FILE))
141
+ return null;
142
+ const raw = JSON.parse(readFileSync2(SESSION_FILE, "utf-8"));
143
+ if (!raw.token || !raw.endpoint)
144
+ return null;
145
+ return raw;
146
+ } catch {
147
+ return null;
148
+ }
149
+ }
150
+ function writeSession(session) {
151
+ mkdirSync(SESSION_DIR, { recursive: true });
152
+ writeFileSync2(SESSION_FILE, JSON.stringify(session, null, 2) + `
153
+ `, "utf-8");
154
+ }
155
+ function requireSession() {
156
+ const session = readSession();
157
+ if (!session) {
158
+ throw new Error('No active session. Run "snapfail init" to authenticate.');
159
+ }
160
+ return session;
161
+ }
162
+
130
163
  // src/api.ts
131
164
  async function apiFetch(url, options) {
132
165
  let res;
@@ -285,7 +318,8 @@ function formatIncidentDetail(group, sample) {
285
318
 
286
319
  // src/commands/incidents.ts
287
320
  async function runIncidents(opts) {
288
- const config = loadConfig();
321
+ requireSession();
322
+ const config = loadConfig(process.cwd(), opts.pk);
289
323
  const result = await fetchIncidents(config, {
290
324
  status: opts.status ?? "unresolved",
291
325
  limit: opts.limit,
@@ -301,7 +335,8 @@ async function runIncidents(opts) {
301
335
 
302
336
  // src/commands/incident.ts
303
337
  async function runIncident(opts) {
304
- const config = loadConfig();
338
+ requireSession();
339
+ const config = loadConfig(process.cwd(), opts.pk);
305
340
  if (opts.delete) {
306
341
  const ok = await deleteGroup(config, opts.id);
307
342
  if (!ok) {
@@ -1902,30 +1937,6 @@ Config file: \`.snapfail.json\` (gitignored)
1902
1937
  `;
1903
1938
  }
1904
1939
 
1905
- // src/session.ts
1906
- import { readFileSync as readFileSync2, writeFileSync as writeFileSync2, mkdirSync, existsSync as existsSync2, rmSync } from "fs";
1907
- import { join } from "path";
1908
- import { homedir } from "os";
1909
- var SESSION_DIR = join(homedir(), ".snapfail");
1910
- var SESSION_FILE = join(SESSION_DIR, "auth.json");
1911
- function readSession() {
1912
- try {
1913
- if (!existsSync2(SESSION_FILE))
1914
- return null;
1915
- const raw = JSON.parse(readFileSync2(SESSION_FILE, "utf-8"));
1916
- if (!raw.token || !raw.endpoint)
1917
- return null;
1918
- return raw;
1919
- } catch {
1920
- return null;
1921
- }
1922
- }
1923
- function writeSession(session) {
1924
- mkdirSync(SESSION_DIR, { recursive: true });
1925
- writeFileSync2(SESSION_FILE, JSON.stringify(session, null, 2) + `
1926
- `, "utf-8");
1927
- }
1928
-
1929
1940
  // src/auth.ts
1930
1941
  import { execSync } from "child_process";
1931
1942
  function openBrowser(url) {
@@ -2346,7 +2357,8 @@ function formatDiagnosis(d) {
2346
2357
  `);
2347
2358
  }
2348
2359
  async function runExplain(opts) {
2349
- const config = loadConfig();
2360
+ requireSession();
2361
+ const config = loadConfig(process.cwd(), opts.pk);
2350
2362
  const diagnosis = await fetchDiagnosis(config, opts.id, opts.force ?? false);
2351
2363
  if (!diagnosis) {
2352
2364
  console.error(`Incident ${opts.id} not found.`);
@@ -2384,6 +2396,7 @@ var VERSION = "0.0.18";
2384
2396
  async function main() {
2385
2397
  const { command, args, flags } = parseArgs(process.argv);
2386
2398
  const json = flags["json"] === true;
2399
+ const pk = typeof flags["pk"] === "string" ? flags["pk"] : undefined;
2387
2400
  if (command === "--version" || command === "-v" || flags["version"] === true) {
2388
2401
  console.log(VERSION);
2389
2402
  return;
@@ -2396,6 +2409,7 @@ async function main() {
2396
2409
  if (command === "incidents") {
2397
2410
  await runIncidents({
2398
2411
  json,
2412
+ pk,
2399
2413
  status: typeof flags["status"] === "string" ? flags["status"] : undefined,
2400
2414
  limit: typeof flags["limit"] === "string" ? parseInt(flags["limit"]) : undefined,
2401
2415
  offset: typeof flags["offset"] === "string" ? parseInt(flags["offset"]) : undefined
@@ -2410,7 +2424,7 @@ async function main() {
2410
2424
  }
2411
2425
  const sampleFlag = flags["sample"];
2412
2426
  const sample = typeof sampleFlag === "string" ? parseInt(sampleFlag) : undefined;
2413
- await runIncident({ id, sample, json, delete: flags["delete"] === true });
2427
+ await runIncident({ id, sample, json, pk, delete: flags["delete"] === true });
2414
2428
  return;
2415
2429
  }
2416
2430
  if (command === "explain") {
@@ -2419,7 +2433,7 @@ async function main() {
2419
2433
  console.error("Usage: snapfail explain <id> [--force] [--json]");
2420
2434
  process.exit(1);
2421
2435
  }
2422
- await runExplain({ id, force: flags["force"] === true, json });
2436
+ await runExplain({ id, force: flags["force"] === true, json, pk });
2423
2437
  return;
2424
2438
  }
2425
2439
  console.error(`Unknown command: ${command}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "snapfail",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "type": "module",
5
5
  "description": "CLI for snapfail — project setup, incident inspection and AI diagnostics",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -35,6 +35,7 @@ const VERSION = "0.0.18";
35
35
  async function main(): Promise<void> {
36
36
  const { command, args, flags } = parseArgs(process.argv);
37
37
  const json = flags["json"] === true;
38
+ const pk = typeof flags["pk"] === "string" ? flags["pk"] : undefined;
38
39
 
39
40
  if (command === "--version" || command === "-v" || flags["version"] === true) {
40
41
  console.log(VERSION);
@@ -50,6 +51,7 @@ async function main(): Promise<void> {
50
51
  if (command === "incidents") {
51
52
  await runIncidents({
52
53
  json,
54
+ pk,
53
55
  status: typeof flags["status"] === "string" ? flags["status"] : undefined,
54
56
  limit: typeof flags["limit"] === "string" ? parseInt(flags["limit"]) : undefined,
55
57
  offset: typeof flags["offset"] === "string" ? parseInt(flags["offset"]) : undefined,
@@ -66,7 +68,7 @@ async function main(): Promise<void> {
66
68
  const sampleFlag = flags["sample"];
67
69
  const sample =
68
70
  typeof sampleFlag === "string" ? parseInt(sampleFlag) : undefined;
69
- await runIncident({ id, sample, json, delete: flags["delete"] === true });
71
+ await runIncident({ id, sample, json, pk, delete: flags["delete"] === true });
70
72
  return;
71
73
  }
72
74
 
@@ -76,7 +78,7 @@ async function main(): Promise<void> {
76
78
  console.error("Usage: snapfail explain <id> [--force] [--json]");
77
79
  process.exit(1);
78
80
  }
79
- await runExplain({ id, force: flags["force"] === true, json });
81
+ await runExplain({ id, force: flags["force"] === true, json, pk });
80
82
  return;
81
83
  }
82
84