@vitrinka/web 0.6.0 → 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 (60) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/README.md +124 -4
  3. package/build/hud.iife.js +7 -7
  4. package/build/index.d.ts +1 -0
  5. package/build/recorder/RecorderProvider.js +5 -18
  6. package/build/recorder/api.d.ts +20 -0
  7. package/build/recorder/api.js +21 -9
  8. package/build/recorder/capture/console.d.ts +6 -1
  9. package/build/recorder/capture/console.js +28 -5
  10. package/build/recorder/capture/net.d.ts +10 -1
  11. package/build/recorder/capture/net.js +14 -1
  12. package/build/recorder/capture/redact.d.ts +1 -0
  13. package/build/recorder/capture/redact.js +6 -1
  14. package/build/recorder/capture/rrweb-lane.d.ts +19 -0
  15. package/build/recorder/capture/rrweb-lane.js +109 -0
  16. package/build/recorder/capture/rrweb.d.ts +2 -9
  17. package/build/recorder/capture/rrweb.js +11 -86
  18. package/build/recorder/config.d.ts +3 -1
  19. package/build/recorder/config.js +15 -2
  20. package/build/recorder/flight.d.ts +141 -22
  21. package/build/recorder/flight.js +312 -27
  22. package/build/recorder/hud/host-style.d.ts +14 -0
  23. package/build/recorder/hud/host-style.js +15 -0
  24. package/build/recorder/hud/host.js +1 -1
  25. package/build/recorder/hud/styles.d.ts +1 -11
  26. package/build/recorder/hud/styles.js +1 -12
  27. package/build/recorder/state.d.ts +18 -1
  28. package/build/recorder/state.js +40 -1
  29. package/build/recorder/storage/capture.d.ts +44 -0
  30. package/build/recorder/storage/capture.js +136 -0
  31. package/build/recorder/version.d.ts +2 -2
  32. package/build/recorder/version.js +1 -1
  33. package/build/report/bundle.d.ts +4 -0
  34. package/build/report/bundle.js +30 -0
  35. package/build/report/element.d.ts +86 -0
  36. package/build/report/element.js +146 -0
  37. package/build/report/engine.d.ts +144 -0
  38. package/build/report/engine.js +402 -0
  39. package/build/report/i18n.d.ts +78 -0
  40. package/build/report/i18n.js +151 -0
  41. package/build/report/identity.d.ts +26 -0
  42. package/build/report/identity.js +36 -0
  43. package/build/report/index.d.ts +12 -0
  44. package/build/report/index.js +15 -0
  45. package/build/report/keybind.d.ts +29 -0
  46. package/build/report/keybind.js +99 -0
  47. package/build/report/markers.d.ts +77 -0
  48. package/build/report/markers.js +162 -0
  49. package/build/report/profile.d.ts +62 -0
  50. package/build/report/profile.js +115 -0
  51. package/build/report/recorder-face.d.ts +2 -0
  52. package/build/report/recorder-face.js +20 -0
  53. package/build/report/styles.d.ts +7 -0
  54. package/build/report/styles.js +226 -0
  55. package/build/report/widget.d.ts +109 -0
  56. package/build/report/widget.js +907 -0
  57. package/build/report/wire.d.ts +68 -0
  58. package/build/report/wire.js +96 -0
  59. package/build/report-widget.mjs +229 -0
  60. package/package.json +11 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,76 @@
1
1
  # @vitrinka/web
2
2
 
