@vitrinka/web 0.5.3 → 0.7.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.
Files changed (84) hide show
  1. package/CHANGELOG.md +113 -0
  2. package/README.md +145 -20
  3. package/build/hud.iife.js +150 -28
  4. package/build/index.d.ts +1 -0
  5. package/build/protocol/index.d.ts +10 -0
  6. package/build/recorder/RecorderProvider.js +5 -18
  7. package/build/recorder/api.d.ts +20 -0
  8. package/build/recorder/api.js +21 -9
  9. package/build/recorder/capture/console.d.ts +6 -1
  10. package/build/recorder/capture/console.js +28 -5
  11. package/build/recorder/capture/net.d.ts +10 -1
  12. package/build/recorder/capture/net.js +14 -1
  13. package/build/recorder/capture/redact.d.ts +1 -0
  14. package/build/recorder/capture/redact.js +6 -1
  15. package/build/recorder/capture/rrweb-lane.d.ts +19 -0
  16. package/build/recorder/capture/rrweb-lane.js +109 -0
  17. package/build/recorder/capture/rrweb.d.ts +2 -9
  18. package/build/recorder/capture/rrweb.js +11 -86
  19. package/build/recorder/config.d.ts +3 -1
  20. package/build/recorder/config.js +15 -2
  21. package/build/recorder/flight.d.ts +141 -22
  22. package/build/recorder/flight.js +312 -27
  23. package/build/recorder/hud/Hud.js +206 -31
  24. package/build/recorder/hud/NotesSheet.d.ts +24 -0
  25. package/build/recorder/hud/NotesSheet.js +147 -0
  26. package/build/recorder/hud/RecorderPill.d.ts +34 -12
  27. package/build/recorder/hud/RecorderPill.js +52 -14
  28. package/build/recorder/hud/Sheet.d.ts +18 -15
  29. package/build/recorder/hud/Sheet.js +13 -13
  30. package/build/recorder/hud/controller.d.ts +81 -4
  31. package/build/recorder/hud/drop.d.ts +26 -0
  32. package/build/recorder/hud/drop.js +35 -0
  33. package/build/recorder/hud/host-style.d.ts +14 -0
  34. package/build/recorder/hud/host-style.js +15 -0
  35. package/build/recorder/hud/host.js +1 -1
  36. package/build/recorder/hud/icons.d.ts +6 -0
  37. package/build/recorder/hud/icons.js +12 -0
  38. package/build/recorder/hud/notes-rows.d.ts +39 -0
  39. package/build/recorder/hud/notes-rows.js +49 -0
  40. package/build/recorder/hud/resize.d.ts +6 -3
  41. package/build/recorder/hud/resize.js +8 -4
  42. package/build/recorder/hud/styles.d.ts +2 -30
  43. package/build/recorder/hud/styles.js +63 -31
  44. package/build/recorder/page-controller.js +13 -7
  45. package/build/recorder/queue.d.ts +22 -1
  46. package/build/recorder/queue.js +84 -5
  47. package/build/recorder/recents.d.ts +20 -4
  48. package/build/recorder/recents.js +41 -6
  49. package/build/recorder/session.d.ts +25 -6
  50. package/build/recorder/session.js +50 -8
  51. package/build/recorder/state.d.ts +18 -1
  52. package/build/recorder/state.js +40 -1
  53. package/build/recorder/storage/capture.d.ts +44 -0
  54. package/build/recorder/storage/capture.js +136 -0
  55. package/build/recorder/version.d.ts +2 -2
  56. package/build/recorder/version.js +1 -1
  57. package/build/report/bundle.d.ts +4 -0
  58. package/build/report/bundle.js +30 -0
  59. package/build/report/element.d.ts +86 -0
  60. package/build/report/element.js +146 -0
  61. package/build/report/engine.d.ts +144 -0
  62. package/build/report/engine.js +402 -0
  63. package/build/report/i18n.d.ts +78 -0
  64. package/build/report/i18n.js +151 -0
  65. package/build/report/identity.d.ts +26 -0
  66. package/build/report/identity.js +36 -0
  67. package/build/report/index.d.ts +12 -0
  68. package/build/report/index.js +15 -0
  69. package/build/report/keybind.d.ts +29 -0
  70. package/build/report/keybind.js +99 -0
  71. package/build/report/markers.d.ts +77 -0
  72. package/build/report/markers.js +162 -0
  73. package/build/report/profile.d.ts +62 -0
  74. package/build/report/profile.js +115 -0
  75. package/build/report/recorder-face.d.ts +2 -0
  76. package/build/report/recorder-face.js +20 -0
  77. package/build/report/styles.d.ts +7 -0
  78. package/build/report/styles.js +226 -0
  79. package/build/report/widget.d.ts +109 -0
  80. package/build/report/widget.js +907 -0
  81. package/build/report/wire.d.ts +68 -0
  82. package/build/report/wire.js +96 -0
  83. package/build/report-widget.mjs +229 -0
  84. package/package.json +11 -4
