@xyph3r/faultline 0.1.1 → 0.1.2

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/README.md CHANGED
@@ -1,35 +1,492 @@
1
- # faultline
1
+ # @xyph3r/faultline
2
2
 
3
- Self-hosted error tracking SDK. Zero dependencies, works everywhere.
3
+ Self-hosted error tracking SDK for JavaScript and TypeScript. Zero dependencies, works everywhere.
4
+
5
+ - **Fire-and-forget** — `capture()` never throws, never blocks
6
+ - **Under 3KB** — safe to add to any project, no dependency conflicts
7
+ - **Runs anywhere** — Node 18+, Bun, Deno, Edge Runtime, browsers
8
+ - **Full TypeScript** — typed API with autocomplete
9
+ - **Observable** — hooks to filter, enrich, and log every event
10
+
11
+ ---
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install @xyph3r/faultline
17
+ # or
18
+ bun add @xyph3r/faultline
19
+ # or
20
+ pnpm add @xyph3r/faultline
21
+ ```
22
+
23
+ ---
24
+
25
+ ## Quick Start
4
26
 
5
27
  ```ts
6
28
  import { Faultline } from "@xyph3r/faultline"
7
29
 
30
+ // Reads FAULTLINE_DSN and FAULTLINE_BASE_URL from env
31
+ Faultline.init()
32
+
33
+ // Manual capture
34
+ try {
35
+ await someRiskyOperation()
36
+ } catch (err) {
37
+ Faultline.capture(err, {
38
+ route: "/api/checkout",
39
+ userId: currentUser.id,
40
+ metadata: { cartId: cart.id }
41
+ })
42
+ }
43
+ ```
44
+
45
+ Set these environment variables:
46
+
47
+ ```bash
48
+ # Required — your project's DSN key (from the faultline dashboard)
49
+ FAULTLINE_DSN=LV0l2yhx7QtWCkoumWCw660e
50
+
51
+ # Optional — defaults to https://faultline.dev
52
+ FAULTLINE_BASE_URL=https://faultline.example.com
53
+
54
+ # Optional — release version for source map resolution
55
+ FAULTLINE_RELEASE=v2.3.1
56
+ ```
57
+
58
+ ---
59
+
60
+ ## API Reference
61
+
62
+ ### `Faultline.init(options?)`
63
+
64
+ Initialize the global singleton. Call once at app startup. Reads `FAULTLINE_DSN` and `FAULTLINE_BASE_URL` from environment if not passed explicitly.
65
+
66
+ ```ts
8
67
  Faultline.init({
9
- dsn: process.env.FAULTLINE_DSN,
10
- baseUrl: process.env.FAULTLINE_BASE_URL
68
+ dsn: "LV0l2yhx7QtWCkoumWCw660e",
69
+ baseUrl: "https://faultline.example.com",
70
+ env: "production",
71
+ release: "v2.3.1",
72
+ debug: false, // enable console warnings
73
+ enabled: true // set false to disable in dev
11
74
  })
75
+ ```
12
76
 
13
- // Manual capture
14
- Faultline.capture(err, { route: "/api/checkout", userId: "usr_123" })
77
+ All options are optional — if you set the env vars, `Faultline.init()` with no arguments is enough.
78
+
79
+ ### `Faultline.capture(error, context?)`
80
+
81
+ Capture an error. Returns a `Promise<void>` — fire and forget.
82
+
83
+ ```ts
84
+ Faultline.capture(error, {
85
+ route: "/api/checkout", // route where the error occurred
86
+ userId: "usr_123", // affected user
87
+ level: "error", // "error" | "warning" | "info" (default: "error")
88
+ release: "v2.3.1", // overrides the init-level release
89
+ metadata: { // arbitrary JSON-serializable data
90
+ cartId: "cart_456",
91
+ paymentMethod: "stripe"
92
+ }
93
+ })
94
+ ```
95
+
96
+ The `context` is fully optional — you can call `Faultline.capture(err)` with no context at all.
15
97
 
16
- // Wrap a handler
98
+ ### `Faultline.withCapture(handler, getContext?)`
99
+
100
+ Wrap any async function. If it throws, the error is captured and rethrown.
101
+
102
+ ```ts
103
+ // Basic — auto-infers route from Request.url
17
104
  export const POST = Faultline.withCapture(async (req: Request) => {
18
- // thrown errors are captured and rethrown
105
+ const body = await req.json()
106
+ return processCheckout(body)
19
107
  })