3
+ ## 0.7.0
4
+
5
+ **Report a problem** — the report face of the one capture client (QA Studio
6
+ D6): the same engine as the recorder, a reporter's face.
7
+
8
+ - **`@vitrinka/web/report`** — `mountReport(opts)` and the
9
+ `<vitrinka-report>` element (`key`, `base`, `open-selector`, `locale`,
10
+ `button`): a large floating "Report a problem" button (`button: false`
11
+ hides it), a card that asks "What went wrong?" with Send, and **Show us
12
+ where** to mark the frozen page — circle, box, arrow, hide — numbered
13
+ 1, 2, 3… with an optional note each. No element selector. Until the first
14
+ mark a coach card rides beside the pointer: a tiny loop of the gesture and
15
+ "Click, hold and move around the problem". `open()`, `close()`,
16
+ `identify({token} | {email, name?})`, `setLocale('cs' | 'en')`,
17
+ `unmount()`; `face: 'recorder'` mounts the recorder pill instead (npm).
18
+ - **One file for vitrinka** — `@vitrinka/web/report-widget.mjs`
19
+ (`build/report-widget.mjs`), served as `/vendor/report-widget-1.mjs`:
20
+ React-free, its only runtime import the deployment's
21
+ `/vendor/rrweb-record-1.min.js`, loaded lazily.
22
+ - **The capture profile** (D7) from `GET /api/v1/report-config`, which the
23
+ host can only narrow: memory or browser storage (IndexedDB, masked before
24
+ storage, expiring with the window, cleared after send and on the next load
25
+ past its age), the window (default 5 min), the size cap, and the classes
26
+ (errors · interactions · full · console · network). Drafts stay in memory.
27
+ - **The report wire**: `POST /api/v1/reports` → chunks → rrweb rows →
28
+ `submit`, under the `vkb_` key; leg-resumable (Retry resumes, never
29
+ duplicates); marks as viewport rects with `env.viewport {w, h, dpr}`; a
30
+ hide blanks its region in the replay before it leaves the browser.
31
+ - **cs / en built in**: the browser's language by default; the `locale`
32
+ option, attribute and `setLocale()` repaint live without losing the draft
33
+ or the marks.
34
+ - **The reporter's own shortcut**, recorded in the card's settings by
35
+ pressing it (a modifier required, Esc cancels); no default.
36
+ - **Marks from the keyboard**: the marking layer takes focus; Enter places
37
+ a mark, arrows move it, Shift+arrows resize it, Enter sets it.
38
+ - **Stored capture is scoped** to vitrinka's origin, the project, the
39
+ masking profile and the classes it was captured under: a load under
40
+ anything else drops it. A hide names the nodes it covers when drawn, and
41
+ without rrweb's mirror a report with a hide goes without its replay.
42
+ Console and network entries are stored in spans of their own (an
43
+ errors-only profile keeps them across loads); a draft reads the stored
44
+ windows when the card opens.
45
+ - **One runtime per page**: the recorder face, when mounted, runs the
46
+ page's capture (`claimCapture`); a report face beside it reports without
47
+ one and never rewrites the recorder's server, key or rules.
48
+ `identify(null)` on a widget is anonymous even under a page-wide
49
+ `identify()`; a tag that gets its `key`/`base` after connecting mounts then.
50
+ Widgets share a capture only when they ask the same of it (key, base,
51
+ `capture`, `sanitizeUrl`); the report moves into an open (modal) dialog
52
+ and back, draft and marks intact; a window whose snapshot is over the
53
+ wire cap is left out whole.
54
+
55
+ Engine changes the recorder face shares:
56
+
57
+ - The flight buffer takes a profile (window, checkout interval, caps, an
58
+ optional store). Windows now age against the clock — a window is kept
59
+ while it still covers part of the window — and a window being recorded
60
+ that alone outgrows the cap restarts from a forced full snapshot instead
61
+ of waiting for the next checkout; a clip says `truncated` when a cap cut
62
+ it. An idle page's window is replaced by a fresh snapshot once its newest
63
+ event is older than the window. The pill's last minute is otherwise
64
+ unchanged (30 s windows, 4 MiB).
65
+ - `patchNetwork({detail})` and `patchConsole({levels})` take their settings
66
+ per acquisition, so nothing a report face chose outlives its release.
67
+ - The rrweb lane takes its recorder as an argument
68
+ (`capture/rrweb-lane.ts`); `capture/rrweb.ts` binds the static import.
69
+ - The network lane has a metadata-only mode, the console lane can tap
70
+ `warn` / `info` / `log`, the API client takes an explicit `target`
71
+ (`{url, key}`) per call, and the HUD host's inline style moved to its own
72
+ module so mounting the host no longer pulls in the React sheets.
73
+
3
74
  ## 0.6.0
4
75
 
5
76
  The pill now says what it is doing at every step, and keeps what you write.
package/README.md CHANGED
@@ -14,6 +14,12 @@ screenshots), **clicks** (selector, text, rect), **navigation**, **network**
14
14
  [`docs/PROTOCOL.md`](../../docs/PROTOCOL.md). Idle, the pill can also send
