@vitrinka/web 0.9.0 → 0.9.2
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/CHANGELOG.md +47 -0
- package/README.md +9 -2
- package/build/recorder/version.d.ts +2 -2
- package/build/recorder/version.js +1 -1
- package/build/report/face.d.ts +14 -0
- package/build/report/face.js +18 -0
- package/build/report/keybind.d.ts +2 -0
- package/build/report/keybind.js +4 -0
- package/build/report/reader.d.ts +19 -2
- package/build/report/reader.js +32 -3
- package/build/report/widget.d.ts +29 -6
- package/build/report/widget.js +96 -34
- package/build/report/wire.d.ts +37 -3
- package/build/report/wire.js +60 -11
- package/build/report-widget.mjs +5 -5
- package/package.json +1 -1
package/build/report/wire.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The report wire (vitrinka `docs/architecture/qa-studio.md` § "The report
|
|
3
3
|
* wire"), under `Authorization: Bearer <vkb_ key>`:
|
|
4
4
|
*
|
|
5
|
-
* POST /api/v1/reports envelope → {id, custody}
|
|
5
|
+
* POST /api/v1/reports envelope → {id, custody, memberError?}
|
|
6
6
|
* PATCH /api/v1/reports/{id} {title?, description?, markers?, notify?}
|
|
7
7
|
* POST /api/v1/reports/{id}/attachment?name=<name>
|
|
8
8
|
* one file, raw body under its own Content-Type → {id, name, size, type}
|
|
@@ -25,6 +25,13 @@
|
|
|
25
25
|
* pace, so only a stalled one runs out. A create whose answer was lost after
|
|
26
26
|
* the server stored it is created again by Try again: the same risk a dropped
|
|
27
27
|
* connection already carries.
|
|
28
|
+
*
|
|
29
|
+
* OPTIONAL FIELDS NEVER COST THE REPORT: a vitrinka older than a field refuses
|
|
30
|
+
* it by name (400, `unknown field "<name>"`), and the create goes again without
|
|
31
|
+
* each optional field it names — `type`, `memberToken` — once. `memberToken`
|
|
32
|
+
* proves this browser's vitrinka member link (vt-8020), so the member co-owns
|
|
33
|
+
* the report; `memberError` says the server did not take it, and the report
|
|
34
|
+
* files regardless.
|
|
28
35
|
*/
|
|
29
36
|
import { type ApiTarget } from '../recorder/api';
|
|
30
37
|
import { type BuiltCapture, type ConsoleEntry, type NetEntry } from './engine';
|
|
@@ -57,11 +64,26 @@ export interface ReportEnvelope {
|
|
|
57
64
|
notify?: boolean;
|
|
58
65
|
/** The reporter's own word for it (vt-8020 D11), absent when they picked none. */
|
|
59
66
|
type?: ReportKind;
|
|
67
|
+
/** The vitrinka member link this browser holds for the widget's base (face.ts memberTokenFor), absent without one: the member co-owns the report. */
|
|
68
|
+
memberToken?: string;
|
|
60
69
|
}
|
|
61
70
|
export interface SubmitReply {
|
|
62
71
|
status: 'filed' | 'quarantined';
|
|
63
72
|
reportUrl?: string;
|
|
64
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Hears the create's `memberError` — the server did not take the member link
|
|
76
|
+
* it carried (revoked, another workspace, no longer a member) — with that
|
|
77
|
+
* link's token, once, as soon as the create answers.
|
|
78
|
+
*/
|
|
79
|
+
export type MemberRefusal = (error: string, sent: string) => void;
|
|
80
|
+
/**
|
|
81
|
+
* The top-level field a vitrinka refused as unknown — a 400 whose body names
|
|
82
|
+
* it (`json: unknown field "<name>"`, its quotes escaped once more inside the
|
|
83
|
+
* JSON error) — else ''. A field merely listed among the accepted ones is
|
|
84
|
+
* never it.
|
|
85
|
+
*/
|
|
86
|
+
export declare function refusedField(e: unknown): string;
|
|
65
87
|
/** How long a leg may go unanswered: `ms` for any leg, plus one ms per `bytesPerMs` bytes an upload carries. */
|
|
66
88
|
export interface LegLimits {
|
|
67
89
|
ms: number;
|
|
@@ -111,8 +133,20 @@ export declare class ReportJob {
|
|
|
111
133
|
private upload;
|
|
112
134
|
/** A file has not landed yet: the attachment leg is what a retry resumes. */
|
|
113
135
|
get filesPending(): boolean;
|
|
114
|
-
/**
|
|
115
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Run the legs from wherever the last run stopped; rejects with the failing
|
|
138
|
+
* leg's error. `onMemberRefusal` hears the create's `memberError` the moment
|
|
139
|
+
* the create answers, so a later leg failing never holds it back.
|
|
140
|
+
*/
|
|
141
|
+
run(env: ReportEnvelope, onMemberRefusal?: MemberRefusal): Promise<SubmitReply>;
|
|
142
|
+
/**
|
|
143
|
+
* The create leg, answering with the member link the accepted body carried
|
|
144
|
+
* ('' none). A vitrinka older than an optional field refuses it by name;
|
|
145
|
+
* the reporter's word (`type`) and the member link (`memberToken`) are
|
|
146
|
+
* optional, the report is not, so it goes again without each field named,
|
|
147
|
+
* once. A refusal naming nothing still in the body fails the leg.
|
|
148
|
+
*/
|
|
149
|
+
private create;
|
|
116
150
|
private sendFiles;
|
|
117
151
|
private sendCapture;
|
|
118
152
|
}
|
package/build/report/wire.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The report wire (vitrinka `docs/architecture/qa-studio.md` § "The report
|
|
3
3
|
* wire"), under `Authorization: Bearer <vkb_ key>`:
|
|
4
4
|
*
|
|
5
|
-
* POST /api/v1/reports envelope → {id, custody}
|
|
5
|
+
* POST /api/v1/reports envelope → {id, custody, memberError?}
|
|
6
6
|
* PATCH /api/v1/reports/{id} {title?, description?, markers?, notify?}
|
|
7
7
|
* POST /api/v1/reports/{id}/attachment?name=<name>
|
|
8
8
|
* one file, raw body under its own Content-Type → {id, name, size, type}
|
|
@@ -25,9 +25,27 @@
|
|
|
25
25
|
* pace, so only a stalled one runs out. A create whose answer was lost after
|
|
26
26
|
* the server stored it is created again by Try again: the same risk a dropped
|
|
27
27
|
* connection already carries.
|
|
28
|
+
*
|
|
29
|
+
* OPTIONAL FIELDS NEVER COST THE REPORT: a vitrinka older than a field refuses
|
|
30
|
+
* it by name (400, `unknown field "<name>"`), and the create goes again without
|
|
31
|
+
* each optional field it names — `type`, `memberToken` — once. `memberToken`
|
|
32
|
+
* proves this browser's vitrinka member link (vt-8020), so the member co-owns
|
|
33
|
+
* the report; `memberError` says the server did not take it, and the report
|
|
34
|
+
* files regardless.
|
|
28
35
|
*/
|
|
29
36
|
import { api, permanentStatus, uploadTo, VitrinkaApiError } from '../recorder/api';
|
|
30
37
|
import { EVENTS_PER_POST } from './engine';
|
|
38
|
+
/**
|
|
39
|
+
* The top-level field a vitrinka refused as unknown — a 400 whose body names
|
|
40
|
+
* it (`json: unknown field "<name>"`, its quotes escaped once more inside the
|
|
41
|
+
* JSON error) — else ''. A field merely listed among the accepted ones is
|
|
42
|
+
* never it.
|
|
43
|
+
*/
|
|
44
|
+
export function refusedField(e) {
|
|
45
|
+
if (!(e instanceof VitrinkaApiError) || e.status !== 400)
|
|
46
|
+
return '';
|
|
47
|
+
return /unknown field \\?"(\w+)\\?"/.exec(e.message)?.[1] ?? '';
|
|
48
|
+
}
|
|
31
49
|
/** 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
50
|
export const LEG_LIMITS = { ms: 30_000, bytesPerMs: 32 };
|
|
33
51
|
/** A leg ran past its deadline: retryable, never a refusal for good. */
|
|
@@ -111,24 +129,23 @@ export class ReportJob {
|
|
|
111
129
|
get filesPending() {
|
|
112
130
|
return this.filesDone.size < this.files.length;
|
|
113
131
|
}
|
|
114
|
-
/**
|
|
115
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Run the legs from wherever the last run stopped; rejects with the failing
|
|
134
|
+
* leg's error. `onMemberRefusal` hears the create's `memberError` the moment
|
|
135
|
+
* the create answers, so a later leg failing never holds it back.
|
|
136
|
+
*/
|
|
137
|
+
async run(env, onMemberRefusal) {
|
|
116
138
|
const edits = { title: env.title, description: env.description, markers: env.markers, notify: env.notify ?? false };
|
|
117
139
|
const editsKey = JSON.stringify(edits);
|
|
118
140
|
if (!this.id) {
|
|
119
|
-
const res = await this.
|
|
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
|
-
});
|
|
141
|
+
const { res, memberSent } = await this.create(env);
|
|
127
142
|
if (typeof res.id !== 'string' || !res.id)
|
|
128
143
|
throw new Error('vitrinka: the server filed the report without an id');
|
|
129
144
|
this.id = res.id;
|
|
130
145
|
this.custody = res.custody === 'direct' ? 'direct' : 'quarantined';
|
|
131
146
|
this.sent = editsKey;
|
|
147
|
+
if (typeof res.memberError === 'string' && res.memberError)
|
|
148
|
+
onMemberRefusal?.(res.memberError, memberSent);
|
|
132
149
|
}
|
|
133
150
|
else if (this.sent !== editsKey) {
|
|
134
151
|
await this.call('PATCH', `/api/v1/reports/${encodeURIComponent(this.id)}`, edits);
|
|
@@ -152,6 +169,38 @@ export class ReportJob {
|
|
|
152
169
|
...(typeof reply.reportUrl === 'string' && reply.reportUrl ? { reportUrl: reply.reportUrl } : {}),
|
|
153
170
|
};
|
|
154
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* The create leg, answering with the member link the accepted body carried
|
|
174
|
+
* ('' none). A vitrinka older than an optional field refuses it by name;
|
|
175
|
+
* the reporter's word (`type`) and the member link (`memberToken`) are
|
|
176
|
+
* optional, the report is not, so it goes again without each field named,
|
|
177
|
+
* once. A refusal naming nothing still in the body fails the leg.
|
|
178
|
+
*/
|
|
179
|
+
async create(env) {
|
|
180
|
+
let body = env;
|
|
181
|
+
for (;;) {
|
|
182
|
+
try {
|
|
183
|
+
const res = await this.call('POST', '/api/v1/reports', body);
|
|
184
|
+
return { res, memberSent: body.memberToken ?? '' };
|
|
185
|
+
}
|
|
186
|
+
catch (e) {
|
|
187
|
+
const field = refusedField(e);
|
|
188
|
+
if (field === 'type' && body.type !== undefined) {
|
|
189
|
+
console.warn('vitrinka: this server takes no report type yet — sending the report without it');
|
|
190
|
+
const { type: _dropped, ...rest } = body;
|
|
191
|
+
body = rest;
|
|
192
|
+
}
|
|
193
|
+
else if (field === 'memberToken' && body.memberToken !== undefined) {
|
|
194
|
+
console.warn('vitrinka: this server takes no member link yet — sending the report without it');
|
|
195
|
+
const { memberToken: _dropped, ...rest } = body;
|
|
196
|
+
body = rest;
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
throw e;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
155
204
|
async sendFiles() {
|
|
156
205
|
const id = encodeURIComponent(this.id);
|
|
157
206
|
for (const [i, f] of this.files.entries()) {
|