20
108
 
21
- // Observer hooks
109
+ // With custom context — use the error and arguments
110
+ export const GET = Faultline.withCapture(
111
+ async (req: Request) => {
112
+ // ... your handler logic
113
+ },
114
+ (error, [req]) => ({
115
+ route: new URL(req.url).pathname,
116
+ userId: getUserId(req)
117
+ })
118
+ )
119
+ ```
120
+
121
+ When wrapping a handler that receives a `Request` (Next.js App Router, Hono, etc.), the SDK auto-detects the route from `request.url`. Otherwise pass a `getContext` function.
122
+
123
+ ### `Faultline.expressHandler()`
124
+
125
+ Returns an Express error-handling middleware. Place it **after** your routes.
126
+
127
+ ```ts
128
+ import express from "express"
129
+ import { Faultline } from "@xyph3r/faultline"
130
+
131
+ const app = express()
132
+
133
+ Faultline.init()
134
+
135
+ app.get("/api/users", (req, res) => {
136
+ throw new Error("something broke")
137
+ })
138
+
139
+ // Must come after all routes
140
+ app.use(Faultline.expressHandler())
141
+ ```
142
+
143
+ The handler reads the route from `req.originalUrl` (or `req.route.path` / `req.url`) and calls `next(error)` after capture.
144
+
145
+ ---
146
+
147
+ ## Observer Hooks
148
+
149
+ Subscribe to events to filter sensitive data, enrich payloads, or log captures.
150
+
151
+ ```ts
152
+ // Strip PII before sending
22
153
  Faultline.on("beforeCapture", (payload) => {
23
- delete payload.metadata?.password // strip PII
154
+ // Remove sensitive fields
155
+ delete payload.metadata?.password
156
+ delete payload.metadata?.ssn
157
+
158
+ // Redact from message
159
+ if (payload.message) {
160
+ payload.message = payload.message.replace(/secret-\w+/g, "[REDACTED]")
161
+ }
162
+ })
163
+
164
+ // Log to your own system
165
+ Faultline.on("afterCapture", (payload) => {
166
+ console.log(`Captured: ${payload.title} at ${payload.route}`)
167
+ })
168
+
169
+ // Handle capture failures
170
+ Faultline.on("captureError", ({ error, ...payload }) => {
171
+ console.error("Faultline failed to send:", error)
24
172
  })
25
173
  ```
26
174
 
27
- ## Install
175
+ `Faultline.on()` returns an unsubscribe function:
176
+
177
+ ```ts
178
+ const unsubscribe = Faultline.on("beforeCapture", handler)
179
+ // later...
180
+ unsubscribe()
181
+ ```
182
+
183
+ ### Event Types
184
+
185
+ | Event | Payload | When |
186
+ |-------|---------|------|
187
+ | `beforeCapture` | `IngestPayload` | Before sending. Mutate the payload to filter/enrich. |
188
+ | `afterCapture` | `IngestPayload` | After a successful send. |
189
+ | `captureError` | `IngestPayload & { error: string }` | When the HTTP request fails. |
190
+
191
+ ---
192
+
193
+ ## Configuration
194
+
195
+ ### Options (all optional)
196
+
197
+ | Option | Env Fallback | Default | Description |
198
+ |--------|-------------|---------|-------------|
199
+ | `dsn` | `FAULTLINE_DSN` | — | Project DSN key (required to send) |
200
+ | `baseUrl` | `FAULTLINE_BASE_URL` | `https://faultline.dev` | Faultline server URL |
201
+ | `env` | `NODE_ENV` | `"production"` | Environment name (`production`, `staging`, etc.) |
202
+ | `release` | `FAULTLINE_RELEASE` | — | Release version for source map resolution |
203
+ | `enabled` | — | `true` | Set to `false` to disable all capture |
204
+ | `debug` | — | `false` | Enable console warnings for misconfiguration |
205
+ | `fetch` | — | `globalThis.fetch` | Custom fetch implementation (for polyfills) |
206
+
207
+ ### Environment Variables
28
208
 
