@vitrinka/web 0.7.2 → 0.8.1

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 (54) hide show
  1. package/CHANGELOG.md +162 -0
  2. package/README.md +130 -23
  3. package/build/hud.iife.js +15 -15
  4. package/build/one.iife.js +1 -1
  5. package/build/recorder/api.d.ts +5 -3
  6. package/build/recorder/api.js +5 -3
  7. package/build/recorder/config.d.ts +6 -2
  8. package/build/recorder/hud/Hud.d.ts +3 -1
  9. package/build/recorder/hud/Hud.js +2 -2
  10. package/build/recorder/hud/Menu.d.ts +7 -1
  11. package/build/recorder/hud/Menu.js +2 -2
  12. package/build/recorder/hud/host.d.ts +13 -0
  13. package/build/recorder/hud/host.js +96 -1
  14. package/build/recorder/hud/icons.d.ts +2 -0
  15. package/build/recorder/hud/icons.js +4 -0
  16. package/build/recorder/hud/mount.d.ts +2 -0
  17. package/build/recorder/hud/mount.js +1 -0
  18. package/build/recorder/index.d.ts +6 -0
  19. package/build/recorder/index.js +3 -0
  20. package/build/recorder/link.js +1 -1
  21. package/build/recorder/storage/index.d.ts +1 -1
  22. package/build/recorder/storage/index.js +3 -2
  23. package/build/recorder/storage/lock.js +85 -3
  24. package/build/recorder/version.d.ts +2 -2
  25. package/build/recorder/version.js +1 -1
  26. package/build/report/attachments.d.ts +56 -0
  27. package/build/report/attachments.js +91 -0
  28. package/build/report/drag.d.ts +18 -0
  29. package/build/report/drag.js +34 -0
  30. package/build/report/element.d.ts +11 -2
  31. package/build/report/element.js +106 -15
  32. package/build/report/engine.d.ts +13 -1
  33. package/build/report/engine.js +31 -4
  34. package/build/report/face.d.ts +23 -0
  35. package/build/report/face.js +92 -0
  36. package/build/report/i18n.d.ts +77 -3
  37. package/build/report/i18n.js +127 -6
  38. package/build/report/place.d.ts +26 -0
  39. package/build/report/place.js +33 -0
  40. package/build/report/reader.d.ts +42 -0
  41. package/build/report/reader.js +39 -0
  42. package/build/report/recorder-face.js +6 -2
  43. package/build/report/sent.d.ts +16 -0
  44. package/build/report/sent.js +39 -0
  45. package/build/report/settings.d.ts +32 -0
  46. package/build/report/settings.js +47 -0
  47. package/build/report/styles.d.ts +1 -1
  48. package/build/report/styles.js +223 -53
  49. package/build/report/widget.d.ts +122 -3
  50. package/build/report/widget.js +1125 -107
  51. package/build/report/wire.d.ts +59 -9
  52. package/build/report/wire.js +114 -14
  53. package/build/report-widget.mjs +232 -62
  54. package/package.json +1 -1
@@ -4,20 +4,31 @@
4
4
  *
5
5
  * POST /api/v1/reports envelope → {id, custody}
6
6
  * PATCH /api/v1/reports/{id} {title?, description?, markers?, notify?}
7
+ * POST /api/v1/reports/{id}/attachment?name=<name>
8
+ * one file, raw body under its own Content-Type → {id, name, size, type}
7
9
  * POST /api/v1/reports/{id}/chunk?seq=N raw rrweb event array (≤ 4 MiB, N from 1) → {blobKey}
8
10
  * POST /api/v1/reports/{id}/events {events: [{seq, ts, tabHost, kind: "rrweb", payload, blobKey}]}
9
11
  * POST /api/v1/reports/{id}/submit {} → {status: "filed" | "quarantined", reportUrl?}
10
12
  *