@@ -0,0 +1,402 @@
1
+ import { api } from '../recorder/api';
2
+ import { patchConsole, unpatchConsole } from '../recorder/capture/console';
3
+ import { patchNetwork, unpatchNetwork } from '../recorder/capture/net';
4
+ import { setCaptureSanitizer, setRedactionPolicy } from '../recorder/capture/redact';
5
+ import { checkoutRRWeb, runningRecord, startRecordWith, stopRRWeb } from '../recorder/capture/rrweb-lane';
6
+ import { addOwnBase } from '../recorder/config';
7
+ import { clearFlight, clipHasSnapshot, FLIGHT_MAX_LANE_EVENTS, flightWrites, persistFlightNow, startFlightBuffer, stopFlightBuffer, takeFlightClip, } from '../recorder/flight';
8
+ import { listen } from '../recorder/hud/listen';
9
+ import { EVENTS_PER_POST, splitRRWebEvents, utf8Bytes } from '../recorder/queue';
10
+ import { browserTabId, claimCapture, currentRoute, releaseCapture, setTabIdentity } from '../recorder/state';
11
+ import { deleteCaptureStore, openCaptureStore } from '../recorder/storage/capture';
12
+ import { applyHides, hiddenNodeIds } from './markers';
13
+ import { lanesOf, legacyProfile, maskingOf, maskingPolicy, narrowProfile, parseProfile, UNMASK_SELECTOR, } from './profile';
14
+ export { EVENTS_PER_POST };
15
+ /** The report wire's chunk cap is 4 MiB; pack a little under it. */
16
+ const CHUNK_PACK_BYTES = 3.5 * 1024 * 1024;
17
+ const CHUNK_HARD_BYTES = 4 * 1024 * 1024 - 64;
18
+ const MAX_CONSOLE_TEXT = 2000;
19
+ const MAX_ENTRIES = 500;
20
+ /** A checkout every minute at most: a short window checks out as often as it is long. */
21
+ const MAX_CHECKOUT_MS = 60_000;
22
+ /** Token-shaped runs in a request path (reset links, signed URLs) are scrubbed: the server keeps paths as sent. */
23
+ const TOKENY = /[A-Za-z0-9_-]{20,}/g;
24
+ function str(v, fallback = '') {
25
+ return typeof v === 'string' ? v : fallback;
26
+ }
27
+ /** A request URL (already through the redaction engine) as the wire's path: pathname only, token runs scrubbed. */
28
+ export function reportPath(url) {
29
+ const raw = str(url);
30
+ let path;
31
+ try {
32
+ path = new URL(raw, globalThis.location?.href ?? 'http://localhost').pathname;
33
+ }
34
+ catch {
35
+ path = raw.split(/[?#]/)[0] ?? '';
36
+ }
37
+ return path.replace(TOKENY, '•••').slice(0, 300);
38
+ }
39
+ /** rrweb's `EventType.Meta`, the head of every window (`@rrweb/types` is type-only here). */
40
+ const RRWEB_META = 4;
41
+ /**
42
+ * Whole windows only: rrweb's stream is stateful, so a window holding an
43
+ * event over the wire cap (a huge full snapshot) goes entirely — its
44
+ * incrementals are worthless without it — and the replay says truncated.
45
+ */
46
+ export function wholeWindows(events, hardBytes) {
47
+ const out = [];
48
+ let dropped = false;
49
+ let window = [];
50
+ let tooBig = false;
51
+ const close = () => {
52
+ if (tooBig)
53
+ dropped = true;
54
+ else
55
+ out.push(...window);
56
+ window = [];
57
+ tooBig = false;
58
+ };
59
+ for (const ev of events) {
60
+ if (ev.type === RRWEB_META && window.length)
61
+ close();
62
+ if (!tooBig && utf8Bytes(JSON.stringify(ev)) + 1 > hardBytes)
63
+ tooBig = true;
64
+ window.push(ev);
65
+ }
66
+ close();
67
+ return { events: out, dropped };
68
+ }
69
+ /** What the flight buffer keeps of each lane event under the profile's classes: the wire's shapes only. */
70
+ function laneKeeper(lanes) {
71
+ return (kind, payload) => {
72
+ if (kind === 'console') {
73
+ const level = str(payload?.level, 'error');
74
+ if (level === 'error' ? !(lanes.errors || lanes.console) : !lanes.console)
75
+ return null;
76
+ return { level, text: str(payload?.text).slice(0, MAX_CONSOLE_TEXT) };
77
+ }
78
+ if (kind === 'net') {
79
+ const status = typeof payload?.status === 'number' ? payload.status : 0;
80
+ const failed = status === 0 || status >= 400 || payload?.error !== undefined;
81
+ if (!(lanes.network || (lanes.errors && failed)))
82
+ return null;
83
+ return {
84
+ method: str(payload?.method, 'GET').toUpperCase(),
85
+ path: reportPath(payload?.url),
86
+ status,
87
+ ms: typeof payload?.ms === 'number' ? Math.max(0, Math.round(payload.ms)) : 0,
88
+ };
89
+ }
90
+ return null;
91
+ };
92
+ }
93
+ async function fetchConfig(target) {
94
+ try {
95
+ const res = await api('GET', '/api/v1/report-config', undefined, { target });
96
+ const flight = typeof res.flightRecorder === 'boolean' ? res.flightRecorder : undefined;
97
+ return {
98
+ project: str(res.project),
99
+ profile: res.captureProfile == null ? legacyProfile(flight) : parseProfile(res.captureProfile, flight),
100
+ masking: maskingOf(res.profile),
101
+ reachable: true,
102
+ };
103
+ }
104
+ catch (e) {
105
+ console.warn('vitrinka: report config unavailable — capturing the last minute, strictly masked', e);
106
+ return { project: '', profile: legacyProfile(), masking: 'strict', reachable: false };
107
+ }
108
+ }
109
+ /** rrweb's mirror off the running recorder, when it carries one (the vendor build may not). */
110
+ function mirrorOf(record) {
111
+ const mirror = record?.mirror;
112
+ if (typeof mirror !== 'object' || mirror === null)
113
+ return null;
114
+ const getId = mirror.getId;
115
+ return typeof getId === 'function' ? { getId: (n) => Number(getId.call(mirror, n)) } : null;
116
+ }
117
+ export class CaptureEngine {
118
+ opts;
119
+ ready;
120
+ store = null;
121
+ stopped = false;
122
+ /** The release token of this engine's claim on the page's capture runtime. */
123
+ claim = null;
124
+ /** The config `ready` resolved with — kept true to what the engine does now. */
125
+ config = null;
126
+ listeners = new Set();
127
+ /** …and runs it now: false before the claim, without it, and after it yielded. */
128
+ capturing = false;
129
+ /** The engine's own lifetime (its base registration). */
130
+ offs = [];
131
+ /** The capture runtime's teardown, run when it yields to a recorder or stops. */
132
+ capture = [];
133
+ constructor(opts) {
134
+ this.opts = opts;
135
+ this.ready = this.start();
136
+ }
137
+ async start() {
138
+ const { opts } = this;
139
+ // Every call is targeted (ApiTarget): the recorder's configuration is
140
+ // never written. Its lanes skip this base's traffic all the same.
141
+ this.offs.push(addOwnBase(opts.base));
142
+ const fetched = await fetchConfig({ url: opts.base, key: opts.key });
143
+ const profile = narrowProfile(fetched.profile, opts.capture);
144
+ const lanes = lanesOf(profile.classes);
145
+ const config = {
146
+ project: fetched.project,
147
+ profile,
148
+ lanes,
149
+ masking: fetched.masking,
150
+ reachable: fetched.reachable,
151
+ capturing: false,
152
+ };
153
+ if (this.stopped)
154
+ return config;
155
+ // The page-wide runtime (lanes, buffer, rrweb, rules) is the recorder's
156
+ // whenever one is mounted; this widget then reports without a capture.
157
+ this.config = config;
158
+ this.claim = claimCapture('report', () => this.standDown());
159
+ if (!this.claim) {
160
+ console.warn('vitrinka: the recorder runs this page’s capture — Report a problem sends without one');
161
+ return config;
162
+ }
163
+ this.capturing = true;
164
+ config.capturing = true;
165
+ setTabIdentity(browserTabId(), globalThis.location?.host ?? '');
166
+ currentRoute.pathname = globalThis.location?.pathname ?? '/';
167
+ setRedactionPolicy(maskingPolicy(config.masking));
168
+ setCaptureSanitizer(opts.sanitizeUrl);
169
+ this.capture.push(() => setCaptureSanitizer(null));
170
+ const windowMs = profile.windowSec * 1000;
171
+ // What stored windows were captured FOR: another project, or a laxer
172
+ // masking or wider classes than now, never comes back (sweep drops it).
173
+ const scope = [opts.base, fetched.project, config.masking, profile.classes.join(',')].join('|');
174
+ let prior = [];
175
+ let priorLanes = [];
176
+ if (profile.storage === 'browser') {
177
+ try {
178
+ this.store = await openCaptureStore();
179
+ const kept = await this.store.sweep(Date.now(), windowMs, currentRoute.tabId, scope);
180
+ // Replay windows and lane spans both: the buffer expires each in its turn.
181
+ prior = kept;
182
+ // The console and network entries of earlier loads, replay or not.
183
+ const store = this.store;
184
+ const spans = await Promise.all(kept.filter((w) => w.kind === 'lanes').map((w) => store.read(w.id)));
185
+ priorLanes = spans.flatMap((s) => s.lanes).sort((a, b) => Date.parse(a.ts) - Date.parse(b.ts));
186
+ }
187
+ catch (e) {
188
+ console.warn('vitrinka: browser capture storage unavailable — keeping the capture in memory', e);
189
+ this.store = null;
190
+ prior = [];
191
+ priorLanes = [];
192
+ }
193
+ }
194
+ else {
195
+ // Memory means memory: nothing a browser profile once stored stays behind.
196
+ deleteCaptureStore();
197
+ }
198
+ if (!this.capturing) {
199
+ this.store?.close();
200
+ this.store = null;
201
+ return config;
202
+ }
203
+ startFlightBuffer({
204
+ windowMs,
205
+ checkoutMs: Math.min(MAX_CHECKOUT_MS, windowMs),
206
+ maxBytes: profile.maxBytes,
207
+ maxEvents: Math.max(20_000, Math.round(profile.maxBytes / 200)),
208
+ maxLaneEvents: FLIGHT_MAX_LANE_EVENTS,
209
+ keepLane: laneKeeper(lanes),
210
+ store: this.store,
211
+ scope,
212
+ prior,
213
+ priorLanes,
214
+ });
215
+ this.capture.push(stopFlightBuffer);
216
+ if (this.store && typeof window !== 'undefined') {
217
+ const persist = () => persistFlightNow();
218
+ this.capture.push(listen(window, 'pagehide', persist), listen(document, 'visibilitychange', persist));
219
+ }
220
+ // Each acquisition names its own settings, so nothing of the report face
221
+ // outlives its release into the next face that patches these lanes.
222
+ if (lanes.errors || lanes.console) {
223
+ patchConsole({ levels: lanes.console ? ['warn', 'info', 'log'] : [] });
224
+ this.capture.push(unpatchConsole);
225
+ }
226
+ if (lanes.errors || lanes.network) {
227
+ patchNetwork({ detail: 'meta' });
228
+ this.capture.push(unpatchNetwork);
229
+ }
230
+ if (lanes.replay) {
231
+ const record = await opts.loadRecord(opts.base).catch((e) => {
232
+ // A report without a replay is still a report: never block the card.
233
+ console.warn('vitrinka: the page recorder did not load — reports go without a replay', e);
234
+ return null;
235
+ });
236
+ if (record && this.capturing) {
237
+ startRecordWith(record, 'flight', { unmaskSelector: UNMASK_SELECTOR });
238
+ this.capture.push(stopRRWeb);
239
+ }
240
+ }
241
+ return config;
242
+ }
243
+ /** Hear the engine's state change (it stopped capturing): the widget repaints. */
244
+ onChange(fn) {
245
+ this.listeners.add(fn);
246
+ return () => this.listeners.delete(fn);
247
+ }
248
+ /** The recorder mounted: hand it the runtime — this widget goes on reporting without a capture. */
249
+ standDown() {
250
+ if (!this.capturing)
251
+ return;
252
+ this.capturing = false;
253
+ if (this.config)
254
+ this.config.capturing = false;
255
+ for (const off of this.capture.splice(0).reverse())
256
+ off();
257
+ const store = this.store;
258
+ this.store = null;
259
+ if (store)
260
+ void flightWrites().then(() => store.close());
261
+ for (const fn of this.listeners)
262
+ fn();
263
+ }
264
+ /** Freeze the capture now (the card opened); the buffer rolls on. */
265
+ freeze() {
266
+ // Not this widget's runtime (the recorder runs it): nothing to take.
267
+ if (!this.capturing)
268
+ return { clip: null, stored: Promise.resolve(new Map()) };
269
+ currentRoute.pathname = globalThis.location?.pathname ?? currentRoute.pathname;
270
+ let clip = takeFlightClip();
271
+ // No screen of this page yet (the recorder only just started, a window
272
+ // went over the cap): take one now so the report shows the current view.
273
+ if (clip && runningRecord() && !clipHasSnapshot(clip)) {
274
+ checkoutRRWeb();
275
+ clip = takeFlightClip();
276
+ }
277
+ // Earlier loads' windows are read NOW: the buffer keeps rolling while the
278
+ // reporter writes and may expire them before Send.
279
+ const store = this.store;
280
+ const ids = clip?.windows.filter((w) => w.stored).map((w) => w.id) ?? [];
281
+ const stored = store && ids.length ? Promise.all(ids.map(async (id) => [id, await store.read(id)])).then((rows) => new Map(rows)) : Promise.resolve(new Map());
282
+ stored.catch(() => undefined); // build reports a failed read
283
+ return { clip, stored };
284
+ }
285
+ /**
286
+ * The rrweb ids of the page nodes under a hide right now — taken when the
287
+ * hide is drawn (the page sits frozen under the marking layer); null when
288
+ * the running recorder has no mirror to say (then a hide withholds the replay).
289
+ */
290
+ hiddenIdsAt(rect) {
291
+ if (!this.capturing)
292
+ return null;
293
+ const mirror = mirrorOf(runningRecord());
294
+ return mirror ? hiddenNodeIds([rect], mirror) : null;
295
+ }
296
+ /**
297
+ * What one report sends: the frozen windows (stored ones read back), the
298
+ * hides applied, split under the chunk cap. `markedIds` are the nodes each
299
+ * hide covered when it was drawn; the nodes under it at send join them. A
300
+ * hide whose nodes cannot be named (no mirror) withholds the replay — fail
301
+ * closed, never a box over text that still rides along.
302
+ */
303
+ async build(frozen, markers, markedIds = new Set()) {
304
+ const hides = markers.filter((m) => m.shape === 'hide').map((m) => m.rect);
305
+ const mirror = mirrorOf(runningRecord());
306
+ const withheld = hides.length > 0 && !mirror;
307
+ if (withheld)
308
+ console.warn('vitrinka: this page recorder cannot name what a hide covers — the report goes without its replay');
309
+ const hiddenIds = new Set(markedIds);
310
+ if (hides.length && mirror)
311
+ for (const id of hiddenNodeIds(hides, mirror))
312
+ hiddenIds.add(id);
313
+ const events = [];
314
+ let truncated = frozen.clip?.truncated ?? false;
315
+ const pinned = await frozen.stored.catch((e) => {
316
+ console.warn('vitrinka: the stored part of the capture could not be read — the replay starts later', e);
317
+ return null;
318
+ });
319
+ for (const w of frozen.clip?.windows ?? []) {
320
+ if (!w.stored) {
321
+ events.push(...w.events);
322
+ continue;
323
+ }
324
+ const read = pinned?.get(w.id);
325
+ // Gone before the card opened, or unreadable: say the replay is short.
326
+ if (!read?.events.length)
327
+ truncated = true;
328
+ else
329
+ events.push(...read.events);
330
+ }
331
+ // The console and network entries, earlier loads' included (priorLanes).
332
+ const lanes = frozen.clip?.lanes ?? [];
333
+ const whole = withheld ? { events: [], dropped: false } : wholeWindows(applyHides(events, hides, hiddenIds), CHUNK_HARD_BYTES);
334
+ if (whole.dropped)
335
+ truncated = true;
336
+ const { parts, dropped } = splitRRWebEvents(whole.events, CHUNK_PACK_BYTES, CHUNK_HARD_BYTES);
337
+ const chunks = [];
338
+ let at = 0;
339
+ for (const p of parts) {
340
+ at += p.count;
341
+ const last = whole.events[at - 1]?.timestamp ?? Date.now();
342
+ chunks.push({ seq: chunks.length + 1, ts: new Date(last).toISOString(), count: p.count, body: p.body });
343
+ }
344
+ const consoleEntries = lanes
345
+ .filter((e) => e.kind === 'console')
346
+ .slice(-MAX_ENTRIES)
347
+ .map((e) => ({ level: str(e.payload?.level, 'error'), ts: e.ts, text: str(e.payload?.text) }));
348
+ const network = lanes
349
+ .filter((e) => e.kind === 'net')
350
+ .slice(-MAX_ENTRIES)
351
+ .map((e) => ({
352
+ method: str(e.payload?.method, 'GET'),
353
+ path: str(e.payload?.path),
354
+ status: typeof e.payload?.status === 'number' ? e.payload.status : 0,
355
+ ms: typeof e.payload?.ms === 'number' ? e.payload.ms : 0,
356
+ }));
357
+ return { chunks, truncated: truncated || dropped.length > 0, console: consoleEntries, network };
358
+ }
359
+ /** A report went out: forget what it carried, in memory and in the store. */
360
+ clear() {
361
+ if (this.capturing)
362
+ clearFlight();
363
+ }
364
+ stop() {
365
+ this.stopped = true;
366
+ this.listeners.clear();
367
+ this.standDown();
368
+ releaseCapture(this.claim);
369
+ this.claim = null;
370
+ for (const off of this.offs.splice(0).reverse())
371
+ off();
372
+ }
373
+ }
374
+ let shared = null;
375
+ /** The page's one engine (started by the first widget); null when another base/key already owns it. */
376
+ export function acquireEngine(opts) {
377
+ if (shared) {
378
+ const owner = shared.engine.opts;
379
+ // Sharing means one capture: only for a widget asking exactly what the
380
+ // first one did — never another target, narrowing or URL sanitizer.
381
+ const same = owner.base === opts.base &&
382
+ owner.key === opts.key &&
383
+ owner.sanitizeUrl === opts.sanitizeUrl &&
384
+ JSON.stringify(owner.capture ?? {}) === JSON.stringify(opts.capture ?? {});
385
+ if (!same) {
386
+ console.warn('vitrinka: one capture engine per page — this widget reports without a capture (another widget’s key, base, capture or sanitizeUrl owns it)');
387
+ return null;
388
+ }
389
+ shared.refs++;
390
+ return shared.engine;
391
+ }
392
+ shared = { engine: new CaptureEngine(opts), refs: 1 };
393
+ return shared.engine;
394
+ }
395
+ export function releaseEngine(engine) {
396
+ if (!engine || !shared || shared.engine !== engine)
397
+ return;
398
+ if (--shared.refs > 0)
399
+ return;
400
+ shared = null;
401
+ engine.stop();
402
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Every string Report a problem shows, one catalog per locale (cs, en). The
3
+ * browser's language picks one by default; the host's `locale` option,
4
+ * `locale` attribute and `setLocale()` switch it live — the widget repaints
5
+ * its text in place, so a draft and its marks survive the switch.
6
+ *
7
+ * Marking is taught as "click, hold and move" — never "drag" (D21): a
8
+ * first-time reporter does not know the word.
9
+ */
10
+ export type Locale = 'cs' | 'en';
11
+ export interface Strings {
12
+ button: string;
13
+ title: string;
14
+ close: string;
15
+ settings: string;
16
+ prompt: string;
17
+ placeholder: string;
18
+ /** "The last 5 minutes are attached" for a window of `sec` seconds. */
19
+ attached: (sec: number) => string;
20
+ included: string;
21
+ incReplay: string;
22
+ incReplayMasked: {
23
+ strict: string;
24
+ balanced: string;
25
+ full: string;
26
+ };
27
+ incErrors: string;
28
+ incConsole: string;
29
+ incNetwork: string;
30
+ incFailedRequests: string;
31
+ incEnv: string;
32
+ incIdentity: string;
33
+ incMarks: string;
34
+ showWhere: string;
35
+ marked: (n: number) => string;
36
+ notify: string;
37
+ send: string;
38
+ sending: string;
39
+ retry: string;
40
+ errorCreate: string;
41
+ errorCapture: string;
42
+ sentTitle: string;
43
+ sentBody: string;
44
+ sentNotify: string;
45
+ seeReport: string;
46
+ tools: {
47
+ circle: string;
48
+ box: string;
49
+ arrow: string;
50
+ hide: string;
51
+ };
52
+ toolbar: string;
53
+ undo: string;
54
+ done: string;
55
+ coach: string;
56
+ coachMore: string;
57
+ /** The marking layer's name, for assistive technology. */
58
+ marking: string;
59
+ /** How to mark from the keyboard (the layer's description; shown in the coach card). */
60
+ keyboardHint: string;
61
+ hidden: string;
62
+ notePlaceholder: string;
63
+ mark: (n: number) => string;
64
+ removeMark: (n: number) => string;
65
+ shortcut: string;
66
+ shortcutHint: string;
67
+ notSet: string;
68
+ recordShortcut: string;
69
+ pressKeys: string;
70
+ needModifier: string;
71
+ removeShortcut: string;
72
+ back: string;
73
+ }
74
+ export declare function strings(locale: Locale): Strings;
75
+ /** `cs`, `cs-CZ`, `CS` → cs; `en-GB` → en; anything else → null. */
76
+ export declare function parseLocale(raw: unknown): Locale | null;
77
+ /** The first of the browser's languages the widget speaks; English otherwise. */
78
+ export declare function browserLocale(): Locale;
@@ -0,0 +1,151 @@
1
+ /** Czech plural: 1 · 2–4 · 5+ (and 0). */
2
+ function csPlural(n, one, few, many) {
3
+ if (n === 1)
4
+ return one;
5
+ if (n >= 2 && n <= 4)
6
+ return few;
7
+ return many;
8
+ }
9
+ const en = {
10
+ button: 'Report a problem',
11
+ title: 'Report a problem',
12
+ close: 'Close',
13
+ settings: 'Settings',
14
+ prompt: 'What went wrong?',
15
+ placeholder: 'Tell us what happened and what you expected',
16
+ attached: (sec) => {
17
+ if (sec < 60)
18
+ return `The last ${sec} seconds are attached`;
19
+ const min = Math.round(sec / 60);
20
+ return min === 1 ? 'The last minute is attached' : `The last ${min} minutes are attached`;
21
+ },
22
+ included: 'What’s included',
23
+ incReplay: 'A replay of what happened on this page',
24
+ incReplayMasked: {
25
+ strict: 'Text on the page and anything you typed are hidden in it',
26
+ balanced: 'Anything you typed is hidden in it',
27
+ full: 'It shows the page as you saw it',
28
+ },
29
+ incErrors: 'Errors the page ran into',
30
+ incConsole: 'Messages from the browser console',
31
+ incNetwork: 'Which addresses the page loaded, with their status',
32
+ incFailedRequests: 'Requests that failed — address and status only',
33
+ incEnv: 'Your browser, screen size, language and this page’s address',
34
+ incIdentity: 'Your name and email from this app',
35
+ incMarks: 'The places you marked, with your notes',
36
+ showWhere: 'Show us where',
37
+ marked: (n) => (n === 1 ? '1 place marked' : `${n} places marked`),
38
+ notify: 'Email me when it’s fixed',
39
+ send: 'Send',
40
+ sending: 'Sending…',
41
+ retry: 'Try again',
42
+ errorCreate: 'Couldn’t send — your text is safe, try again',
43
+ errorCapture: 'Your report arrived, the recording not yet — try again to attach it',
44
+ sentTitle: 'Thanks — we’ve got it',
45
+ sentBody: 'The team will take a look.',
46
+ sentNotify: 'We’ll email you when it’s fixed.',
47
+ seeReport: 'See your report',
48
+ tools: { circle: 'Circle', box: 'Box', arrow: 'Arrow', hide: 'Hide' },
49
+ toolbar: 'Marking tools',
50
+ undo: 'Undo',
51
+ done: 'Done',
52
+ coach: 'Click, hold and move around the problem.',
53
+ coachMore: 'You can mark more than one place.',
54
+ marking: 'Marking',
55
+ keyboardHint: 'Keyboard: Enter to start, arrows to move, Shift+arrows to resize, Enter to place.',
56
+ hidden: 'Hidden',
57
+ notePlaceholder: 'Add a note (optional)',
58
+ mark: (n) => `Mark ${n}`,
59
+ removeMark: (n) => `Remove mark ${n}`,
60
+ shortcut: 'Keyboard shortcut',
61
+ shortcutHint: 'Opens Report a problem anywhere in this app.',
62
+ notSet: 'Not set',
63
+ recordShortcut: 'Record a new shortcut',
64
+ pressKeys: 'Press keys · Esc cancels',
65
+ needModifier: 'Add Ctrl, Alt or ⌘ — a key on its own would get in the way of typing',
66
+ removeShortcut: 'Remove',
67
+ back: 'Back',
68
+ };
69
+ const cs = {
70
+ button: 'Nahlásit problém',
71
+ title: 'Nahlásit problém',
72
+ close: 'Zavřít',
73
+ settings: 'Nastavení',
74
+ prompt: 'Co se pokazilo?',
75
+ placeholder: 'Napište, co se stalo a co jste čekali',
76
+ attached: (sec) => {
77
+ if (sec < 60) {
78
+ return csPlural(sec, 'Poslední sekunda je přiložena', `Poslední ${sec} sekundy jsou přiloženy`, `Posledních ${sec} sekund je přiloženo`);
79
+ }
80
+ const min = Math.round(sec / 60);
81
+ return csPlural(min, 'Poslední minuta je přiložena', `Poslední ${min} minuty jsou přiloženy`, `Posledních ${min} minut je přiloženo`);
82
+ },
83
+ included: 'Co je přiloženo',
84
+ incReplay: 'Záznam toho, co se na stránce dělo',
85
+ incReplayMasked: {
86
+ strict: 'Texty stránky i vše, co jste napsali, jsou v něm skryté',
87
+ balanced: 'Vše, co jste napsali, je v něm skryté',
88
+ full: 'Ukazuje stránku tak, jak jste ji viděli',
89
+ },
90
+ incErrors: 'Chyby, na které stránka narazila',
91
+ incConsole: 'Zprávy z konzole prohlížeče',
92
+ incNetwork: 'Které adresy stránka načítala a s jakým výsledkem',
93
+ incFailedRequests: 'Požadavky, které selhaly — jen adresa a výsledek',
94
+ incEnv: 'Váš prohlížeč, velikost obrazovky, jazyk a adresa stránky',
95
+ incIdentity: 'Vaše jméno a e-mail z této aplikace',
96
+ incMarks: 'Místa, která jste označili, i s poznámkami',
97
+ showWhere: 'Ukažte nám kde',
98
+ marked: (n) => csPlural(n, '1 označené místo', `${n} označená místa`, `${n} označených míst`),
99
+ notify: 'Pošlete mi e-mail, až to bude opravené',
100
+ send: 'Odeslat',
101
+ sending: 'Odesílám…',
102
+ retry: 'Zkusit znovu',
103
+ errorCreate: 'Nepodařilo se odeslat — váš text zůstal, zkuste to znovu',
104
+ errorCapture: 'Hlášení dorazilo, záznam zatím ne — zkuste to znovu a přiložíme ho',
105
+ sentTitle: 'Díky — máme to',
106
+ sentBody: 'Tým se na to podívá.',
107
+ sentNotify: 'Až to bude opravené, pošleme vám e-mail.',
108
+ seeReport: 'Zobrazit hlášení',
109
+ tools: { circle: 'Kruh', box: 'Obdélník', arrow: 'Šipka', hide: 'Skrýt' },
110
+ toolbar: 'Nástroje pro označení',
111
+ undo: 'Zpět',
112
+ done: 'Hotovo',
113
+ coach: 'Klikněte, podržte a veďte kolem problému.',
114
+ coachMore: 'Označit můžete i více míst.',
115
+ marking: 'Označování',
116
+ keyboardHint: 'Klávesnice: Enter začne, šipky posouvají, Shift+šipky mění velikost, Enter umístí.',
117
+ hidden: 'Skryto',
118
+ notePlaceholder: 'Přidejte poznámku (nepovinné)',
119
+ mark: (n) => `Značka ${n}`,
120
+ removeMark: (n) => `Odebrat značku ${n}`,
121
+ shortcut: 'Klávesová zkratka',
122
+ shortcutHint: 'Otevře Nahlásit problém kdekoli v této aplikaci.',
123
+ notSet: 'Nenastavena',
124
+ recordShortcut: 'Nahrát novou zkratku',
125
+ pressKeys: 'Stiskněte klávesy · Esc zruší',
126
+ needModifier: 'Přidejte Ctrl, Alt nebo ⌘ — samotná klávesa by překážela při psaní',
127
+ removeShortcut: 'Odebrat',
128
+ back: 'Zpět',
129
+ };
130
+ const CATALOGS = { cs, en };
131
+ export function strings(locale) {
132
+ return CATALOGS[locale];
133
+ }
134
+ /** `cs`, `cs-CZ`, `CS` → cs; `en-GB` → en; anything else → null. */
135
+ export function parseLocale(raw) {
136
+ if (typeof raw !== 'string')
137
+ return null;
138
+ const lang = raw.trim().toLowerCase().split(/[-_]/)[0];
139
+ return lang === 'cs' || lang === 'en' ? lang : null;
140
+ }
141
+ /** The first of the browser's languages the widget speaks; English otherwise. */
142
+ export function browserLocale() {
143
+ const nav = globalThis.navigator;
144
+ const prefs = nav ? (nav.languages?.length ? nav.languages : [nav.language]) : [];
145
+ for (const p of prefs) {
146
+ const l = parseLocale(p);
147
+ if (l)
148
+ return l;
149
+ }
150
+ return 'en';
151
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Who a report is filed as (QA Studio D4). The host vouches with a token it
3
+ * signed SERVER-SIDE — a compact HS256 JWS over `{sub, email, name?, iat,
4
+ * exp, aud: "<ws>/<project>"}` with the project's host secret, `exp` at most
5
+ * 24 h after `iat` — which files the report directly; or it asserts an
6
+ * email, which binds the report to a pending reporter (quarantined until
7
+ * approved). Neither: anonymous, quarantined.
8
+ *
9
+ * Held in memory only, for the life of the page: the host passes it on
10
+ * every load. The widget never reads the token's claims — the server
11
+ * verifies it; the token itself never leaves for anywhere but `base`.
12
+ */
13
+ export type Identity = {
14
+ token: string;
15
+ } | {
16
+ email: string;
17
+ name?: string;
18
+ };
19
+ /** What `identify()` accepts: an identity, or null/undefined to go anonymous. */
20
+ export type IdentifyInput = Identity | null | undefined;
21
+ /** A clean identity, or null (with one warning) for anything malformed. */
22
+ export declare function normalizeIdentity(input: IdentifyInput): Identity | null;
23
+ /** Name the person every mounted widget files as (a widget's own `identify` wins). */
24
+ export declare function identify(input: IdentifyInput): void;
25
+ export declare function sharedIdentity(): Identity | null;
26
+ export declare function onSharedIdentity(fn: () => void): () => void;