@fixback/sdk 0.4.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.
@@ -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 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 {};
@@ -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` Feedback (stamped `Kind = bug` server-side, ADR-0023) 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,42 +24,20 @@
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
30
  import type { ReporterDisplay } from "./invite";
30
- import { type CapturedFrame } from "./report";
31
31
  import type { ReplaySource } from "./replay";
32
- import { type BeforeSend } from "./scrub";
33
- import { type Capture, type CaptureOptions } from "./screenshot";
34
32
  import { type SubmitInput, type SubmitResult } from "./submit";
35
33
  export type { Teardown };
34
+ export { computeFingerprint, extractTopFrames, hashString, normalize };
36
35
  /** Burst limiter capacity — how many auto-reports may fire back-to-back (§E). */
37
36
  export declare const DEFAULT_BURST_CAPACITY = 5;
38
37
  /** Burst limiter refill — one token returns every this-many ms (§E). */
39
38
  export declare const DEFAULT_BURST_REFILL_MS = 2000;
40
39
  /** Per-session ceiling on distinct auto-Feedback; beyond it, only a dropped-count (§E). */
41
40
  export declare const DEFAULT_MAX_DISTINCT_AUTO = 20;
42
- /**
43
- * Collapse the volatile parts of an error message so a changing string doesn't
44
- * split one bug: UUIDs, URLs, `0x…` and long hex runs, and long digit runs are
45
- * replaced with stable placeholders. Short numbers and stable text are kept so
46
- * genuinely distinct bugs stay distinct. A small, dependency-free regex set —
47
- * tunable per ticket #92, never a frozen magic set.
48
- */
49
- export declare function normalize(value: string): string;
50
- /**
51
- * A dependency-free FNV-1a hash rendered in base-36. It only has to be stable and
52
- * well-distributed within one session (the client key is a flood guard; the server
53
- * does canonical cross-session clustering), so a non-cryptographic hash is right.
54
- */
55
- export declare function hashString(input: string): string;
56
- /**
57
- * Extract a compact, stable signature of the top in-app frames of a stack: up to
58
- * {@link FINGERPRINT_FRAME_LIMIT} frames as `function@basename:line:col`, origin
59
- * and cache-busting query stripped so a per-deploy asset hash doesn't matter within
60
- * a session. Returns `""` when there is no usable stack (message-only fallback).
61
- */
62
- export declare function extractTopFrames(stack: string | undefined, limit?: number): string;
63
41
  /**
64
42
  * Extract **structured** frames from a stack for the wire (#117, ADR-0024) —
65
43
  * unlike {@link extractTopFrames} (a compact fingerprint signature that drops the
@@ -69,12 +47,6 @@ export declare function extractTopFrames(stack: string | undefined, limit?: numb
69
47
  * `<anonymous>`, eval) are skipped; the count is capped.
70
48
  */
71
49
  export declare function extractStructuredFrames(stack: string | undefined, limit?: number): CapturedFrame[];
72
- /**
73
- * The per-session fingerprint (research §7.2):
74
- * `hash(errorType + "|" + normalize(value) + "|" + topFrames)`. Stack frames
75
- * dominate when present; otherwise it falls back to type + normalized value.
76
- */
77
- export declare function computeFingerprint(type: string, value: string, stack?: string): string;
78
50
  /** Configuration for {@link TokenBucket}. */
79
51
  export interface TokenBucketOptions {
80
52
  readonly capacity: number;
@@ -99,7 +71,6 @@ export declare class TokenBucket {
99
71
  }
100
72
  /** Injectable collaborators, defaulted to the real implementations. */
101
73
  export interface AutoCaptureDeps {
102
- readonly captureView: (options?: CaptureOptions) => Promise<Capture | null>;
103
74
  readonly submitReport: (apiUrl: string, input: SubmitInput, fetchImpl?: typeof fetch) => Promise<SubmitResult>;
104
75
  }
105
76
  /** Configuration for {@link installErrorCapture}. */