15
15
  the last minute as a bug report ([Report a bug](#report-a-bug)).
16
16
 
17
+ The same engine has a second face for the people who use your app:
18
+ **[Report a problem](#report-a-problem-vitrinkawebreport)** — a large
19
+ button, "What went wrong?", optional marks drawn on the page, and the last
20
+ minutes attached under your project's capture profile. No React needed; it
21
+ also ships as one file vitrinka serves.
22
+
17
23
  ## Install
18
24
 
19
25
  ```bash
@@ -177,7 +183,7 @@ vitrinka` (or `sending N`) · actions · frames · notes · pages:
177
183
  | ≣ History | | this recording's notes and annotations, newest first, in the board's annotation-island layout: open one to see its versions, **Save edit** (sent as a new note that `replaces` it), or **reference** it from a new note |
178
184
  | ⏸ Pause / ▶ Resume | ⌥⇧P (Alt⇧P) | freezes the clock and capture (a note written while paused is still sent) |
179
185
  | ✎ Note | ⌥⇧N | the note sheet — Enter sends, ⇧Enter newline, Esc / ✕ / click-outside cancel. A cancelled draft (and its images) parks as a small drop on the pill: hover shows its first line, a click resumes it. The clock says **queued**, then **Saved** once the server has the note. Images: see [Attach images](#attach-images) |
180
- | ⌖ Annotate | ⌥⇧A | click or tap an element, or drag a region (a finger too). While annotating, the page gets no press, move or hover, does not scroll, and selects no text. Then describe it; the sheet names what you picked (its crop where the host can read pixels — the extension — else its size and route) with **Reselect**. Everything lands on the board |
186
+ | ⌖ Annotate | ⌥⇧A | click or tap an element, or drag a region (a finger too). While annotating, the page gets no press, move or hover, does not scroll, and selects no text. Then describe it; the sheet names what you picked (its size and route; a crop only from a host that can show pixels outside the page — `HudController.captureRegion` — which neither recorder does, since the HUD's shadow root is open to the page) with **Reselect**. Everything lands on the board |
181
187
  | ■ Stop | ⌥⇧S | the pill asks **Stop & save?** (Esc / **Keep recording** cancels), shows **Saving…** with progress while the tail drains, then **Building board · k/n** while the server builds it, then **Board ready · Open board** until **Done** (a failed build says so, with **Retry**) |
182
188
  | ⋯ | | the linked account · **Report a bug** (below) · **Open this board** · **Recent** (this device's last five recordings, each linked to its board) · **Go to vitrinka** · **Size** S/M/L · **Technical details** · **Position** · **Unlink this device** (asks first) |
183
189
 
@@ -248,11 +254,12 @@ is the same code for the extension.
248
254
 
249
255
  **The last minute.** While the pill is mounted and idle on a device that can
250
256
  record (a recorder key or a linked device), it keeps the page's last minute
251
- **in memory**: the rrweb DOM stream as two 30-second checkout windows (a clip
257
+ **in memory**: the rrweb DOM stream as 30-second checkout windows (a clip
252
258
  covers the last 30–60 s and always opens on a full snapshot), plus the
253
- click, navigation, console and network events since the older window
259
+ click, navigation, console and network events since the oldest window
254
260
  opened. Caps: 4 MiB of serialized rrweb, 20 000 rrweb events, 500 lane
255
- events; over a cap the older window goes. It runs the recording's own
261
+ events; over a cap the oldest window goes, and a window being recorded
262
+ that alone outgrows it restarts from a fresh snapshot. It runs the recording's own
256
263
  redaction (masked inputs, your workspace policy — fetched once when the
257
264
  buffer starts — scrubbed URLs, click text that never reads a value). Nothing
258
265
  of it is written to storage or sent until you press Send; a reload, an
@@ -284,6 +291,119 @@ the running session instead.
284
291
  Then nothing is captured until a recording starts, and Report a bug is
285
292
  offered only during one.
286
293
 
294
+ ## Report a problem (`@vitrinka/web/report`)
295
+
296
+ The report face of the same engine, for the people using your app: a large
297
+ **Report a problem** / **Nahlásit problém** button, a card that asks
298
+ **What went wrong?** with Send, and **Show us where** to circle, box, point
299
+ at or hide parts of the page — numbered marks with an optional note each,
300
+ taught by a coach card ("click, hold and move") until the first mark
301
+ exists; from the keyboard, Enter places a mark, arrows move it,
302
+ Shift+arrows resize it and Enter sets it. The minutes before are attached under your project's **capture
303
+ profile** (set in vitrinka; see [`docs/PROTOCOL.md`](../../docs/PROTOCOL.md)
304
+ § Report a problem). You need the project's report key (`vkb_…`).
305
+
306
+ **Script tag** — vitrinka serves the single-file build; `base` defaults to
307
+ the origin it came from:
308
+
309
+ ```html
310
+ <script type="module" src="https://vitrinka.example/vendor/report-widget-1.mjs"></script>
311
+ <vitrinka-report key="vkb_…" locale="cs"></vitrinka-report>
312
+ ```
313
+
314
+ **npm** (rrweb, a peer dependency, loads lazily — only when the profile
315
+ records the page):
316
+
317
+ ```ts
318
+ import { mountReport } from '@vitrinka/web/report';
319
+
320
+ const report = mountReport({
321
+ key: 'vkb_…',
322
+ base: 'https://vitrinka.example',
323
+ locale: 'cs', // default: the browser's language
324
+ capture: { windowSec: 120 }, // optional: narrow the project's profile, never widen it
325
+ });
326
+ report.open(); // or the button, or the reporter's own shortcut
327
+ ```
328
+
329
+ **React** — mount once, follow the app's language live (a switch never
330
+ loses the draft or the marks):
331
+
332
+ ```tsx
333
+ import { useEffect, useRef } from 'react';
334
+ import { mountReport, type ReportHandle } from '@vitrinka/web/report';
335
+
336
+ function ReportAProblem({ locale, token }: { locale: string; token?: string }) {
337
+ const report = useRef<ReportHandle | null>(null);
338
+ useEffect(() => {
339
+ report.current = mountReport({ key: process.env.NEXT_PUBLIC_VITRINKA_REPORT_KEY!, base: 'https://vitrinka.example' });
340
+ return () => report.current?.unmount();
341
+ }, []);
342
+ useEffect(() => report.current?.setLocale(locale), [locale]);
343
+ useEffect(() => report.current?.identify(token ? { token } : null), [token]);
344
+ return null;
345
+ }
346
+ ```
347
+
348
+ | Option / attribute | |
349
+ |---|---|
350
+ | `key` | the project's `vkb_` report key (required) |
351
+ | `base` | vitrinka's origin (the script tag defaults to where it was served from) |
352
+ | `locale` | `cs` · `en`; live as an attribute, and through `setLocale()` |
353
+ | `button` | `false` hides the floating button: open the card from your own control |
354
+ | `open-selector` / `openSelector` | a CSS selector of your control(s) that open the card |
355
+ | `face` | `report` (default) or `recorder` — the recorder pill on the same engine (npm only; it takes a `vkr_` key or the device link) |
356
+ | `capture` | narrow the capture profile: `{storage: 'memory', windowSec, maxBytes, classes}` |
357
+ | `identity` | as `identify()` below |
358
+ | `appVersion`, `sanitizeUrl` | as on the recorder |
359
+
360
+ The handle (and the element) has `open()`, `close()`, `identify()`,
361
+ `setLocale()`; the handle also `unmount()`s. For the tag from npm, call
362
+ `defineReportElement()` once.
363
+
364
+ **Who reports.** Vouch for your signed-in user with a token your SERVER
365
+ signs — never in the browser — over `{sub, email, name?, iat, exp, aud:
366
+ "<workspace>/<project>"}`, HS256 with the project's host secret (shown once
367
+ in the project's settings), `exp` at most 24 h after `iat`:
368
+
369
+ ```ts
370
+ // server-side, e.g. a route your app calls after sign-in
371
+ import { createHmac } from 'node:crypto';
372
+
373
+ const b64 = (v: string | Buffer) => Buffer.from(v).toString('base64url');
374
+ export function reporterToken(user: { id: string; email: string; name?: string }): string {
375
+ const now = Math.floor(Date.now() / 1000);
376
+ const head = b64(JSON.stringify({ alg: 'HS256', typ: 'JWT' }));
377
+ const body = b64(JSON.stringify({ sub: user.id, email: user.email, name: user.name, iat: now, exp: now + 3600, aud: 'acme/voke' }));
378
+ const sig = b64(createHmac('sha256', process.env.VITRINKA_REPORT_HOST_SECRET!).update(`${head}.${body}`).digest());
379
+ return `${head}.${body}.${sig}`;
380
+ }
381
+ ```
382
+
383
+ ```ts
384
+ report.identify({ token }); // filed directly, as that reporter
385
+ report.identify({ email, name }); // a pending reporter: held until approved
386
+ report.identify(null); // anonymous: held until approved
387
+ ```
388
+
389
+ `identify` from `@vitrinka/web/report` names the reporter for every widget
390
+ on the page; a widget's own `identify()` wins (`null` makes that widget
391
+ anonymous, `undefined` hands it back to the page-wide one). Identity lives
392
+ in memory only; pass it on every load.
393
+
394
+ **Beside the recorder.** One page runs one capture: when the recorder face
395
+ (`VitrinkaRecorderRoot`) is mounted it owns it, and Report a problem sends
396
+ its reports without a capture of its own — mount one face per page (pick it
397
+ by your app's mode, or with `face`).
398
+
399
+ **The shortcut.** There is none by default. A reporter sets their own in the
400
+ card's settings (⚙) by pressing it: a modifier other than Shift is required,
401
+ Esc cancels. It is kept in `localStorage` (`vitrinka.recorder.report.keybind`).
402
+
403
+ **What the reporter sees after Send**: "Thanks — we've got it", and **See
404
+ your report** when the server returns the report's page. A failed send
405
+ keeps every word; **Try again** resumes the same report.
406
+
287
407
  ## Attach images
288
408
 
289
409
  A note, an annotation and a bug report can carry reference images — "how