11
- * LEG-RESUMABLE: a job remembers which legs landed, so a retry resumes the
12
- * failed one — one report, never a duplicate. Text the reporter changed
13
- * after the report was created rides a PATCH. A capture leg the server
14
- * refuses for good (a permanent 4xx) is skipped with a warning: the report
15
- * still files, without its replay. `reportUrl` is the server's — shown as
16
- * returned, never composed.
13
+ * LEG-RESUMABLE: a job remembers which legs landed — each file, each chunk —
14
+ * so a retry resumes the failed one: one report, never a duplicate, never a
15
+ * file twice. Text the reporter changed after the report was created rides a
16
+ * PATCH. A file or a capture leg the server refuses for good (a permanent
17
+ * 4xx) is skipped with a warning: the report still files, without it. The
18
+ * reporter's files go before the replay — they are what they chose to send.
19
+ * `reportUrl` is the server's — shown as returned, never composed.
20
+ *
21
+ * EVERY LEG HAS A DEADLINE (`deadline`): a request nothing answers — a server
22
+ * stuck in a handler, a proxy or connection holding it — rejects like a
23
+ * dropped connection, so the card shows Try again instead of "Sending…"
24
+ * forever. An upload's allowance grows with its bytes at a slow uplink's
25
+ * pace, so only a stalled one runs out. A create whose answer was lost after
26
+ * the server stored it is created again by Try again: the same risk a dropped
27
+ * connection already carries.
17
28
  */
18
29
  import { type ApiTarget } from '../recorder/api';
19
30
  import { type BuiltCapture, type ConsoleEntry, type NetEntry } from './engine';
20
- import type { Locale } from './i18n';
31
+ import type { Locale, ReportKind } from './i18n';
21
32
  import type { Identity } from './identity';
22
33
  import type { WireMarker } from './markers';
