@fixback/sdk 0.3.0 → 0.5.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.
package/README.md CHANGED
@@ -8,9 +8,9 @@ launcher **only when it would**. Nothing renders when the origin isn't
8
8
  allowlisted or the Gate turns the visitor away, and if Fixback can't be reached
9
9
  the SDK stays completely silent — it never throws into the host page.
10
10
 
11
- Activating the launcher opens the **report overlay**: the Reporter picks a
12
- **Kind** (bug / improve / idea), writes a comment, optionally **points at the
13
- element** they mean, and hits **Send** — which captures a **masked screenshot**
11
+ Activating the launcher opens the **report overlay**: the Reporter writes a
12
+ comment, optionally **points at the element** they mean, and hits **Send**
13
+ which captures a **masked screenshot**
14
14
  of the current view, assembles the annotation, and submits it to Fixback. A
15
15
  successful send shows a confirmation; a refusal or an unreachable Fixback fails
16
16
  quietly, leaving the host page untouched.
@@ -79,11 +79,12 @@ fixback.destroy();
79
79
 
80
80
  The launcher is a bottom-right **Feedback** pill, and it stays out of the way:
81
81
 
82
- - **Hover-peek & tuck-away** — the pill's caret tucks it off-screen behind a
83
- small edge nub. Hovering the bottom-right corner (or the nub) peeks it back;
84
- clicking the nub or pressing Enter/Space on it brings it fully back, which
85
- also covers pointers that can't hover (touch, keyboard). A brief hint appears
86
- the first time it's tucked, pointing at the corner.
82
+ - **Hover-peek & tuck-away** — the pill's chevron tucks it off-screen to the
83
+ right behind a small edge nub, pointing **right** to tuck away and flipping to
84
+ point **left** while tucked. Hovering the bottom-right corner (or the nub)
85
+ peeks it back, where clicking that same chevron or the nub, or pressing
86
+ Enter/Space on the nub restores the launcher, which also covers pointers that
87
+ can't hover (touch, keyboard).
87
88
  - **First-visit welcome** — a one-time toast greets a new visitor, drawing the
88
89
  eye with a gentle pulse. It shows once per publishable key per browser.
89
90
  - **Reduce motion** — pass `reduceMotion: true` to still the pulse and the