29
209
  ```bash
30
- npm install @xyph3r/faultline
210
+ FAULTLINE_DSN=LV0l2yhx7QtWCkoumWCw660e
211
+ FAULTLINE_BASE_URL=https://faultline.example.com
212
+ FAULTLINE_RELEASE=v2.3.1
213
+ ```
214
+
215
+ The SDK reads these at init time. Pass explicit options to override.
216
+
217
+ ---
218
+
219
+ ## Multiple Projects / Non-Singleton Usage
220
+
221
+ The singleton (`Faultline.init()` + `Faultline.capture()`) covers most use cases. When you need to report to multiple faultline projects from the same process, use instance mode:
222
+
223
+ ```ts
224
+ import { Faultline } from "@xyph3r/faultline"
225
+
226
+ const backendFaultline = new Faultline({
227
+ dsn: "dsk_backend_xxxxxxxxxxxx",
228
+ baseUrl: "https://faultline.example.com"
229
+ })
230
+
231
+ const frontendFaultline = new Faultline({
232
+ dsn: "dsk_frontend_yyyyyyyyyyy",
233
+ baseUrl: "https://faultline.example.com"
234
+ })
235
+
236
+ await backendFaultline.capture(err, { route: "/api/internal" })
237
+ await frontendFaultline.capture(err, { route: "/checkout" })
238
+ ```
239
+
240
+ Instances have the same `.capture()`, `.withCapture()`, and `.expressHandler()` methods as the singleton.
241
+
242
+ ---
243
+
244
+ ## CLI: Source Map Upload
245
+
246
+ The SDK ships with a CLI for uploading source maps. Upload them as part of your build pipeline — after the build produces `.map` files, but before the deploy ships to production.
247
+
248
+ ```bash
249
+ npx faultline upload-sourcemaps --dir <path> --release <version>
250
+ ```
251
+
252
+ Requires `FAULTLINE_DSN` and optionally `FAULTLINE_BASE_URL` in the environment.
253
+
254
+ ### When to run it
255
+
256
+ Source maps must be uploaded **after the build** (when `.map` files exist) and **before errors hit production**. The `--release` flag ties source maps to a specific deployment — when faultline receives an error with a matching `release`, it uses the corresponding source map bundle to resolve the minified stack trace back to your original source code.
257
+
258
+ ```
259
+ next build ──→ upload source maps ──→ deploy
260
+
261
+ this is the critical step
262
+ if you skip it, minified stacks stay minified
263
+ ```
264
+
265
+ ### CI/CD examples
266
+
267
+ **GitHub Actions:**
268
+
269
+ ```yaml
270
+ - name: Build
271
+ run: next build
272
+
273
+ - name: Upload source maps to faultline
274
+ env:
275
+ FAULTLINE_DSN: ${{ secrets.FAULTLINE_DSN }}
276
+ FAULTLINE_BASE_URL: ${{ secrets.FAULTLINE_BASE_URL }}
277
+ run: npx faultline upload-sourcemaps --dir .next/static --release ${{ github.ref_name }}
278
+
279
+ - name: Deploy
280
+ run: docker push myapp:${{ github.ref_name }}
281
+ ```
282
+
283
+ **Docker build (multi-stage):**
284
+
285
+ ```dockerfile
286
+ # Stage 1: Build + upload
287
+ FROM oven/bun:1 AS build
288
+ WORKDIR /app
289
+ COPY . .
290
+ RUN bun install && next build
291
+ ENV FAULTLINE_DSN=${FAULTLINE_DSN}
292
+ ENV FAULTLINE_BASE_URL=${FAULTLINE_BASE_URL}
293
+ RUN npx faultline upload-sourcemaps --dir .next/static --release ${RELEASE_VERSION}
294
+
295
+ # Stage 2: Production image (no source maps)
296
+ FROM oven/bun:1 AS prod
297
+ WORKDIR /app
298
+ COPY --from=build /app/.next ./.next
299
+ COPY --from=build /app/node_modules ./node_modules
300
+ CMD ["bun", "start"]
31
301
  ```