23
34
  export interface ReportEnv {
@@ -44,15 +55,45 @@ export interface ReportEnvelope {
44
55
  /** The widget's language (the reporter reads mail and the portal in it). */
45
56
  locale: Locale;
46
57
  notify?: boolean;
58
+ /** The reporter's own word for it (vt-8020 D11), absent when they picked none. */
59
+ type?: ReportKind;
47
60
  }
48
61
  export interface SubmitReply {
49
62
  status: 'filed' | 'quarantined';
50
63
  reportUrl?: string;
51
64
  }
65
+ /** How long a leg may go unanswered: `ms` for any leg, plus one ms per `bytesPerMs` bytes an upload carries. */
66
+ export interface LegLimits {
67
+ ms: number;
68
+ bytesPerMs: number;
69
+ }
70
+ /** 30 s for a JSON leg; an upload adds its bytes at 32 KiB/s (≈ 256 kbit/s), so a 10 MiB file gets about six minutes. */
71
+ export declare const LEG_LIMITS: LegLimits;
72
+ /** A leg ran past its deadline: retryable, never a refusal for good. */
73
+ export declare class LegTimeout extends Error {
74
+ constructor(what: string, ms: number);
75
+ }
76
+ /**
77
+ * Run `work` under a deadline: past `ms` its signal aborts (the fetch and its
78
+ * answer's body stop) and the returned promise rejects with LegTimeout —
79
+ * whether or not `work` honours the signal, so nothing waits on it forever.
80
+ */
81
+ export declare function deadline<T>(what: string, ms: number, work: (signal: AbortSignal) => Promise<T>): Promise<T>;
82
+ /** What a report carries when its capture could not be prepared. */
83
+ export declare const EMPTY_CAPTURE: BuiltCapture;
84
+ /**
85
+ * The capture a report sends, under its deadline like every leg (reading an
86
+ * earlier load's stored windows can hang): past it, or failed, the report
87
+ * goes without one. A build that finishes later is dropped — it never
88
+ * reaches the job this answer started.
89
+ */
90
+ export declare function prepareCapture(build: () => Promise<BuiltCapture>, ms?: number): Promise<BuiltCapture>;
52
91
  export declare class ReportJob {
53
92
  readonly capture: BuiltCapture;
54
93
  private readonly tabHost;
55
94
  private readonly target;
95
+ readonly files: readonly File[];
96
+ private readonly limits;
56
97
  id: string;
57
98
  custody: 'direct' | 'quarantined' | '';
58
99
  /** The editable fields as the server last received them. */
@@ -60,9 +101,18 @@ export declare class ReportJob {
60
101
  private readonly blobKeys;
61
102
  private rowsPosted;
62
103
  private skipCapture;
63
- /** `target`: the widget's own base and key — never whatever another widget configured. */
64
- constructor(capture: BuiltCapture, tabHost: string, target: ApiTarget);
104
+ /** The files (by index) the server has — landed or refused for good. */
105
+ private readonly filesDone;
106
+ /** `target`: the widget's own base and key — never whatever another widget configured. `files`: the reporter's attachments, fixed for the job. */
107
+ constructor(capture: BuiltCapture, tabHost: string, target: ApiTarget, files?: readonly File[], limits?: LegLimits);
108
+ /** One JSON call under its leg deadline. */
109
+ private call;
110
+ /** One upload under a deadline that grows with its bytes. */
111
+ private upload;
112
+ /** A file has not landed yet: the attachment leg is what a retry resumes. */
113
+ get filesPending(): boolean;
65
114
  /** Run the legs from wherever the last run stopped; rejects with the failing leg's error. */
66
115
  run(env: ReportEnvelope): Promise<SubmitReply>;
116
+ private sendFiles;
67
117
  private sendCapture;
68
118
  }
@@ -4,23 +4,81 @@
4
4
  *
5
5
  * POST /api/v1/reports envelope → {id, custody}
6
6
  * PATCH /api/v1/reports/{id} {title?, description?, markers?, notify?}
7
+ * POST /api/v1/reports/{id}/attachment?name=<name>
8
+ * one file, raw body under its own Content-Type → {id, name, size, type}
7
9
  * POST /api/v1/reports/{id}/chunk?seq=N raw rrweb event array (≤ 4 MiB, N from 1) → {blobKey}
8
10
  * POST /api/v1/reports/{id}/events {events: [{seq, ts, tabHost, kind: "rrweb", payload, blobKey}]}
9
11
  * POST /api/v1/reports/{id}/submit {} → {status: "filed" | "quarantined", reportUrl?}
10
12
  *
11
- * LEG-RESUMABLE: a job remembers which legs landed, so a retry resumes the
12
- * failed one — one report, never a duplicate. Text the reporter changed
13
- * after the report was created rides a PATCH. A capture leg the server
14
- * refuses for good (a permanent 4xx) is skipped with a warning: the report
15
- * still files, without its replay. `reportUrl` is the server's — shown as
16
- * returned, never composed.
13
+ * LEG-RESUMABLE: a job remembers which legs landed — each file, each chunk —
14
+ * so a retry resumes the failed one: one report, never a duplicate, never a
15
+ * file twice. Text the reporter changed after the report was created rides a
16
+ * PATCH. A file or a capture leg the server refuses for good (a permanent
17
+ * 4xx) is skipped with a warning: the report still files, without it. The
18
+ * reporter's files go before the replay — they are what they chose to send.
19
+ * `reportUrl` is the server's — shown as returned, never composed.
20
+ *
21
+ * EVERY LEG HAS A DEADLINE (`deadline`): a request nothing answers — a server
22
+ * stuck in a handler, a proxy or connection holding it — rejects like a
23
+ * dropped connection, so the card shows Try again instead of "Sending…"
24
+ * forever. An upload's allowance grows with its bytes at a slow uplink's
25
+ * pace, so only a stalled one runs out. A create whose answer was lost after
26
+ * the server stored it is created again by Try again: the same risk a dropped
27
+ * connection already carries.
17
28
  */
18
29
  import { api, permanentStatus, uploadTo, VitrinkaApiError } from '../recorder/api';
19
30
  import { EVENTS_PER_POST } from './engine';
31
+ /** 30 s for a JSON leg; an upload adds its bytes at 32 KiB/s (≈ 256 kbit/s), so a 10 MiB file gets about six minutes. */
32
+ export const LEG_LIMITS = { ms: 30_000, bytesPerMs: 32 };
33
+ /** A leg ran past its deadline: retryable, never a refusal for good. */
34
+ export class LegTimeout extends Error {
35
+ constructor(what, ms) {
36
+ super(`vitrinka: ${what} got no answer in ${Math.round(ms / 1000)} s — Try again resumes it`);
37
+ this.name = 'LegTimeout';
38
+ }
39
+ }
40
+ /**
41
+ * Run `work` under a deadline: past `ms` its signal aborts (the fetch and its
42
+ * answer's body stop) and the returned promise rejects with LegTimeout —
43
+ * whether or not `work` honours the signal, so nothing waits on it forever.
44
+ */
45
+ export async function deadline(what, ms, work) {
46
+ const ctl = new AbortController();
47
+ let timer;
48
+ const expired = new Promise((_, reject) => {
49
+ timer = setTimeout(() => {
50
+ const e = new LegTimeout(what, ms);
51
+ ctl.abort(e);
52
+ reject(e);
53
+ }, ms);
54
+ });
55
+ try {
56
+ return await Promise.race([work(ctl.signal), expired]);
57
+ }
58
+ finally {
59
+ clearTimeout(timer);
60
+ }
61
+ }
62
+ /** What a report carries when its capture could not be prepared. */
63
+ export const EMPTY_CAPTURE = { chunks: [], truncated: false, console: [], network: [] };
64
+ /**
65
+ * The capture a report sends, under its deadline like every leg (reading an
66
+ * earlier load's stored windows can hang): past it, or failed, the report
67
+ * goes without one. A build that finishes later is dropped — it never
68
+ * reaches the job this answer started.
69
+ */
70
+ export function prepareCapture(build, ms = LEG_LIMITS.ms) {
71
+ return deadline('preparing the capture', ms, build).catch((e) => {
72
+ console.warn('vitrinka: the capture could not be prepared — the report goes without it', e);
73
+ return EMPTY_CAPTURE;
74
+ });
75
+ }
20
76
  export class ReportJob {
21
77
  capture;
22
78
  tabHost;
23
79
  target;
80
+ files;
81
+ limits;
24
82
  id = '';
25
83
  custody = '';
26
84
  /** The editable fields as the server last received them. */
@@ -28,19 +86,44 @@ export class ReportJob {
28
86
  blobKeys = new Map();
29
87
  rowsPosted = 0;
30
88
  skipCapture = false;
31
- /** `target`: the widget's own base and key — never whatever another widget configured. */
32
- constructor(capture, tabHost, target) {
89
+ /** The files (by index) the server has — landed or refused for good. */
90
+ filesDone = new Set();
91
+ /** `target`: the widget's own base and key — never whatever another widget configured. `files`: the reporter's attachments, fixed for the job. */
92
+ constructor(capture, tabHost, target, files = [], limits = LEG_LIMITS) {
33
93
  this.capture = capture;
34
94
  this.tabHost = tabHost;
35
95
  this.target = target;
96
+ this.files = files;
97
+ this.limits = limits;
98
+ }
99
+ /** One JSON call under its leg deadline. */
100
+ call(method, path, body) {
101
+ return deadline(`${method} ${path}`, this.limits.ms, (signal) => api(method, path, body, { target: this.target, signal }));
102
+ }
103
+ /** One upload under a deadline that grows with its bytes. */
104
+ upload(path, contentType, body) {
105
+ // The bytes fetch sends: a JSON chunk's UTF-8, never its UTF-16 length (non-ASCII text runs up to 3× longer).
106
+ const bytes = typeof body === 'string' ? new TextEncoder().encode(body).byteLength : body.size;
107
+ const ms = this.limits.ms + Math.ceil(bytes / this.limits.bytesPerMs);
108
+ return deadline(`POST ${path}`, ms, (signal) => uploadTo(path, contentType, body, this.target, signal));
109
+ }
110
+ /** A file has not landed yet: the attachment leg is what a retry resumes. */
111
+ get filesPending() {
112
+ return this.filesDone.size < this.files.length;
36
113
  }
37
114
  /** Run the legs from wherever the last run stopped; rejects with the failing leg's error. */
38
115
  async run(env) {
39
- const to = { target: this.target };
40
116
  const edits = { title: env.title, description: env.description, markers: env.markers, notify: env.notify ?? false };
41
117
  const editsKey = JSON.stringify(edits);
42
118
  if (!this.id) {
43
- const res = await api('POST', '/api/v1/reports', env, to);
119
+ const res = await this.call('POST', '/api/v1/reports', env).catch((e) => {
120
+ // A vitrinka older than the report type refuses the unknown field: the hint is optional, the report is not.
121
+ if (env.type === undefined || !(e instanceof VitrinkaApiError) || e.status !== 400 || !/\btype\b/.test(e.message))
122
+ throw e;
123
+ console.warn('vitrinka: this server takes no report type yet — sending the report without it');
124
+ const { type: _dropped, ...rest } = env;
125
+ return this.call('POST', '/api/v1/reports', rest);
126
+ });
44
127
  if (typeof res.id !== 'string' || !res.id)
45
128
  throw new Error('vitrinka: the server filed the report without an id');
46
129
  this.id = res.id;
@@ -48,9 +131,10 @@ export class ReportJob {
48
131
  this.sent = editsKey;
49
132
  }
50
133
  else if (this.sent !== editsKey) {
51
- await api('PATCH', `/api/v1/reports/${encodeURIComponent(this.id)}`, edits, to);
134
+ await this.call('PATCH', `/api/v1/reports/${encodeURIComponent(this.id)}`, edits);
52
135
  this.sent = editsKey;
53
136
  }
137
+ await this.sendFiles();
54
138
  if (!this.skipCapture) {
55
139
  try {
56
140
  await this.sendCapture();
@@ -62,19 +146,35 @@ export class ReportJob {
62
146
  this.skipCapture = true;
63
147
  }
64
148
  }
65
- const reply = await api('POST', `/api/v1/reports/${encodeURIComponent(this.id)}/submit`, {}, to);
149
+ const reply = await this.call('POST', `/api/v1/reports/${encodeURIComponent(this.id)}/submit`, {});
66
150
  return {
67
151
  status: reply.status === 'filed' ? 'filed' : 'quarantined',
68
152
  ...(typeof reply.reportUrl === 'string' && reply.reportUrl ? { reportUrl: reply.reportUrl } : {}),
69
153
  };
70
154
  }
155
+ async sendFiles() {
156
+ const id = encodeURIComponent(this.id);
157
+ for (const [i, f] of this.files.entries()) {
158
+ if (this.filesDone.has(i))
159
+ continue;
160
+ try {
161
+ await this.upload(`/api/v1/reports/${id}/attachment?name=${encodeURIComponent(f.name)}`, f.type || 'application/octet-stream', f);
162
+ }
163
+ catch (e) {
164
+ if (!(e instanceof VitrinkaApiError) || !permanentStatus(e.status))
165
+ throw e;
166
+ console.warn(`vitrinka: the server refused ${f.name} — the report goes without it`, e);
167
+ }
168
+ this.filesDone.add(i);
169
+ }
170
+ }
71
171
  async sendCapture() {
72
172
  const id = encodeURIComponent(this.id);
73
173
  const { chunks, truncated } = this.capture;
74
174
  for (const c of chunks) {
75
175
  if (this.blobKeys.has(c.seq))
76
176
  continue;
77
- const up = await uploadTo(`/api/v1/reports/${id}/chunk?seq=${c.seq}`, 'application/json', c.body, this.target);
177
+ const up = await this.upload(`/api/v1/reports/${id}/chunk?seq=${c.seq}`, 'application/json', c.body);
78
178
  if (!up.blobKey)
79
179
  throw new Error(`vitrinka: chunk ${c.seq} came back without a blob key`);
80
180
  this.blobKeys.set(c.seq, up.blobKey);
@@ -89,7 +189,7 @@ export class ReportJob {
89
189
  }));
90
190
  while (this.rowsPosted < rows.length) {
91
191
  const batch = rows.slice(this.rowsPosted, this.rowsPosted + EVENTS_PER_POST);
92
- await api('POST', `/api/v1/reports/${id}/events`, { events: batch }, { target: this.target });
192
+ await this.call('POST', `/api/v1/reports/${id}/events`, { events: batch });
93
193
  this.rowsPosted += batch.length;
94
194
  }
95
195
  }