@chrom-ar/collector 0.0.0-stage → 0.3.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.
@@ -0,0 +1,150 @@
1
+ /** How bad an event is. Collector accepts exactly these four. */
2
+ type Level = "fatal" | "error" | "warning" | "info";
3
+ /** One stack frame, innermost first, as the protocol defines it. */
4
+ interface Frame {
5
+ /** Script path with content hashes removed, e.g. `/assets/index.js`. Used for grouping. */
6
+ module: string;
7
+ /** Function name, or `"?"` for anonymous functions. */
8
+ function: string;
9
+ /** Script path as loaded, e.g. `/assets/index-a1b2c3d4.js`. Shown, not grouped on. */
10
+ file: string;
11
+ line?: number;
12
+ column?: number;
13
+ /** True for the app's own code; this decides how errors group into issues. */
14
+ in_app: boolean;
15
+ }
16
+ /** Something that happened before an error: a click, a request, a log line. */
17
+ interface Breadcrumb {
18
+ /** ISO 8601; set to now when missing. */
19
+ timestamp?: string;
20
+ level?: Level;
21
+ /** e.g. `ui.click`, `fetch`, `xhr`, `navigation`, `console`. */
22
+ category?: string;
23
+ message: string;
24
+ }
25
+ /** An event as sent to Collector (protocol v1). */
26
+ interface CollectorEvent {
27
+ v: 1;
28
+ uuid: string;
29
+ timestamp: string;
30
+ platform: "javascript";
31
+ level: Level;
32
+ environment?: string;
33
+ release?: string;
34
+ exception?: {
35
+ type: string;
36
+ message?: string;
37
+ frames?: Frame[];
38
+ };
39
+ message?: string;
40
+ fingerprint?: string[];
41
+ request?: {
42
+ url: string;
43
+ headers: Record<string, string>;
44
+ };
45
+ user?: {
46
+ id: string;
47
+ };
48
+ tags?: Record<string, string>;
49
+ breadcrumbs?: Breadcrumb[];
50
+ sdk: {
51
+ name: string;
52
+ version: string;
53
+ };
54
+ }
55
+ /** Extra details for one captured event. They merge over what `setUser`/`setTag` set. */
56
+ interface CaptureContext {
57
+ level?: Level;
58
+ tags?: Record<string, string>;
59
+ /** Overrides how Collector groups this event into an issue. */
60
+ fingerprint?: string[];
61
+ user?: {
62
+ id: string | number;
63
+ };
64
+ }
65
+ type BreadcrumbKind = "console" | "dom" | "fetch" | "xhr" | "history";
66
+ interface CollectorOptions {
67
+ /** Your project's DSN, from its setup page in Collector. Without it, nothing is sent. */
68
+ dsn?: string;
69
+ /** e.g. `"production"`, `"staging"`. Issues are counted per environment. */
70
+ environment?: string;
71
+ /** Your app's version or git sha, e.g. `"web@1.4.2"`. */
72
+ release?: string;
73
+ /** Logs what the SDK does to the console, prefixed `[collector]`. Default `false`. */
74
+ debug?: boolean;
75
+ /** Set to `false` to turn the SDK off entirely. Default `true`. */
76
+ enabled?: boolean;
77
+ /**
78
+ * Last chance to edit or drop an event before it's sent. Return the event
79
+ * (changed or not) to send it, or `null` to drop it.
80
+ */
81
+ beforeSend?: (event: CollectorEvent) => CollectorEvent | null;
82
+ /**
83
+ * Errors to ignore: strings match anywhere in `"Type: message"`, regexps are
84
+ * tested against it. Added to the built-in list of well-known browser noise.
85
+ */
86
+ ignoreErrors?: (string | RegExp)[];
87
+ /**
88
+ * Which script URLs are your app's own code. When set, a frame is in-app only
89
+ * if its URL matches. Default: same origin as the page, except vendor chunks.
90
+ */
91
+ inAppUrls?: (string | RegExp)[];
92
+ /** Remove `?query` and `#hash` from URLs sent to Collector. Default `true`. */
93
+ stripQuery?: boolean;
94
+ /** Which breadcrumbs to record automatically. All on by default. */
95
+ breadcrumbs?: Partial<Record<BreadcrumbKind, boolean>>;
96
+ /** How many breadcrumbs to keep. Default `50`. */
97
+ maxBreadcrumbs?: number;
98
+ /**
99
+ * Tell Collector once a day that the app is running (its release and
100
+ * environment, nothing about the user), so it shows as set up before any
101
+ * error. Default `true`.
102
+ */
103
+ heartbeat?: boolean;
104
+ /** Report uncaught errors and unhandled promise rejections. Default: both on. */
105
+ autoCapture?: false | {
106
+ onerror?: boolean;
107
+ onunhandledrejection?: boolean;
108
+ };
109
+ }
110
+
111
+ /** The version of this SDK, as sent in every event's `sdk.version`. */
112
+ declare const SDK_VERSION: string;
113
+ /**
114
+ * Starts reporting errors to Collector. Call it once, as early as possible in
115
+ * your app's entry point:
116
+ *
117
+ * ```ts
118
+ * import * as Collector from "@chrom-ar/collector";
119
+ *
120
+ * Collector.init({ dsn: "https://clt_…@app.clt.chrom.ar" });
121
+ * ```
122
+ *
123
+ * Without a `dsn`, nothing is captured or sent. Calling it again replaces the
124
+ * options. Safe to import during server-side rendering: it does nothing there.
125
+ */
126
+ declare function init(options: CollectorOptions): void;
127
+ /**
128
+ * Reports an error you caught. Returns the event id, or `undefined` if it
129
+ * wasn't sent (no DSN, ignored, duplicate, dropped by `beforeSend`).
130
+ */
131
+ declare function captureException(error: unknown, context?: CaptureContext): string | undefined;
132
+ /** Reports something that isn't an error: `captureMessage("Payment slow", "warning")`. */
133
+ declare function captureMessage(message: string, context?: CaptureContext | Level): string | undefined;
134
+ /** Attaches your user's id to the following events. An id, not personal data. `null` clears it. */
135
+ declare function setUser(user: {
136
+ id: string | number;
137
+ } | null): void;
138
+ /** Adds a tag to the following events, e.g. `setTag("plan", "pro")`. */
139
+ declare function setTag(key: string, value: string): void;
140
+ /** Adds several tags to the following events. */
141
+ declare function setTags(tags: Record<string, string>): void;
142
+ /** Records something that happened, to be sent with the next events. */
143
+ declare function addBreadcrumb(crumb: Breadcrumb): void;
144
+ /** Waits until queued events are sent. Resolves `false` if `timeoutMs` (default 2000) passes first. */
145
+ declare function flush(timeoutMs?: number): Promise<boolean>;
146
+ /** Stops capturing and removes everything the SDK installed. */
147
+ declare function close(): void;
148
+
149
+ export { SDK_VERSION, addBreadcrumb, captureException, captureMessage, close, flush, init, setTag, setTags, setUser };
150
+ export type { Breadcrumb, BreadcrumbKind, CaptureContext, CollectorEvent, CollectorOptions, Frame, Level };
@@ -0,0 +1,150 @@
1
+ /** How bad an event is. Collector accepts exactly these four. */
2
+ type Level = "fatal" | "error" | "warning" | "info";
3
+ /** One stack frame, innermost first, as the protocol defines it. */
4
+ interface Frame {
5
+ /** Script path with content hashes removed, e.g. `/assets/index.js`. Used for grouping. */
6
+ module: string;
7
+ /** Function name, or `"?"` for anonymous functions. */
8
+ function: string;
9
+ /** Script path as loaded, e.g. `/assets/index-a1b2c3d4.js`. Shown, not grouped on. */
10
+ file: string;
11
+ line?: number;
12
+ column?: number;
13
+ /** True for the app's own code; this decides how errors group into issues. */
14
+ in_app: boolean;
15
+ }
16
+ /** Something that happened before an error: a click, a request, a log line. */
17
+ interface Breadcrumb {
18
+ /** ISO 8601; set to now when missing. */
19
+ timestamp?: string;
20
+ level?: Level;
21
+ /** e.g. `ui.click`, `fetch`, `xhr`, `navigation`, `console`. */
22
+ category?: string;
23
+ message: string;
24
+ }
25
+ /** An event as sent to Collector (protocol v1). */
26
+ interface CollectorEvent {
27
+ v: 1;
28
+ uuid: string;
29
+ timestamp: string;
30
+ platform: "javascript";
31
+ level: Level;
32
+ environment?: string;
33
+ release?: string;
34
+ exception?: {
35
+ type: string;
36
+ message?: string;
37
+ frames?: Frame[];
38
+ };
39
+ message?: string;
40
+ fingerprint?: string[];
41
+ request?: {
42
+ url: string;
43
+ headers: Record<string, string>;
44
+ };
45
+ user?: {
46
+ id: string;
47
+ };
48
+ tags?: Record<string, string>;
49
+ breadcrumbs?: Breadcrumb[];
50
+ sdk: {
51
+ name: string;
52
+ version: string;
53
+ };
54
+ }
55
+ /** Extra details for one captured event. They merge over what `setUser`/`setTag` set. */
56
+ interface CaptureContext {
57
+ level?: Level;
58
+ tags?: Record<string, string>;
59
+ /** Overrides how Collector groups this event into an issue. */
60
+ fingerprint?: string[];
61
+ user?: {
62
+ id: string | number;
63
+ };
64
+ }
65
+ type BreadcrumbKind = "console" | "dom" | "fetch" | "xhr" | "history";
66
+ interface CollectorOptions {
67
+ /** Your project's DSN, from its setup page in Collector. Without it, nothing is sent. */
68
+ dsn?: string;
69
+ /** e.g. `"production"`, `"staging"`. Issues are counted per environment. */
70
+ environment?: string;
71
+ /** Your app's version or git sha, e.g. `"web@1.4.2"`. */
72
+ release?: string;
73
+ /** Logs what the SDK does to the console, prefixed `[collector]`. Default `false`. */
74
+ debug?: boolean;
75
+ /** Set to `false` to turn the SDK off entirely. Default `true`. */
76
+ enabled?: boolean;
77
+ /**
78
+ * Last chance to edit or drop an event before it's sent. Return the event
79
+ * (changed or not) to send it, or `null` to drop it.
80
+ */
81
+ beforeSend?: (event: CollectorEvent) => CollectorEvent | null;
82
+ /**
83
+ * Errors to ignore: strings match anywhere in `"Type: message"`, regexps are
84
+ * tested against it. Added to the built-in list of well-known browser noise.
85
+ */
86
+ ignoreErrors?: (string | RegExp)[];
87
+ /**
88
+ * Which script URLs are your app's own code. When set, a frame is in-app only
89
+ * if its URL matches. Default: same origin as the page, except vendor chunks.
90
+ */
91
+ inAppUrls?: (string | RegExp)[];
92
+ /** Remove `?query` and `#hash` from URLs sent to Collector. Default `true`. */
93
+ stripQuery?: boolean;
94
+ /** Which breadcrumbs to record automatically. All on by default. */
95
+ breadcrumbs?: Partial<Record<BreadcrumbKind, boolean>>;
96
+ /** How many breadcrumbs to keep. Default `50`. */
97
+ maxBreadcrumbs?: number;
98
+ /**
99
+ * Tell Collector once a day that the app is running (its release and
100
+ * environment, nothing about the user), so it shows as set up before any
101
+ * error. Default `true`.
102
+ */
103
+ heartbeat?: boolean;
104
+ /** Report uncaught errors and unhandled promise rejections. Default: both on. */
105
+ autoCapture?: false | {
106
+ onerror?: boolean;
107
+ onunhandledrejection?: boolean;
108
+ };
109
+ }
110
+
111
+ /** The version of this SDK, as sent in every event's `sdk.version`. */
112
+ declare const SDK_VERSION: string;
113
+ /**
114
+ * Starts reporting errors to Collector. Call it once, as early as possible in
115
+ * your app's entry point:
116
+ *
117
+ * ```ts
118
+ * import * as Collector from "@chrom-ar/collector";
119
+ *
120
+ * Collector.init({ dsn: "https://clt_…@app.clt.chrom.ar" });
121
+ * ```
122
+ *
123
+ * Without a `dsn`, nothing is captured or sent. Calling it again replaces the
124
+ * options. Safe to import during server-side rendering: it does nothing there.
125
+ */
126
+ declare function init(options: CollectorOptions): void;
127
+ /**
128
+ * Reports an error you caught. Returns the event id, or `undefined` if it
129
+ * wasn't sent (no DSN, ignored, duplicate, dropped by `beforeSend`).
130
+ */
131
+ declare function captureException(error: unknown, context?: CaptureContext): string | undefined;
132
+ /** Reports something that isn't an error: `captureMessage("Payment slow", "warning")`. */
133
+ declare function captureMessage(message: string, context?: CaptureContext | Level): string | undefined;
134
+ /** Attaches your user's id to the following events. An id, not personal data. `null` clears it. */
135
+ declare function setUser(user: {
136
+ id: string | number;
137
+ } | null): void;
138
+ /** Adds a tag to the following events, e.g. `setTag("plan", "pro")`. */
139
+ declare function setTag(key: string, value: string): void;
140
+ /** Adds several tags to the following events. */
141
+ declare function setTags(tags: Record<string, string>): void;
142
+ /** Records something that happened, to be sent with the next events. */
143
+ declare function addBreadcrumb(crumb: Breadcrumb): void;
144
+ /** Waits until queued events are sent. Resolves `false` if `timeoutMs` (default 2000) passes first. */
145
+ declare function flush(timeoutMs?: number): Promise<boolean>;
146
+ /** Stops capturing and removes everything the SDK installed. */
147
+ declare function close(): void;
148
+
149
+ export { SDK_VERSION, addBreadcrumb, captureException, captureMessage, close, flush, init, setTag, setTags, setUser };
150
+ export type { Breadcrumb, BreadcrumbKind, CaptureContext, CollectorEvent, CollectorOptions, Frame, Level };