@snapfail/browser 0.0.1 → 0.0.4

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 ADDED
@@ -0,0 +1,24 @@
1
+ # @snapfail/browser
2
+
3
+ Browser SDK for [snapfail](https://snapfail.com) — error capture, replay and transport.
4
+
5
+ This package is used internally by the framework adapters (`@snapfail/vite`, `@snapfail/astro`, `@snapfail/next`). You don't need to install it directly unless you're integrating snapfail without an adapter.
6
+
7
+ ## Manual setup
8
+
9
+ ```bash
10
+ npm install @snapfail/browser
11
+ ```
12
+
13
+ ```ts
14
+ import { initSnapfail } from "@snapfail/browser";
15
+
16
+ initSnapfail({
17
+ projectKey: "proj_xxxxxxxxxxxxxxxxx",
18
+ environment: "prod", // or "dev"
19
+ });
20
+ ```
21
+
22
+ ## Documentation
23
+
24
+ Full docs at [snapfail.com](https://snapfail.com)
@@ -4,4 +4,5 @@ export interface CapturedError {
4
4
  message: string;
5
5
  stack: StackFrame[];
6
6
  }
7
+ export declare function parseStackFromError(stack: string | undefined): StackFrame[];
7
8
  export declare function attachErrorCollector(onError: (e: CapturedError) => void): () => void;
package/dist/index.js CHANGED
@@ -4227,7 +4227,7 @@ function buildPayload(config, error, buffers) {
4227
4227
  }
4228
4228
 
4229
4229
  // src/collectors/errors.ts
4230
- function parseStack(stack) {
4230
+ function parseStackFromError(stack) {
4231
4231
  if (!stack)
4232
4232
  return [];
4233
4233
  return stack.split(`
@@ -4248,7 +4248,7 @@ function fromError(err) {
4248
4248
  return {
4249
4249
  type: err.name || "Error",
4250
4250
  message: err.message,
4251
- stack: parseStack(err.stack)
4251
+ stack: parseStackFromError(err.stack)
4252
4252
  };
4253
4253
  }
4254
4254
  return { type: "UnknownError", message: String(err), stack: [] };
@@ -4494,6 +4494,9 @@ async function send(endpoint, payload) {
4494
4494
 
4495
4495
  // src/index.ts
4496
4496
  function initSnapfail(config) {
4497
+ if (!config.projectKey) {
4498
+ return { capture() {}, destroy() {} };
4499
+ }
4497
4500
  const windowMs = (config.bufferSeconds ?? 15) * 1000;
4498
4501
  const consoleBuffer = new RingBuffer(windowMs);
4499
4502
  const networkBuffer = new RingBuffer(windowMs);
@@ -4526,7 +4529,7 @@ function initSnapfail(config) {
4526
4529
  }
4527
4530
  function fromError2(error) {
4528
4531
  if (error instanceof Error) {
4529
- return { type: error.name || "Error", message: error.message, stack: [] };
4532
+ return { type: error.name || "Error", message: error.message, stack: parseStackFromError(error.stack) };
4530
4533
  }
4531
4534
  return { type: "UnknownError", message: String(error), stack: [] };
4532
4535
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snapfail/browser",
3
- "version": "0.0.1",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "description": "Browser SDK for snapfail — error capture, replay and transport",
6
6
  "license": "MIT",
@@ -23,6 +23,6 @@
23
23
  "prepublishOnly": "bun run build"
24
24
  },
25
25
  "dependencies": {
26
- "@snapfail/protocol": "^0.0.1"
26
+ "@snapfail/protocol": "^0.0.2"
27
27
  }
28
28
  }