32
302
 
303
+ **Vercel / Netlify / other platforms:**
304
+
305
+ On platforms where you can't run arbitrary CLI commands during build, use a post-build script in `package.json`:
306
+
307
+ ```json
308
+ {
309
+ "scripts": {
310
+ "build": "next build",
311
+ "postbuild": "faultline upload-sourcemaps --dir .next/static --release $VERCEL_GIT_COMMIT_REF"
312
+ }
313
+ }
314
+ ```
315
+
316
+ Set `FAULTLINE_DSN` and `FAULTLINE_BASE_URL` as environment variables in your platform's dashboard.
317
+
318
+ ---
319
+
320
+ ## Framework Integration
321
+
322
+ ### Next.js (App Router)
323
+
324
+ **Step 1: Initialize the SDK**
325
+
326
+ ```ts
327
+ // app/faultline.ts — init once, import from anywhere
328
+ import { Faultline } from "@xyph3r/faultline"
329
+
330
+ Faultline.init({
331
+ dsn: process.env.FAULTLINE_DSN!,
332
+ baseUrl: process.env.FAULTLINE_BASE_URL,
333
+ release: process.env.FAULTLINE_RELEASE // ties errors to this deploy
334
+ })
335
+
336
+ export { Faultline }
337
+ ```
338
+
339
+ **Step 2: Wrap your API routes**
340
+
341
+ ```ts
342
+ // app/api/checkout/route.ts
343
+ import { Faultline } from "@/app/faultline"
344
+
345
+ export const POST = Faultline.withCapture(async (req: Request) => {
346
+ // thrown errors are captured and rethrown
347
+ })
348
+ ```
349
+
350
+ **Step 3: Upload source maps after each build**
351
+
352
+ Add a `postbuild` script so source maps are uploaded every time you build:
353
+
354
+ ```json
355
+ // package.json
356
+ {
357
+ "scripts": {
358
+ "build": "next build",
359
+ "postbuild": "faultline upload-sourcemaps --dir .next/static --release $FAULTLINE_RELEASE"
360
+ }
361
+ }
362
+ ```
363
+
364
+ Set these environment variables in your CI/CD or `.env`:
365
+
366
+ ```bash
367
+ FAULTLINE_DSN=LV0l2yhx7QtWCkoumWCw660e
368
+ FAULTLINE_BASE_URL=https://faultline.example.com
369
+ FAULTLINE_RELEASE=v2.3.1 # or $GIT_SHA, $VERCEL_GIT_COMMIT_SHA, etc.
370
+ ```
371
+
372
+ **Step 4: (Optional) Client-side error boundary**
373
+
374
+ ```ts
375
+ // app/global-error.tsx
376
+ "use client"
377
+ import { useEffect } from "react"
378
+ import { Faultline } from "@xyph3r/faultline"
379
+
380
+ export default function GlobalError({ error }: { error: Error }) {
381
+ useEffect(() => {
382
+ Faultline.capture(error)
383
+ }, [error])
384
+ return <html><body><h1>Something went wrong</h1></body></html>
385
+ }
386
+ ```
387
+
388
+ **How the pieces fit together:**
389
+
390
+ ```
391
+ next build → produces .next/static/**/*.js.map
392
+ postbuild → uploads .map files to faultline with --release v2.3.1
393
+ deploy → ship to production
394
+ error occurs → SDK sends error with release: "v2.3.1"
395
+ faultline dashboard → resolves minified stack using the v2.3.1 source maps
396
+ → shows original source code in the error detail sheet
397
+ ```
398
+
399
+ If you skip the postbuild step, faultline still tracks errors — the stack traces just show the minified file/line/col instead of the original source.
400
+ return <html><body>Something went wrong</body></html>
401
+ }
402
+ ```
403
+
404
+ ### Express
405
+
406
+ ```ts
407
+ import express from "express"
408
+ import { Faultline } from "@xyph3r/faultline"
409
+
410
+ const app = express()
411
+ Faultline.init()
412
+
413
+ app.use(Faultline.expressHandler())
414
+ app.listen(3000)
415
+ ```
416
+
417
+ ### Hono
418
+
419
+ ```ts
420
+ import { Hono } from "hono"
421
+ import { Faultline } from "@xyph3r/faultline"
422
+
423
+ const app = new Hono()
424
+ Faultline.init()
425
+
426
+ app.onError((err, c) => {
427
+ Faultline.capture(err, {
428
+ route: c.req.path,
429
+ userId: c.get("userId")
430
+ })
431
+ return c.json({ error: "Internal server error" }, 500)
432
+ })
433
+ ```
434
+
435
+ ### Plain Node.js
436
+
437
+ ```ts
438
+ import { Faultline } from "@xyph3r/faultline"
439
+
440
+ Faultline.init()
441
+
442
+ process.on("uncaughtException", (err) => {
443
+ Faultline.capture(err)
444
+ process.exit(1)
445
+ })
446
+
447
+ process.on("unhandledRejection", (reason) => {
448
+ Faultline.capture(reason)
449
+ })
450
+ ```
451
+
452
+ ---
453
+
454
+ ## How It Works
455
+
456
+ ```
457
+ your app → Faultline.capture(err)
458
+ → normalize error (name, message, stack, file, line)
459
+ → call beforeCapture hooks (filter/enrich)
460
+ → POST /ingest/{dsn} (fire-and-forget)
461
+ → call afterCapture hooks
462
+ ```
463
+
464
+ The [faultline API](https://github.com/faisalahmedsifat/faultline) handles deduplication (fingerprint-based), persistence, and alerting. The SDK only normalizes and sends — it never blocks, and errors in the capture path itself are silently caught and surfaced via the `captureError` hook.
465
+
466
+ ---
467
+
33
468
  ## Requirements
34
469
 
35
- Node 18+, Bun, Deno, or any runtime with `fetch` and `crypto`.
470
+ - Node 18+, Bun, Deno, or any runtime with `fetch` and `crypto`
471
+ - No polyfills needed
472
+ - Zero npm dependencies
473
+
474
+ ---
475
+
476
+ ## Comparison: Faultline SDK vs Sentry SDK
477
+
478
+ | | Faultline SDK | Sentry SDK |
479
+ |---|---|---|
480
+ | Dependencies | 0 | 40+ |
481
+ | Bundle size | < 3KB | 50KB+ |
482
+ | Runtimes | Node, Bun, Deno, Edge, browsers | Same |
483
+ | Self-hosted | Designed for faultline | Works with faultline via DSN |
484
+ | Features | Capture, hooks, source maps | Breadcrumbs, spans, profiling |
485
+
486
+ If you need breadcrumbs, performance tracing, or session replay, use any [Sentry SDK](https://docs.sentry.io/platforms/) pointed at your faultline instance. If you want a lightweight, zero-dependency error tracker, use the faultline SDK.
487
+
488
+ ---
489
+
490
+ ## License
491
+
492
+ MIT
package/dist/cli.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * faultline CLI — upload source maps
4
+ *
5
+ * Usage:
6
+ * faultline upload-sourcemaps --dir .next/static --release v2.3.1
7
+ * faultline upload-sourcemaps --dir dist --release $npm_package_version
8
+ *
9
+ * Env vars:
10
+ * FAULTLINE_DSN — project DSN key
11
+ * FAULTLINE_BASE_URL — faultline server URL
12
+ */
13
+ declare function main(): Promise<void>;
14
+ declare function uploadSourcemaps(args: string[]): Promise<void>;
package/dist/cli.js ADDED
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env bun
2
+ "use strict";
3
+ /**
4
+ * faultline CLI — upload source maps
5
+ *
6
+ * Usage:
7
+ * faultline upload-sourcemaps --dir .next/static --release v2.3.1
8
+ * faultline upload-sourcemaps --dir dist --release $npm_package_version
9
+ *
10
+ * Env vars:
11
+ * FAULTLINE_DSN — project DSN key
12
+ * FAULTLINE_BASE_URL — faultline server URL
13
+ */
14
+ async function main() {
15
+ const args = process.argv.slice(2);
16
+ const command = args[0];
17
+ if (!command || command === "help") {
18
+ console.log(`faultline CLI
19
+
20
+ Usage:
21
+ faultline upload-sourcemaps --dir <path> --release <version>
22
+
23
+ Commands:
24
+ upload-sourcemaps Upload .map files to faultline for source map resolution
25
+ help Show this help
26
+
27
+ Options:
28
+ --dir <path> Directory containing .map files
29
+ --release <version> Release version (e.g. "v2.3.1")
30
+
31
+ Env:
32
+ FAULTLINE_DSN Project DSN key (required)
33
+ FAULTLINE_BASE_URL faultline server URL (default: https://faultline.dev)
34
+ `);
35
+ return;
36
+ }
37
+ if (command === "upload-sourcemaps") {
38
+ await uploadSourcemaps(args.slice(1));
39
+ }
40
+ else {
41
+ console.error(`Unknown command: ${command}`);
42
+ process.exit(1);
43
+ }
44
+ }
45
+ async function uploadSourcemaps(args) {
46
+ const dirIdx = args.indexOf("--dir");
47
+ const releaseIdx = args.indexOf("--release");
48
+ if (dirIdx === -1 || releaseIdx === -1) {
49
+ console.error("Usage: faultline upload-sourcemaps --dir <path> --release <version>");
50
+ process.exit(1);
51
+ }
52
+ const dir = args[dirIdx + 1];
53
+ const release = args[releaseIdx + 1];
54
+ if (!dir || !release) {
55
+ console.error("--dir and --release are required");
56
+ process.exit(1);
57
+ }
58
+ const dsn = process.env.FAULTLINE_DSN;
59
+ const baseUrl = process.env.FAULTLINE_BASE_URL ?? "https://faultline.dev";
60
+ if (!dsn) {
61
+ console.error("FAULTLINE_DSN is not set");
62
+ process.exit(1);
63
+ }
64
+ // Find .map files
65
+ const { readdir, readFile } = await import("node:fs/promises");
66
+ const { join, extname } = await import("node:path");
67
+ let files;
68
+ try {
69
+ files = (await readdir(dir, { recursive: true }))
70
+ .filter((f) => extname(f) === ".map");
71
+ }
72
+ catch (err) {
73
+ console.error(`Cannot read directory: ${dir}`);
74
+ process.exit(1);
75
+ }
76
+ if (files.length === 0) {
77
+ console.log("No .map files found in", dir);
78
+ return;
79
+ }
80
+ console.log(`Uploading ${files.length} source maps to faultline...`);
81
+ const formData = new FormData();
82
+ formData.append("release", release);
83
+ for (const file of files) {
84
+ const content = await readFile(join(dir, file));
85
+ formData.append("files", new Blob([content]), file);
86
+ }
87
+ const projectId = dsn; // DSN key is the project identifier
88
+ const url = `${baseUrl}/api/projects/${projectId}/sourcemaps`;
89
+ try {
90
+ const res = await fetch(url, { method: "POST", body: formData });
91
+ if (!res.ok) {
92
+ const body = await res.json().catch(() => ({}));
93
+ console.error(`Upload failed: ${body?.error?.message ?? res.statusText}`);
94
+ process.exit(1);
95
+ }
96
+ const data = await res.json();
97
+ console.log(`Uploaded ${data.uploaded} source maps for release ${data.release}`);
98
+ }
99
+ catch (err) {
100
+ console.error("Upload failed:", err instanceof Error ? err.message : "Network error");
101
+ process.exit(1);
102
+ }
103
+ }
104
+ main();
package/dist/client.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare class FaultlineClient {
4
4
  dsn: string | undefined;
5
5
  baseUrl: string | undefined;
6
6
  env: string;
7
+ release: string | undefined;
7
8
  enabled: boolean;
8
9
  debug: boolean;
9
10
  fetch: typeof fetch | undefined;
package/dist/client.js CHANGED
@@ -5,6 +5,7 @@ export class FaultlineClient {
5
5
  dsn: options.dsn ?? process.env.FAULTLINE_DSN,
6
6
  baseUrl: options.baseUrl ?? process.env.FAULTLINE_BASE_URL ?? "https://faultline.dev",
7
7
  env: options.env ?? process.env.NODE_ENV ?? "production",
8
+ release: options.release ?? process.env.FAULTLINE_RELEASE,
8
9
  enabled: options.enabled ?? true,
9
10
  debug: options.debug ?? false,
10
11
  fetch: options.fetch,
@@ -23,7 +24,8 @@ export class FaultlineClient {
23
24
  }
24
25
  let payload = buildPayload(error, {
25
26
  ...context,
26
- env: this.options.env
27
+ env: this.options.env,
28
+ release: context.release ?? this.options.release
27
29
  });
28
30
  if (this.options.onBeforeCapture) {
29
31
  const modified = this.options.onBeforeCapture(payload);
@@ -76,7 +78,8 @@ function buildPayload(error, context) {
76
78
  env: context.env,
77
79
  level: context.level ?? "error",
78
80
  userId: context.userId,
79
- metadata: context.metadata
81
+ metadata: context.metadata,
82
+ release: context.release
80
83
  };
81
84
  }
82
85
  function normalizeError(error) {
package/dist/types.d.ts CHANGED
@@ -3,6 +3,7 @@ export type CaptureContext = {
3
3
  route?: string;
4
4
  metadata?: Record<string, unknown>;
5
5
  level?: "error" | "warning" | "info";
6
+ release?: string;
6
7
  };
7
8
  export type IngestPayload = {
8
9
  title: string;
@@ -16,11 +17,13 @@ export type IngestPayload = {
16
17
  level?: "error" | "warning" | "info";
17
18
  userId?: string;
18
19
  metadata?: Record<string, unknown>;
20
+ release?: string;
19
21
  };
20
22
  export type FaultlineOptions = {
21
23
  baseUrl?: string;
22
24
  dsn?: string;
23
25
  env?: string;
26
+ release?: string;
24
27
  enabled?: boolean;
25
28
  debug?: boolean;
26
29
  fetch?: typeof fetch;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyph3r/faultline",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Self-hosted error tracking SDK. Zero dependencies, works everywhere.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -29,6 +29,9 @@
29
29
  "default": "./dist/types.js"
30
30
  }
31
31
  },
32
+ "bin": {
33
+ "faultline": "./dist/cli.js"
34
+ },
32
35
  "publishConfig": {
33
36
  "access": "public"
34
37
  },
@@ -39,6 +42,9 @@
39
42
  "scripts": {
40
43
  "build": "tsc -p tsconfig.json",
41
44
  "dev": "tsc -p tsconfig.json --watch",
42
- "typecheck": "tsc -p tsconfig.json --noEmit"
45
+ "typecheck": "tsc -p tsconfig.json --noEmit",
46
+ "prepublishOnly": "tsc -p tsconfig.json",
47
+ "release": "tsc -p tsconfig.json && npm publish",
48
+ "release:dry": "tsc -p tsconfig.json && npm publish --dry-run"
43
49
  }
44
50
  }