@@ -111,8 +112,8 @@ document.addEventListener(LAUNCH_EVENT, () => {
111
112
 
112
113
  The SDK's signature capability: **errors report themselves, with no prompt.** Two
113
114
  capture-phase global handlers (`error` + `unhandledrejection`) turn uncaught
114
- exceptions and unhandled promise rejections into `source: auto`, `Kind = bug`
115
- Feedback for the current session's reporter — carrying the same masked screenshot
115
+ exceptions and unhandled promise rejections into `source: auto` Feedback
116
+ (classified `Kind = bug` server-side) for the current session's reporter — carrying the same masked screenshot
116
117
  and trace buffer a manual report does, plus a per-session fingerprint. It is
117
118
  **on by default across every Gate**; pass `autoCapture: false` to turn it off.
118
119
 
@@ -1,78 +1,16 @@
1
1
  /**
2
- * The Annotation & vector-marks model (spec 0003 §B/§D).
2
+ * The Annotation & vector-marks geometry (spec 0003 §B/§D).
3
3
  *
4
- * An Annotation is everything a Reporter marked on the page, as three
5
- * **composable, optional** layers over one full masked screenshot: the picked
6
- * `element` (from the element-picker), a drag-captured `region`, and vector
7
- * `marks` arrow / box / pen / text. Marks live in the **screenshot's coordinate
8
- * space** (the full viewport the screenshot is rasterised at), never baked into
9
- * the PNG: the dashboard composites them at view time (#91).
10
- *
11
- * This module is the marks' single home — the pure types and geometry used by the
12
- * region-capture and draw controllers and by the overlay's Send assembly. Like the
13
- * rest of the SDK's wire types it is vendored (no `@fixback/shared` import); keep
14
- * `Annotation` in lock-step with the server's ingest contract (spec §D/§H).
15
- */
16
- import type { SelectedElement } from "./report";
17
- /** A point in screenshot (viewport) coordinate space. */
18
- export interface Point {
19
- readonly x: number;
20
- readonly y: number;
21
- }
22
- /** A rectangle in screenshot coordinates — the same shape as an element's rect. */
23
- export interface Rect {
24
- readonly x: number;
25
- readonly y: number;
26
- readonly width: number;
27
- readonly height: number;
28
- }
29
- /** The draw tools the overlay offers, in toolbar order (spec §B, prototype). */
30
- export type DrawTool = "arrow" | "box" | "pen" | "text";
31
- /** Fields shared by every vector mark. */
32
- interface MarkBase {
33
- /** Stroke/fill colour, as a CSS colour string. */
34
- readonly color: string;
35
- }
36
- /** A directional arrow from `(x0,y0)` to its tip at `(x1,y1)`. */
37
- export interface ArrowMark extends MarkBase {
38
- readonly type: "arrow";
39
- readonly x0: number;
40
- readonly y0: number;
41
- readonly x1: number;
42
- readonly y1: number;
43
- }
44
- /** A rectangle spanning the drag from `(x0,y0)` to `(x1,y1)`. */
45
- export interface BoxMark extends MarkBase {
46
- readonly type: "box";
47
- readonly x0: number;
48
- readonly y0: number;
49
- readonly x1: number;
50
- readonly y1: number;
51
- }
52
- /** A freehand polyline through `points` (in order). */
53
- export interface PenMark extends MarkBase {
54
- readonly type: "pen";
55
- readonly points: ReadonlyArray<Point>;
56
- }
57
- /** A text label anchored at `(x,y)` (its baseline-left, as SVG text). */
58
- export interface TextMark extends MarkBase {
59
- readonly type: "text";
60
- readonly x: number;
61
- readonly y: number;
62
- readonly text: string;
63
- }
64
- /** A single vector mark, in screenshot coordinates. */
65
- export type Mark = ArrowMark | BoxMark | PenMark | TextMark;
66
- /**
67
- * The structured Annotation carried on a report's content (spec §D): the three
68
- * optional layers. Every field is optional — a report may carry any subset or
69
- * none (a bare Kind + comment is a valid Send).
4
+ * The Annotation **wire types** (`Annotation`, `Mark` and friends, `Point`,
5
+ * `Rect`, `SelectedElement`) live in `@fixback/sdk-core` (ADR-0028) so every
6
+ * surface shares one shape; this module re-exports them and holds the browser's
7
+ * pure geometry and Send-assembly used by the region-capture and draw controllers
8
+ * and the overlay. Marks live in the **screenshot's coordinate space** (the full
9
+ * viewport the screenshot is rasterised at), never baked into the PNG: the
10
+ * dashboard composites them at view time (#91).
70
11
  */
71
- export interface Annotation {
72
- readonly element?: SelectedElement;
73
- readonly region?: Rect;
74
- readonly marks?: ReadonlyArray<Mark>;
75
- }
12
+ import { type Annotation, type ArrowMark, type BoxMark, type DrawTool, type Mark, type PenMark, type Point, type Rect, type SelectedElement, type TextMark } from "@fixback/sdk-core";
13
+ export type { Annotation, ArrowMark, BoxMark, DrawTool, Mark, PenMark, Point, Rect, TextMark, };
76
14
  /**
77
15
  * The default mark colour — Signal's danger red, matching the frozen Reporter
78
16
  * prototype's draw layer (`docs/design/Fixback Reporter.dc.html`).
@@ -103,4 +41,3 @@ export declare function assembleAnnotation(parts: {
103
41
  readonly region?: Rect | null;
104
42
  readonly marks?: ReadonlyArray<Mark> | null;
105
43
  }): Annotation | undefined;
106
- export {};
package/dist/boot.d.ts CHANGED
@@ -37,6 +37,12 @@ export interface BootRequest extends IdentityInputs {
37
37
  export interface CaptureConfig {
38
38
  readonly console: boolean;
39
39
  readonly network: boolean;
40
+ /**
41
+ * The Project's session-replay toggle (issue #189, ADR-0024). Optional on the
42
+ * wire: a server predating replay omits it, which — like the other streams —
43
+ * means **capture on**.
44
+ */
45
+ readonly replay?: boolean;
40
46
  }
41
47
  /**
42
48
  * The boot answer: whether this origin is allowlisted, the Project's Gate, the
@@ -18,128 +18,8 @@
18
18
  * instrumentation hook is wrapped: a capture failure is swallowed and the original
19
19
  * behaviour (the real `console`, `fetch`, navigation) always runs.
20
20
  */
21
- /** Console-style severity a `console` crumb records. */
22
- export type BreadcrumbLevel = "log" | "info" | "warn" | "error" | "assert" | "debug";
23
- /** The kind of activity a crumb records. */
24
- export type BreadcrumbCategory = "console" | "navigation" | "fetch" | "xhr" | "beacon" | "ui.click" | "ui.input" | "error";
25
- /**
26
- * Which browser API issued a captured network request (spec #122 §D, ticket #139).
27
- * Every network crumb's `category` is one of these too, so a stream router and the
28
- * read model agree on what is a network entry.
29
- */
30
- export type NetworkApi = "fetch" | "xhr" | "beacon";
31
- /**
32
- * A network request's failure classification (spec #122 §D, ticket #139). `ok` and
33
- * the HTTP status classes come from a settled response; `network-error` / `timeout`
34
- * / `aborted` from how a request failed; `opaque-cors` from a cross-origin response
35
- * whose status is unreadable. The Network tab flags every non-`ok` outcome.
36
- */
37
- export type NetworkOutcome = "ok" | "http-4xx" | "http-5xx" | "network-error" | "timeout" | "aborted" | "opaque-cors";
38
- /**
39
- * A crumb's structured detail. Deliberately narrow: there is **no** field for a
40
- * request/response body or an input value, so those can never be recorded.
41
- */
42
- export interface BreadcrumbData {
43
- readonly url?: string;
44
- readonly method?: string;
45
- readonly status?: number;
46
- /** A masked CSS selector for a `ui.*` target — never its text or value. */
47
- readonly target?: string;
48
- readonly from?: string;
49
- readonly to?: string;
50
- readonly errorType?: string;
51
- }
52
- /**
53
- * The type tag on a structured console argument (spec #122 §C, decision D7). A
54
- * console call's arguments are preserved **type-tagged** rather than flattened to a
55
- * string, so an object/array argument can be inspected in the Console tab rather
56
- * than read as `[object Object]`: `string`/`number`/`bool`/`null` carry the value
57
- * directly, `json` a depth-/byte-capped JSON-safe clone, and `error` an Error's
58
- * `{ name, message, stack }`.
59
- */
60
- export type ConsoleArgType = "string" | "number" | "bool" | "null" | "json" | "error";
61
- /**
62
- * One structured console argument (spec #122 §C): a type tag plus a JSON-safe value.
63
- * `v` is always serializable — a `json` arg is depth-, breadth-, and string-capped at
64
- * assembly, and exotic values (bigint, symbol, function, circular refs) are rendered
65
- * to safe text — so a console crumb can never carry an unserializable or unbounded
66
- * value onto the wire.
67
- */
68
- export interface ConsoleArg {
69
- readonly t: ConsoleArgType;
70
- readonly v: unknown;
71
- }
72
- /** A `file:line` source location (spec #122 §C) — where a console call was made. */
73
- export interface SourceLocation {
74
- readonly file: string;
75
- readonly line: number;
76
- }
77
- /**
78
- * One entry in a trace stream. Alongside its semantic fields every entry carries a
79
- * stable {@link id} and a high-res monotonic {@link mono} timestamp — both stamped
80
- * by the buffer on `add` — so entries from the three independent streams order and
81
- * cross-link exactly (spec #122 §B, decision D9). `timestamp` stays epoch ms.
82
- */
83
- export interface Breadcrumb {
84
- readonly category: BreadcrumbCategory;
85
- readonly message?: string;
86
- readonly level?: BreadcrumbLevel;
87
- /** Epoch milliseconds when the crumb was recorded. */
88
- readonly timestamp: number;
89
- /** A stable id, unique within the buffer — assigned on `add` when not already set. */
90
- readonly id?: string;
91
- /** A high-res monotonic timestamp (`performance.now()`) — assigned on `add`. */
92
- readonly mono?: number;
93
- readonly data?: BreadcrumbData;
94
- /**
95
- * For a `console` crumb (spec #122 §C): the call's arguments preserved as
96
- * structured, type-tagged values (see {@link ConsoleArg}), so the Console tab can
97
- * render each argument expandably instead of a flattened string. `message` stays
98
- * the one-line preview. Absent on non-console crumbs.
99
- */
100
- readonly args?: readonly ConsoleArg[];
101
- /**
102
- * For a `console` crumb (spec #122 §C): the `file:line` the call was made from,
103
- * parsed best-effort from the call stack. Captured only for the levels that keep a
104
- * source — `warn`/`error`/`assert` (ticket #159; see {@link SOURCE_CAPTURE_LEVELS}) —
105
- * and only when the stack yields a usable location; a chatty app's `log`/`info`/`debug`
106
- * omit it so the hot-page capture cost stays low. Absent on non-console crumbs.
107
- */
108
- readonly source?: SourceLocation;
109
- /**
110
- * For an auto-captured `error` crumb only (spec #122 §F): the ids of the entries
111
- * immediately preceding the throw — a causal pointer into the same trace, so a
112
- * machine-filed crash names its lead-up. Absent on every other crumb.
113
- */
114
- readonly causedBy?: readonly string[];
115
- /**
116
- * For a network crumb (`fetch` / `xhr` / `beacon`) — spec #122 §D, ticket #139.
117
- * The rich request metadata the Network tab renders, lifted to the top level (the
118
- * console-enrichment precedent) so the read model shapes each into a
119
- * `NetworkTraceEntry`. **No field carries a request/response body or an arbitrary
120
- * header** — `respSize` derives from the `content-length` response header only and
121
- * `contentType` from `content-type`; nothing else is read. Absent on every other crumb.
122
- */
123
- readonly api?: NetworkApi;
124
- /** The request method (network crumb) — e.g. `GET`, `POST`. */
125
- readonly method?: string;
126
- /** The scrubbed request URL (network crumb) — query dropped, path PII redacted. */
127
- readonly url?: string;
128
- /** The final HTTP status (network crumb), when one was known; absent on a network error/beacon. */
129
- readonly status?: number;
130
- /** The HTTP status text (network crumb), when the response carried one. */
131
- readonly statusText?: string;
132
- /** Wall-clock duration of the request in ms (network crumb) — a `performance.now()` delta. */
133
- readonly durationMs?: number;
134
- /** Request body size in bytes (network crumb) — only when trivially known (string/Blob/ArrayBuffer), never by reading a stream. */
135
- readonly reqSize?: number;
136
- /** Response body size in bytes (network crumb) — from the `content-length` response header only. */
137
- readonly respSize?: number;
138
- /** Response content type (network crumb) — the `content-type` header's media type. */
139
- readonly contentType?: string;
140
- /** The request's failure classification (network crumb) — see {@link NetworkOutcome}. */
141
- readonly outcome?: NetworkOutcome;
142
- }
21
+ import { type Breadcrumb, type BreadcrumbCategory, type BreadcrumbData, type BreadcrumbLevel, type ConsoleArg, type ConsoleArgType, type NetworkApi, type NetworkOutcome, type SourceLocation } from "@fixback/sdk-core";
22
+ export type { Breadcrumb, BreadcrumbCategory, BreadcrumbData, BreadcrumbLevel, ConsoleArg, ConsoleArgType, NetworkApi, NetworkOutcome, SourceLocation, };
143
23
  /**
144
24
  * The three independent trace streams (spec #122 §A, decision D6). Each is its own
145
25
  * FIFO ring with its own size budget, so a chatty stream can't evict another's
@@ -445,4 +325,3 @@ export declare function instrumentUiEvents(buffer: BreadcrumbBuffer, doc: Docume
445
325
  * never blocks the others, and none can throw into the host page.
446
326
  */
447
327
  export declare function instrumentBreadcrumbs(buffer: BreadcrumbBuffer, options?: InstrumentOptions): Teardown;
448
- export {};
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * Exactly **two capture-phase listeners** (`window` `error` +
7
7
  * `unhandledrejection`) turn uncaught exceptions and unhandled rejections into
8
- * `source: auto`, `Kind = bug` Feedback for the current session's Reporter — no
8
+ * `source: error` Feedback (stamped `Kind = bug` server-side, ADR-0023) for the current session's Reporter — no
9
9
  * native-API monkeypatching, no library. Each firing is deduped by a per-session
10
10
  * fingerprint, rate-limited by a token-bucket burst limiter and a per-session cap,
11
11
  * scrubbed through the same `beforeSend` choke point as manual reports (§C), and
@@ -24,12 +24,14 @@
24
24
  * The fingerprint/`normalize` shape and the limiter numbers are **starting points**
25
25
  * from research (ticket #92), exposed as config — tunable, not frozen.
26
26
  */
27
+ import { type BeforeSend, type CapturedFrame, computeFingerprint, extractTopFrames, hashString, normalize } from "@fixback/sdk-core";
27
28
  import type { IdentityInputs } from "./boot";
28
29
  import { type BreadcrumbBuffer, type Teardown } from "./breadcrumbs";
29
- import { type BeforeSend } from "./scrub";
30
- import { type Capture, type CaptureOptions } from "./screenshot";
30
+ import type { ReporterDisplay } from "./invite";
31
+ import type { ReplaySource } from "./replay";
31
32
  import { type SubmitInput, type SubmitResult } from "./submit";
32
33
  export type { Teardown };
34
+ export { computeFingerprint, extractTopFrames, hashString, normalize };
33
35
  /** Burst limiter capacity — how many auto-reports may fire back-to-back (§E). */
34
36
  export declare const DEFAULT_BURST_CAPACITY = 5;
35
37
  /** Burst limiter refill — one token returns every this-many ms (§E). */
@@ -37,32 +39,14 @@ export declare const DEFAULT_BURST_REFILL_MS = 2000;
37
39
  /** Per-session ceiling on distinct auto-Feedback; beyond it, only a dropped-count (§E). */
38
40
  export declare const DEFAULT_MAX_DISTINCT_AUTO = 20;
39
41
  /**
40
- * Collapse the volatile parts of an error message so a changing string doesn't
41
- * split one bug: UUIDs, URLs, `0x…` and long hex runs, and long digit runs are
42
- * replaced with stable placeholders. Short numbers and stable text are kept so
43
- * genuinely distinct bugs stay distinct. A small, dependency-free regex set —
44
- * tunable per ticket #92, never a frozen magic set.
42
+ * Extract **structured** frames from a stack for the wire (#117, ADR-0024)
43
+ * unlike {@link extractTopFrames} (a compact fingerprint signature that drops the
44
+ * origin), these keep the full script URL, because server-side symbolication
45
+ * matches it against uploaded sourcemap paths. URLs are scrubbed (query dropped,
46
+ * PII redacted) before they leave the page; unlocatable frames (`native`,
47
+ * `<anonymous>`, eval) are skipped; the count is capped.
45
48
  */
46
- export declare function normalize(value: string): string;
47
- /**
48
- * A dependency-free FNV-1a hash rendered in base-36. It only has to be stable and
49
- * well-distributed within one session (the client key is a flood guard; the server
50
- * does canonical cross-session clustering), so a non-cryptographic hash is right.
51
- */
52
- export declare function hashString(input: string): string;
53
- /**
54
- * Extract a compact, stable signature of the top in-app frames of a stack: up to
55
- * {@link FINGERPRINT_FRAME_LIMIT} frames as `function@basename:line:col`, origin
56
- * and cache-busting query stripped so a per-deploy asset hash doesn't matter within
57
- * a session. Returns `""` when there is no usable stack (message-only fallback).
58
- */
59
- export declare function extractTopFrames(stack: string | undefined, limit?: number): string;
60
- /**
61
- * The per-session fingerprint (research §7.2):
62
- * `hash(errorType + "|" + normalize(value) + "|" + topFrames)`. Stack frames
63
- * dominate when present; otherwise it falls back to type + normalized value.
64
- */
65
- export declare function computeFingerprint(type: string, value: string, stack?: string): string;
49
+ export declare function extractStructuredFrames(stack: string | undefined, limit?: number): CapturedFrame[];
66
50
  /** Configuration for {@link TokenBucket}. */
67
51
  export interface TokenBucketOptions {
68
52
  readonly capacity: number;
@@ -87,7 +71,6 @@ export declare class TokenBucket {
87
71
  }
88
72
  /** Injectable collaborators, defaulted to the real implementations. */
89
73
  export interface AutoCaptureDeps {
90
- readonly captureView: (options?: CaptureOptions) => Promise<Capture | null>;
91
74
  readonly submitReport: (apiUrl: string, input: SubmitInput, fetchImpl?: typeof fetch) => Promise<SubmitResult>;
92
75
  }
93
76
  /** Configuration for {@link installErrorCapture}. */
@@ -95,13 +78,31 @@ export interface AutoCaptureConfig {
95
78
  readonly apiUrl: string;
96
79
  readonly key: string;
97
80
  readonly identity?: IdentityInputs;
81
+ /**
82
+ * The Reporter's self-provided display name / email (spec §F). Carried on
83
+ * auto-captured Feedback too, so a machine-filed crash still names whose session it
84
+ * was — display only, never a trust signal.
85
+ */
86
+ readonly display?: ReporterDisplay;
98
87
  /** The window whose global handlers are installed. Defaults to `window`. */
99
88
  readonly win?: Window;
100
89
  /** The document used for capture + environment. Defaults to the window's. */
101
90
  readonly doc?: Document;
102
91
  readonly sdkVersion?: string;
92
+ /**
93
+ * The host app's **Release** (#117, ADR-0024) — already validated by `init`
94
+ * (`normaliseRelease`). Stamped into every auto report's environment so the
95
+ * server can symbolicate the captured frames against this build's sourcemaps.
96
+ */
97
+ readonly release?: string;
103
98
  /** The shared trace buffer; the failing error is added to it before filing. */
104
99
  readonly buffer?: BreadcrumbBuffer | null;
100
+ /**
101
+ * The shared replay recorder (ADR-0024); the buffered window rides on a rich
102
+ * first report — the moment before an uncaught error is exactly what replay
103
+ * exists to show. Light count-update flushes never re-send it.
104
+ */
105
+ readonly replay?: ReplaySource | null;
105
106
  /** Per-project client scrub hook, run at the `beforeSend` choke point (§C). */
106
107
  readonly beforeSend?: BeforeSend;
107
108
  /** Run the built-in default scrubbers. Defaults to `true` (private-by-default). */