catchfn 0.1.1 → 0.2.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 +45 -13
- package/dist/index.cjs +425 -325
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +74 -18
- package/dist/index.d.ts +74 -18
- package/dist/index.js +425 -325
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
|
+
<!-- Generated by scripts/bare-readme.mjs from front-door.template.md and the READMEs it includes; edit those and run `npm run readmes:bare`. -->
|
|
2
|
+
|
|
1
3
|
# catchfn
|
|
2
4
|
|
|
3
5
|
Console, network, breadcrumb, error and WebSocket collectors that record what happened in a
|
|
4
6
|
browser or Node process as versioned **evidence events**. The collectors run on
|
|
5
7
|
their own: no reporter client, widget or server is needed.
|
|
6
8
|
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install catchfn
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`catchfn` has no runtime dependencies and runs in browsers and Node.js.
|
|
16
|
+
|
|
17
|
+
## Quick start
|
|
18
|
+
|
|
7
19
|
```ts
|
|
8
20
|
import { BreadcrumbCollector, ConsoleCollector, ErrorCollector, NetworkCollector, WebSocketCollector, validateEvidenceEvent } from "catchfn";
|
|
9
21
|
|
|
@@ -31,21 +43,21 @@ errors.stop();
|
|
|
31
43
|
sockets.stop();
|
|
32
44
|
```
|
|
33
45
|
|
|
34
|
-
## Evidence
|
|
46
|
+
## Evidence event formats
|
|
35
47
|
|
|
36
|
-
Every event has `schemaVersion
|
|
48
|
+
Every event has a `schemaVersion`, a `kind` (`"console"`, `"network"`,
|
|
37
49
|
`"breadcrumb"`, `"error"` or `"websocket"`), a `seq` capture-order number and a `timestamp` in epoch
|
|
38
50
|
milliseconds, plus the fields of its kind. The format is closed: extra fields
|
|
39
51
|
are invalid. Check an event with `validateEvidenceEvent(event)` (returns a list
|
|
40
52
|
of problems, empty when valid) or with any JSON Schema 2020-12 validator and
|
|
41
53
|
the exported `evidenceEventSchema`. Integer fields (`seq`, `timestamp`,
|
|
42
|
-
`status`, `lineno`, `colno`, `size`, `code`) are safe integers in both, and nested records (`data`, header
|
|
43
|
-
records, objects in `args`) must be plain or null-prototype objects without a
|
|
54
|
+
`argumentCount`, `status`, `lineno`, `colno`, `size`, `code`) are safe integers in both, and nested records (`data`, header
|
|
55
|
+
records, and objects in legacy `args`) must be plain or null-prototype objects without a
|
|
44
56
|
callable `toJSON`.
|
|
45
57
|
|
|
46
58
|
| kind | fields |
|
|
47
59
|
| --- | --- |
|
|
48
|
-
| `console` | `level` (`log`, `info`, `warn`, `error`, `debug`), `
|
|
60
|
+
| `console` | `level` (`log`, `info`, `warn`, `error`, `debug`), `argumentCount`, `source` (`console`), optional `lineno` and `colno` |
|
|
49
61
|
| `network` | `transport` (`fetch`, `xhr`), `method`, `url`, optional `status`, `statusText`, `duration`, `requestHeaders`, `responseHeaders` |
|
|
50
62
|
| `breadcrumb` | `type` (`navigation`, `console`, `network`, `user`, `custom`), optional `message`, `data`, `category`, `level` (`debug`, `info`, `warning`, `error`) |
|
|
51
63
|
| `error` | `source` (`error`, `unhandledrejection`), `message`, optional `name`, `stack`, `filename`, `lineno`, `colno`, `value` |
|
|
@@ -53,6 +65,16 @@ callable `toJSON`.
|
|
|
53
65
|
|
|
54
66
|
Captured events are frozen.
|
|
55
67
|
|
|
68
|
+
Starting with 0.2.0, console collectors record metadata with `schemaVersion: 2`.
|
|
69
|
+
The other collectors continue to emit version 1. Use `argumentCount`
|
|
70
|
+
to show how many arguments were passed. The original console call receives
|
|
71
|
+
the arguments unchanged, and the collector never inspects their contents.
|
|
72
|
+
Wrapped calls omit coordinates and never request a stack. If your instrumentation
|
|
73
|
+
already knows the numeric call site, use `collector.record(level, argumentCount,
|
|
74
|
+
lineno, colno)` to record it directly. This method can be used without starting
|
|
75
|
+
the console wrappers. The current validators accept saved v1 events with `args`
|
|
76
|
+
from earlier releases. Update validators before consuming the new console events.
|
|
77
|
+
|
|
56
78
|
## Time-window queries
|
|
57
79
|
|
|
58
80
|
Each collector keeps its events in a fixed-size ring buffer (the constructor's
|
|
@@ -164,17 +186,23 @@ uncaught error while it runs.
|
|
|
164
186
|
|
|
165
187
|
- An uncaught error is read from a platform `ErrorEvent` through the getters
|
|
166
188
|
captured at load: `message` is the browser's text (`"Uncaught Error: boom"`)
|
|
167
|
-
when it has one
|
|
168
|
-
|
|
189
|
+
when it has one. The collector omits `data:` filenames because they contain
|
|
190
|
+
inline source. Other filenames go through `redactUrl`. The numeric `lineno`
|
|
191
|
+
and `colno` are kept. An `error` event that is not an `ErrorEvent` (one the page
|
|
169
192
|
dispatches itself) is ignored.
|
|
170
193
|
- An unhandled rejection's reason is read through the captured
|
|
171
194
|
`PromiseRejectionEvent` getter, and an `unhandledrejection` event that is
|
|
172
195
|
not a `PromiseRejectionEvent` is ignored. Only on a runtime without that
|
|
173
196
|
class is the reason read from the event's own `reason` data property.
|
|
174
197
|
- A thrown value or reason that is an `Error` gives `name`, `message` and
|
|
175
|
-
`stack`, serialized as one entry; reading
|
|
176
|
-
getters
|
|
177
|
-
`
|
|
198
|
+
`stack`, serialized as one entry; reading diagnostics can run the error's own
|
|
199
|
+
getters. A linear scan replaces absolute and `data:` stack URLs with
|
|
200
|
+
`[REDACTED_URL]` without expanding the retained input prefix. A URL token's
|
|
201
|
+
numeric suffix can belong to the URL, so the scan masks it too. The browser's
|
|
202
|
+
numeric error-event fields described above still carry locations. A `data:`
|
|
203
|
+
token masks the rest of its line because inline source can include spaces
|
|
204
|
+
and frame-like text. That rule can also hide a function label that contains
|
|
205
|
+
`data:`. Any other value is serialized into
|
|
178
206
|
`value`, and `message` holds it as text (a string as is, anything else as
|
|
179
207
|
its JSON). An uncaught error whose `ErrorEvent.error` is `null` or
|
|
180
208
|
`undefined` has no `value`: a cross-origin `"Script error."` and an
|
|
@@ -261,7 +289,7 @@ constructs through the page's own class and is not observed.
|
|
|
261
289
|
or adding a listener) is a no-op, and a `stop()` during that install leaves
|
|
262
290
|
the session at once: a socket constructed meanwhile is never observed, also
|
|
263
291
|
after a restart. Each collector holds at most one subscription.
|
|
264
|
-
- Timestamps of the error and WebSocket collectors come from the `Date.now`
|
|
292
|
+
- Timestamps of the console, error and WebSocket collectors come from the `Date.now`
|
|
265
293
|
captured at load. An observation whose clock gives anything but a
|
|
266
294
|
nonnegative safe integer is dropped; the event or send itself is unchanged.
|
|
267
295
|
Loading never throws: with no `Date.now` to capture then (a throwing
|
|
@@ -295,8 +323,7 @@ Captured values are snapshotted under a closed set of forms:
|
|
|
295
323
|
One entry is at most 10 KB of UTF-8 JSON; strings are cut and containers stop
|
|
296
324
|
early with a `"[Truncated]"` marker (the last array item, or a record key
|
|
297
325
|
whose value counts the omitted keys; `"[Truncated 2]"`, ... when the record
|
|
298
|
-
already holds that key). A
|
|
299
|
-
entry, and each argument counts its depth from 1. A breadcrumb's `data` and
|
|
326
|
+
already holds that key). A breadcrumb's `data` and
|
|
300
327
|
`message`, a network event's `url` and each header record, an error event's
|
|
301
328
|
`message`, `filename` and thrown value (an `Error`'s name, message and stack
|
|
302
329
|
together, or `value`), and a websocket event's `url`, are entries.
|
|
@@ -313,3 +340,8 @@ together, or `value`), and a websocket event's `url`, are entries.
|
|
|
313
340
|
- `redactObject(value)` snapshots a value and redacts keys that name secrets,
|
|
314
341
|
plus URLs under `url`/`href` keys; the redacted result keeps the 10 KB bound.
|
|
315
342
|
- `redactString(text)` masks card numbers.
|
|
343
|
+
|
|
344
|
+
## Packages
|
|
345
|
+
|
|
346
|
+
`catchfn` is the whole product: the collectors, the evidence event schema and validator, and the redaction helpers
|
|
347
|
+
all ship in this one package, with no scoped packages to install alongside it.
|