@sypnia/browser 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +16 -2
- package/dist/chunk-SLX7QGK4.js +487 -0
- package/dist/index.d.ts +275 -0
- package/dist/index.js +2290 -0
- package/dist/recorder.js +1199 -0
- package/dist/script/sdk-recorder.js +152 -0
- package/dist/script/sdk.js +3 -0
- package/package.json +34 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The events the browser SDK sends, as `spec/events.schema.json` (version 1)
|
|
3
|
+
* defines them. Field names are short on purpose: a browser sends thousands.
|
|
4
|
+
*/
|
|
5
|
+
declare const SCHEMA_VERSION: 1;
|
|
6
|
+
type DeviceClass = 'mobile' | 'tablet' | 'desktop';
|
|
7
|
+
type NavigationKind = 'load' | 'push' | 'replace' | 'traverse';
|
|
8
|
+
type VitalName = 'LCP' | 'INP' | 'CLS' | 'TTFB' | 'FCP';
|
|
9
|
+
type VitalRating = 'good' | 'needs-improvement' | 'poor';
|
|
10
|
+
type VitalKind = 'image' | 'text' | 'pointer' | 'keyboard';
|
|
11
|
+
type ErrorSource = 'window' | 'promise' | 'boundary' | 'manual';
|
|
12
|
+
/** 1: the default rules (typed input masked). 2: `maskAllText` (every text of the page masked too). */
|
|
13
|
+
type MaskPolicy = 1 | 2;
|
|
14
|
+
declare const CLICK_ROLES: readonly ["button", "link", "tab", "menuitem", "option", "checkbox", "radio", "switch", "select", "input", "textarea", "row", "cell", "heading", "image", "icon", "text", "other"];
|
|
15
|
+
type ClickRole = (typeof CLICK_ROLES)[number];
|
|
16
|
+
type ValidityReason = 'valueMissing' | 'typeMismatch' | 'patternMismatch' | 'tooShort' | 'tooLong' | 'rangeUnderflow' | 'rangeOverflow' | 'stepMismatch' | 'badInput' | 'customError';
|
|
17
|
+
interface PersonRef {
|
|
18
|
+
id: string;
|
|
19
|
+
}
|
|
20
|
+
interface AccountRef {
|
|
21
|
+
id: string;
|
|
22
|
+
}
|
|
23
|
+
/** Fields of every browser event. */
|
|
24
|
+
interface EventBase {
|
|
25
|
+
v: typeof SCHEMA_VERSION;
|
|
26
|
+
type: string;
|
|
27
|
+
ts: number;
|
|
28
|
+
sid: string;
|
|
29
|
+
did: string;
|
|
30
|
+
env: string;
|
|
31
|
+
ver: string | null;
|
|
32
|
+
person: PersonRef | null;
|
|
33
|
+
account: AccountRef | null;
|
|
34
|
+
url: string;
|
|
35
|
+
route: string;
|
|
36
|
+
dev: DeviceClass;
|
|
37
|
+
vw: number;
|
|
38
|
+
vh: number;
|
|
39
|
+
lang: string | null;
|
|
40
|
+
}
|
|
41
|
+
interface SessionStartEvent extends EventBase {
|
|
42
|
+
type: 'session_start';
|
|
43
|
+
ua: string;
|
|
44
|
+
ref: string | null;
|
|
45
|
+
sw: number;
|
|
46
|
+
sh: number;
|
|
47
|
+
tz: string;
|
|
48
|
+
}
|
|
49
|
+
interface IdentifyEvent extends Omit<EventBase, 'person' | 'account'> {
|
|
50
|
+
type: 'identify';
|
|
51
|
+
person: {
|
|
52
|
+
id: string;
|
|
53
|
+
name: string | null;
|
|
54
|
+
email: string | null;
|
|
55
|
+
};
|
|
56
|
+
account: {
|
|
57
|
+
id: string;
|
|
58
|
+
name: string | null;
|
|
59
|
+
} | null;
|
|
60
|
+
}
|
|
61
|
+
interface PageViewEvent extends EventBase {
|
|
62
|
+
type: 'page_view';
|
|
63
|
+
nav: NavigationKind;
|
|
64
|
+
from: string | null;
|
|
65
|
+
}
|
|
66
|
+
interface PageLeaveEvent extends EventBase {
|
|
67
|
+
type: 'page_leave';
|
|
68
|
+
dur: number;
|
|
69
|
+
scroll: number;
|
|
70
|
+
}
|
|
71
|
+
/** What was clicked, in words and in position. Never the value of a field. */
|
|
72
|
+
interface ClickFields {
|
|
73
|
+
sel: string;
|
|
74
|
+
tag: string;
|
|
75
|
+
txt: string | null;
|
|
76
|
+
crole?: ClickRole;
|
|
77
|
+
ctx: string | null;
|
|
78
|
+
href: string | null;
|
|
79
|
+
x: number;
|
|
80
|
+
y: number;
|
|
81
|
+
rx: number;
|
|
82
|
+
ry: number;
|
|
83
|
+
ex: number;
|
|
84
|
+
ey: number;
|
|
85
|
+
ew: number;
|
|
86
|
+
eh: number;
|
|
87
|
+
}
|
|
88
|
+
interface ClickEvent extends EventBase, ClickFields {
|
|
89
|
+
type: 'click';
|
|
90
|
+
}
|
|
91
|
+
interface RageClickEvent extends EventBase, ClickFields {
|
|
92
|
+
type: 'rage_click';
|
|
93
|
+
/** How many clicks the burst had. */
|
|
94
|
+
n: number;
|
|
95
|
+
}
|
|
96
|
+
interface DeadClickEvent extends EventBase, ClickFields {
|
|
97
|
+
type: 'dead_click';
|
|
98
|
+
/** How long the SDK waited, always 1,000. */
|
|
99
|
+
n: 1000;
|
|
100
|
+
}
|
|
101
|
+
interface VitalEvent extends EventBase {
|
|
102
|
+
type: 'vital';
|
|
103
|
+
name: VitalName;
|
|
104
|
+
value: number;
|
|
105
|
+
rating: VitalRating;
|
|
106
|
+
sel?: string;
|
|
107
|
+
kind?: VitalKind;
|
|
108
|
+
}
|
|
109
|
+
interface RequestEvent extends EventBase {
|
|
110
|
+
type: 'request';
|
|
111
|
+
method: string;
|
|
112
|
+
host: string | null;
|
|
113
|
+
path: string;
|
|
114
|
+
status: number;
|
|
115
|
+
dur: number;
|
|
116
|
+
tid: string;
|
|
117
|
+
span: string;
|
|
118
|
+
code?: string;
|
|
119
|
+
msg?: string;
|
|
120
|
+
}
|
|
121
|
+
interface ErrorEvent extends EventBase {
|
|
122
|
+
type: 'error';
|
|
123
|
+
name: string;
|
|
124
|
+
msg: string;
|
|
125
|
+
stack: string | null;
|
|
126
|
+
digest: string | null;
|
|
127
|
+
src: ErrorSource;
|
|
128
|
+
fp: string;
|
|
129
|
+
}
|
|
130
|
+
type CustomProps = Record<string, string | number | boolean | null>;
|
|
131
|
+
interface CustomEvent extends EventBase {
|
|
132
|
+
type: 'custom';
|
|
133
|
+
name: string;
|
|
134
|
+
props?: CustomProps;
|
|
135
|
+
}
|
|
136
|
+
interface FormInvalidEvent extends EventBase {
|
|
137
|
+
type: 'form_invalid';
|
|
138
|
+
field: string | null;
|
|
139
|
+
ctx: string | null;
|
|
140
|
+
reason: ValidityReason | null;
|
|
141
|
+
sel: string;
|
|
142
|
+
}
|
|
143
|
+
interface ReplayChunkEvent extends EventBase {
|
|
144
|
+
type: 'replay_chunk';
|
|
145
|
+
seq: number;
|
|
146
|
+
bytes: number;
|
|
147
|
+
mask: MaskPolicy;
|
|
148
|
+
full?: boolean;
|
|
149
|
+
}
|
|
150
|
+
type ReplayGapReason = 'rejected' | 'failed' | 'overflow' | 'limit';
|
|
151
|
+
interface ReplayGapEvent extends EventBase {
|
|
152
|
+
type: 'replay_gap';
|
|
153
|
+
seq: number;
|
|
154
|
+
reason: ReplayGapReason;
|
|
155
|
+
mask: MaskPolicy;
|
|
156
|
+
}
|
|
157
|
+
type SnapshotSkipReason = 'too_big' | 'upload_failed' | 'limit';
|
|
158
|
+
interface PageSnapshotEvent extends EventBase {
|
|
159
|
+
type: 'page_snapshot';
|
|
160
|
+
bytes: number;
|
|
161
|
+
mask: MaskPolicy;
|
|
162
|
+
skipped?: SnapshotSkipReason;
|
|
163
|
+
}
|
|
164
|
+
type SypniaEvent = SessionStartEvent | IdentifyEvent | PageViewEvent | PageLeaveEvent | ClickEvent | RageClickEvent | DeadClickEvent | VitalEvent | RequestEvent | ErrorEvent | CustomEvent | FormInvalidEvent | ReplayChunkEvent | ReplayGapEvent | PageSnapshotEvent;
|
|
165
|
+
|
|
166
|
+
/** A route or address in a list: a string matches the start (routes: the route and everything under it). */
|
|
167
|
+
type Pattern = string | RegExp;
|
|
168
|
+
/** What `init` takes (docs: sdks/browser#initoptions). */
|
|
169
|
+
interface InitOptions {
|
|
170
|
+
/** The project's ingest key, `spk_…`. Without it the SDK does nothing and prints one warning. */
|
|
171
|
+
project: string;
|
|
172
|
+
/** Where to send: a self-hosted engine's base URL, or a path on your own domain proxied to it. */
|
|
173
|
+
endpoint?: string;
|
|
174
|
+
/** 1 to 40 characters. `production` by default. */
|
|
175
|
+
environment?: string;
|
|
176
|
+
/** Up to 40 characters: the short git commit. */
|
|
177
|
+
release?: string;
|
|
178
|
+
/** `false` turns the SDK into a no-op. */
|
|
179
|
+
enabled?: boolean;
|
|
180
|
+
/** Prints every event, and every decision not to send one, to the console. */
|
|
181
|
+
debug?: boolean;
|
|
182
|
+
/** Paths where the SDK captures nothing at all. */
|
|
183
|
+
ignoreRoutes?: Pattern[];
|
|
184
|
+
/** When set, the only paths where the SDK captures anything (`ignoreRoutes` still applies inside them). */
|
|
185
|
+
allowRoutes?: Pattern[];
|
|
186
|
+
/** Your own way to turn a path into a route. */
|
|
187
|
+
routeFor?: (pathname: string) => string;
|
|
188
|
+
/** Treats the hash as the path, for apps that route with `#/checkout`. */
|
|
189
|
+
hashRouting?: boolean;
|
|
190
|
+
capture?: CaptureOptions;
|
|
191
|
+
/** Addresses outside your origin whose calls are recorded and receive the trace headers. */
|
|
192
|
+
traceTargets?: Pattern[];
|
|
193
|
+
/** Addresses outside your origin whose calls are recorded without any header. */
|
|
194
|
+
recordTargets?: Pattern[];
|
|
195
|
+
/** Calls that are never recorded. */
|
|
196
|
+
ignoreRequests?: Pattern[];
|
|
197
|
+
/** Errors whose message matches are not sent. */
|
|
198
|
+
ignoreErrors?: Pattern[];
|
|
199
|
+
/** Script addresses that are your code although they are served from another origin. */
|
|
200
|
+
appFrames?: Pattern[];
|
|
201
|
+
/** Masks every text in replays and snapshots, and sends no click label, context or field name. */
|
|
202
|
+
maskAllText?: boolean;
|
|
203
|
+
/** Elements to mask, on top of `[data-sypnia-mask]`. */
|
|
204
|
+
maskSelector?: string;
|
|
205
|
+
/** Elements to leave out of replays, on top of `[data-sypnia-block]`, frames (`iframe`, `frame`, `object`, `embed`) and `video`. */
|
|
206
|
+
blockSelector?: string;
|
|
207
|
+
/** `false` never loads the recorder. */
|
|
208
|
+
replay?: false | {
|
|
209
|
+
blockedRoutes?: Pattern[];
|
|
210
|
+
};
|
|
211
|
+
/** Page snapshots for click maps. */
|
|
212
|
+
snapshots?: boolean;
|
|
213
|
+
/** Called with each event before it is queued: return it, changed or not, or `null` to drop it. */
|
|
214
|
+
beforeSend?: (event: SypniaEvent) => SypniaEvent | null;
|
|
215
|
+
}
|
|
216
|
+
interface CaptureOptions {
|
|
217
|
+
errors?: boolean;
|
|
218
|
+
clicks?: boolean;
|
|
219
|
+
requests?: boolean;
|
|
220
|
+
requestFailureDetail?: boolean;
|
|
221
|
+
vitals?: boolean;
|
|
222
|
+
forms?: boolean;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* The public functions (docs: sdks/browser#the-functions-you-call). One SDK
|
|
227
|
+
* per document: the runtime lives on `window`, so every bundle of a page
|
|
228
|
+
* shares it. None of these functions throws, and all of them do nothing on
|
|
229
|
+
* the server, before `init`, with `enabled: false` or after `optOut()`.
|
|
230
|
+
*/
|
|
231
|
+
|
|
232
|
+
type IdentifyInput = {
|
|
233
|
+
person: {
|
|
234
|
+
id: string | number;
|
|
235
|
+
name?: string | null;
|
|
236
|
+
email?: string | null;
|
|
237
|
+
};
|
|
238
|
+
account?: {
|
|
239
|
+
id: string | number;
|
|
240
|
+
name?: string | null;
|
|
241
|
+
} | null;
|
|
242
|
+
} | null;
|
|
243
|
+
/** Says who the person is, and their account; `identify(null)` when they sign out. */
|
|
244
|
+
declare function identify(who: IdentifyInput): void;
|
|
245
|
+
/** Sends a custom event: something that matters in your app and that Sypnia cannot see by itself. */
|
|
246
|
+
declare function track(name: string, props?: CustomProps): void;
|
|
247
|
+
/** Reports an error your code caught. */
|
|
248
|
+
declare function reportError(error: unknown, info?: {
|
|
249
|
+
source?: 'manual' | 'boundary';
|
|
250
|
+
digest?: string;
|
|
251
|
+
}): void;
|
|
252
|
+
/** Sends what is waiting now. */
|
|
253
|
+
declare function flush(): Promise<void>;
|
|
254
|
+
/** The current session's id, 32 hex characters, or null. */
|
|
255
|
+
declare function getSessionId(): string | null;
|
|
256
|
+
/** Stops everything for this browser and remembers it (`localStorage`, `sypnia:off`). */
|
|
257
|
+
declare function optOut(): void;
|
|
258
|
+
/** Undoes `optOut`. */
|
|
259
|
+
declare function optIn(): void;
|
|
260
|
+
/**
|
|
261
|
+
* For framework integrations: a navigation was announced before the address
|
|
262
|
+
* changed (Next.js' `onRouterTransitionStart`). Apps do not call it.
|
|
263
|
+
*/
|
|
264
|
+
declare function notifyNavigation(url: string, kind: 'push' | 'replace' | 'traverse'): void;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* `@sypnia/browser`: errors, sessions, replay, page performance, failing API
|
|
268
|
+
* calls, and rage and dead clicks, with nothing a person types ever leaving
|
|
269
|
+
* their browser (docs: sdks/browser).
|
|
270
|
+
*/
|
|
271
|
+
|
|
272
|
+
/** Starts the SDK. Call it once, as early as your app starts. A second call does nothing. */
|
|
273
|
+
declare function init(options: InitOptions): void;
|
|
274
|
+
|
|
275
|
+
export { type CaptureOptions, type CustomProps, type InitOptions, type Pattern, type SypniaEvent, flush, getSessionId, identify, init, notifyNavigation, optIn, optOut, reportError, track };
|