@vitrinka/web 0.3.4 → 0.4.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/CHANGELOG.md +60 -0
- package/README.md +59 -5
- package/build/hud.d.ts +1 -1
- package/build/hud.iife.js +46 -9
- package/build/protocol/index.d.ts +55 -4
- package/build/protocol/index.js +4 -2
- package/build/recorder/api.d.ts +25 -5
- package/build/recorder/api.js +21 -9
- package/build/recorder/attachments.d.ts +19 -0
- package/build/recorder/attachments.js +31 -0
- package/build/recorder/hud/Hud.d.ts +1 -1
- package/build/recorder/hud/Hud.js +43 -10
- package/build/recorder/hud/Sheet.d.ts +40 -5
- package/build/recorder/hud/Sheet.js +134 -8
- package/build/recorder/hud/attach.d.ts +26 -0
- package/build/recorder/hud/attach.js +136 -0
- package/build/recorder/hud/controller.d.ts +31 -3
- package/build/recorder/hud/controller.js +1 -1
- package/build/recorder/hud/host.js +2 -0
- package/build/recorder/hud/icons.d.ts +3 -0
- package/build/recorder/hud/icons.js +7 -0
- package/build/recorder/hud/layer.d.ts +4 -1
- package/build/recorder/hud/layer.js +11 -3
- package/build/recorder/hud/resize.d.ts +83 -0
- package/build/recorder/hud/resize.js +236 -0
- package/build/recorder/hud/styles.d.ts +1 -1
- package/build/recorder/hud/styles.js +38 -1
- package/build/recorder/link.d.ts +4 -1
- package/build/recorder/link.js +6 -2
- package/build/recorder/me.d.ts +7 -0
- package/build/recorder/me.js +62 -12
- package/build/recorder/page-controller.js +4 -3
- package/build/recorder/queue.d.ts +33 -3
- package/build/recorder/queue.js +404 -24
- package/build/recorder/report.d.ts +9 -0
- package/build/recorder/report.js +46 -4
- package/build/recorder/session.d.ts +13 -5
- package/build/recorder/session.js +42 -12
- package/build/recorder/storage/blobs.d.ts +32 -0
- package/build/recorder/storage/blobs.js +83 -0
- package/build/recorder/storage/index.js +3 -2
- package/package.json +1 -1
package/build/recorder/report.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { api, fetchPolicy, uploadChunk } from './api';
|
|
1
|
+
import { api, fetchPolicy, uploadChunk, uploadImage } from './api';
|
|
2
|
+
import { stageAttachments } from './attachments';
|
|
2
3
|
import { setRedactionPolicy } from './capture/redact';
|
|
3
4
|
import { checkoutRRWeb } from './capture/rrweb';
|
|
4
5
|
import { recorderConfig, vitrinkaLinked } from './config';
|
|
@@ -12,6 +13,8 @@ let pills = 0;
|
|
|
12
13
|
let armed = false;
|
|
13
14
|
let generation = 0;
|
|
14
15
|
let arming = Promise.resolve();
|
|
16
|
+
/** The armed buffer's policy read answered `attachments: true`. */
|
|
17
|
+
let flightAttachments = false;
|
|
15
18
|
/** A mounted pill wants the flight recorder; returns the release. */
|
|
16
19
|
export function wantFlight() {
|
|
17
20
|
pills++;
|
|
@@ -39,10 +42,11 @@ export function syncFlight() {
|
|
|
39
42
|
const gen = ++generation;
|
|
40
43
|
setRedactionPolicy(null);
|
|
41
44
|
// fetchPolicy never rejects: null is the engine's safe defaults.
|
|
42
|
-
arming = fetchPolicy().then((policy) => {
|
|
45
|
+
arming = fetchPolicy().then(({ policy, attachments }) => {
|
|
43
46
|
if (!armed || gen !== generation)
|
|
44
47
|
return;
|
|
45
48
|
setRedactionPolicy(policy);
|
|
49
|
+
flightAttachments = attachments;
|
|
46
50
|
startFlightBuffer();
|
|
47
51
|
notify();
|
|
48
52
|
});
|
|
@@ -50,6 +54,7 @@ export function syncFlight() {
|
|
|
50
54
|
else if (!want && armed) {
|
|
51
55
|
armed = false;
|
|
52
56
|
generation++;
|
|
57
|
+
flightAttachments = false;
|
|
53
58
|
stopFlightBuffer();
|
|
54
59
|
// A session that just started owns the rules now; only an idle page resets them.
|
|
55
60
|
if (getState() === null)
|
|
@@ -64,6 +69,17 @@ export function canReport() {
|
|
|
64
69
|
return !rec.paused && !rec.dead;
|
|
65
70
|
return flightWanted() && flightActive();
|
|
66
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Do the sheets take images now (recorder attachments D6)? Recording: the
|
|
74
|
+
* session's policy read said so. Idle: the flight recorder's did — only the
|
|
75
|
+
* bug report sheet opens then.
|
|
76
|
+
*/
|
|
77
|
+
export function canAttach() {
|
|
78
|
+
const rec = getState();
|
|
79
|
+
if (rec)
|
|
80
|
+
return rec.attachments === true;
|
|
81
|
+
return flightAttachments && canReport();
|
|
82
|
+
}
|
|
67
83
|
let held = null;
|
|
68
84
|
let job = null;
|
|
69
85
|
let sending = false;
|
|
@@ -133,13 +149,25 @@ function buildJob(clip, note) {
|
|
|
133
149
|
const lastLane = clip.lanes.at(-1);
|
|
134
150
|
if (lastLane)
|
|
135
151
|
endMs = Math.max(endMs, Date.parse(lastLane.ts));
|
|
152
|
+
const sentAt = new Date().toISOString();
|
|
153
|
+
// Stamped at Send like the note, in its lane; only when the workspace takes them.
|
|
154
|
+
const images = (flightAttachments ? stageAttachments(note.attachments) : []).map((image) => ({
|
|
155
|
+
seq: ++seq,
|
|
156
|
+
ts: sentAt,
|
|
157
|
+
...tab,
|
|
158
|
+
...image,
|
|
159
|
+
}));
|
|
160
|
+
if (!flightAttachments && note.attachments?.length) {
|
|
161
|
+
console.warn('vitrinka: this workspace takes no attachments — the report is sent without its images');
|
|
162
|
+
}
|
|
136
163
|
return {
|
|
137
164
|
title: reportTitle(note.text),
|
|
138
165
|
events,
|
|
139
166
|
chunks,
|
|
167
|
+
images,
|
|
140
168
|
note: {
|
|
141
169
|
seq: ++seq,
|
|
142
|
-
ts:
|
|
170
|
+
ts: sentAt,
|
|
143
171
|
...tab,
|
|
144
172
|
kind: 'note',
|
|
145
173
|
payload: {
|
|
@@ -149,6 +177,7 @@ function buildJob(clip, note) {
|
|
|
149
177
|
annotate: true,
|
|
150
178
|
task: true,
|
|
151
179
|
route: currentRoute.pathname,
|
|
180
|
+
...(images.length ? { attachments: images.map((image) => image.seq) } : {}),
|
|
152
181
|
},
|
|
153
182
|
},
|
|
154
183
|
durationMs: startMs !== undefined ? Math.max(0, endMs - startMs) : 0,
|
|
@@ -193,6 +222,15 @@ const steps = [
|
|
|
193
222
|
}
|
|
194
223
|
await postEvents(j.sessionId, rows);
|
|
195
224
|
},
|
|
225
|
+
async (j) => {
|
|
226
|
+
// The images the same way, through the screenshot leaf: bytes first, then their rows.
|
|
227
|
+
const rows = [];
|
|
228
|
+
for (const im of j.images) {
|
|
229
|
+
const up = await uploadImage(j.sessionId, im.seq, im.blob);
|
|
230
|
+
rows.push({ seq: im.seq, ts: im.ts, tabId: im.tabId, tabHost: im.tabHost, kind: 'attachment', payload: { ...im.payload }, blobKey: up.blobKey });
|
|
231
|
+
}
|
|
232
|
+
await postEvents(j.sessionId, rows);
|
|
233
|
+
},
|
|
196
234
|
(j) => postEvents(j.sessionId, [j.note]),
|
|
197
235
|
async (j) => {
|
|
198
236
|
const done = await api('PATCH', `/api/v1/sessions/${j.sessionId}`, { status: 'done' });
|
|
@@ -211,7 +249,10 @@ export async function sendReport(note) {
|
|
|
211
249
|
if (rec) {
|
|
212
250
|
if (rec.paused || rec.dead)
|
|
213
251
|
throw new Error('the recording is not capturing — resume it to report');
|
|
214
|
-
addAnnotation(note.text, note.rect ?? viewportRect(), note.selector, {
|
|
252
|
+
addAnnotation(note.text, note.rect ?? viewportRect(), note.selector, {
|
|
253
|
+
task: true,
|
|
254
|
+
...(note.attachments?.length ? { attachments: note.attachments } : {}),
|
|
255
|
+
});
|
|
215
256
|
return rec.boardUrl ? { boardUrl: rec.boardUrl } : {};
|
|
216
257
|
}
|
|
217
258
|
if (sending)
|
|
@@ -252,6 +293,7 @@ export async function sendReport(note) {
|
|
|
252
293
|
export function dropFlight() {
|
|
253
294
|
armed = false;
|
|
254
295
|
generation++;
|
|
296
|
+
flightAttachments = false;
|
|
255
297
|
arming = Promise.resolve();
|
|
256
298
|
held = null;
|
|
257
299
|
if (!sending)
|
|
@@ -13,13 +13,14 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { RedactionPolicy } from '@vitrinka/redact';
|
|
15
15
|
import type { SessionDone } from '../protocol';
|
|
16
|
+
import type { HudAttachment } from './hud/controller';
|
|
16
17
|
import { type SessionState } from './queue';
|
|
17
18
|
export { currentRoute, notify, subscribe } from './state';
|
|
18
19
|
export { onBeforeStop } from './queue';
|
|
19
20
|
export type { SessionDone } from '../protocol';
|
|
20
21
|
/** Sent as `meta.recorder`; bumped with the package version. */
|
|
21
|
-
export declare const RECORDER_VERSION = "0.
|
|
22
|
-
export declare const RECORDER_ID = "web/0.
|
|
22
|
+
export declare const RECORDER_VERSION = "0.4.0";
|
|
23
|
+
export declare const RECORDER_ID = "web/0.4.0";
|
|
23
24
|
/** What `POST /api/v1/sessions` answers (the fields this recorder keeps). */
|
|
24
25
|
export interface SessionOut {
|
|
25
26
|
id: string;
|
|
@@ -61,8 +62,14 @@ export declare function createSession(title: string, opts?: {
|
|
|
61
62
|
}): Promise<SessionOut>;
|
|
62
63
|
export declare function startSession(opts?: StartOptions): Promise<SessionState>;
|
|
63
64
|
export declare function togglePause(): Promise<boolean>;
|
|
64
|
-
/**
|
|
65
|
-
|
|
65
|
+
/**
|
|
66
|
+
* A plain note — `{text, route}`, the extension's shape. With attachments
|
|
67
|
+
* (recorder attachments) each image becomes an `attachment` event whose seq
|
|
68
|
+
* is allocated just before the note's, in this tab's lane, and the note
|
|
69
|
+
* lists them: `{text, route, attachments: [seq…]}`; `text` may then be
|
|
70
|
+
* empty. Their bytes upload through `/shot` before their rows ride (queue.ts).
|
|
71
|
+
*/
|
|
72
|
+
export declare function addNote(text: string, attachments?: readonly HudAttachment[]): void;
|
|
66
73
|
/** A rect in CSS pixels (viewport coordinates). */
|
|
67
74
|
export interface ViewRect {
|
|
68
75
|
x: number;
|
|
@@ -77,10 +84,11 @@ export declare function imagePixels(r: ViewRect): ViewRect;
|
|
|
77
84
|
* annotate: true}` (+ `task` when the tester chose the task destination);
|
|
78
85
|
* vitrinka projects it into a board annotation. `selector` is '' for a free
|
|
79
86
|
* region. The rect is in device pixels. An empty note is still a valid
|
|
80
|
-
* annotation, matching the extension.
|
|
87
|
+
* annotation, matching the extension. `attachments` ride as for `addNote`.
|
|
81
88
|
*/
|
|
82
89
|
export declare function addAnnotation(text: string, rect: ViewRect, selector: string, opts?: {
|
|
83
90
|
task?: boolean;
|
|
91
|
+
attachments?: readonly HudAttachment[];
|
|
84
92
|
}): void;
|
|
85
93
|
/**
|
|
86
94
|
* Hooks that run at the top of Stop, before the drain snapshot — the rrweb
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { api, fetchPolicy, permanentStatus, VitrinkaApiError } from './api';
|
|
2
|
+
import { stageAttachments } from './attachments';
|
|
2
3
|
import { redactUrl, setRedactionPolicy } from './capture/redact';
|
|
3
4
|
import { recorderConfig } from './config';
|
|
4
|
-
import { adoptStoredState, armReconcile, capturesSettled, disarmReconcile, drainBuffer, getState, markStopping, persistNow, pushEvent, queuedCount, REC_KEY, resetHealth, resetIdle, resetQueues, runBeforeStopHooks, setState, stoppingElsewhere, } from './queue';
|
|
5
|
+
import { adoptStoredState, armReconcile, capturesSettled, disarmReconcile, drainBuffer, getState, markStopping, persistNow, pruneBlobJournal, pushEvent, queuedCount, REC_KEY, resetHealth, resetIdle, resetQueues, runBeforeStopHooks, setState, stoppingElsewhere, } from './queue';
|
|
5
6
|
import { awaitBoard, boardUrlOf, forgetRecents, noteRecent, RECENTS_KEY, updateRecent } from './recents';
|
|
6
7
|
import { currentRoute, notify } from './state';
|
|
7
8
|
import { getRecorderStorage } from './storage';
|
|
@@ -9,11 +10,12 @@ import { recorderPeers, registerRecorderTab, waitForRecorderPeers } from './tabs
|
|
|
9
10
|
export { currentRoute, notify, subscribe } from './state';
|
|
10
11
|
export { onBeforeStop } from './queue';
|
|
11
12
|
/** Sent as `meta.recorder`; bumped with the package version. */
|
|
12
|
-
export const RECORDER_VERSION = '0.
|
|
13
|
+
export const RECORDER_VERSION = '0.4.0';
|
|
13
14
|
export const RECORDER_ID = `web/${RECORDER_VERSION}`;
|
|
14
15
|
/**
|
|
15
16
|
* Re-apply a RECOVERED session's redaction policy after a reload — and
|
|
16
|
-
* re-FETCH it when the original fetch never settled (`policy === undefined`)
|
|
17
|
+
* re-FETCH it when the original fetch never settled (`policy === undefined`),
|
|
18
|
+
* with the `attachments` answer the same read carries.
|
|
17
19
|
*/
|
|
18
20
|
let policyRecoveryInFlight = false;
|
|
19
21
|
export function recoverRedactionPolicy() {
|
|
@@ -27,14 +29,15 @@ export function recoverRedactionPolicy() {
|
|
|
27
29
|
return;
|
|
28
30
|
policyRecoveryInFlight = true;
|
|
29
31
|
void fetchPolicy()
|
|
30
|
-
.then((policy) => {
|
|
32
|
+
.then(({ policy, attachments }) => {
|
|
31
33
|
const live = getState();
|
|
32
34
|
if (live?.sessionId !== rec.sessionId)
|
|
33
35
|
return;
|
|
34
36
|
if (live.policy !== undefined)
|
|
35
37
|
return;
|
|
36
38
|
setRedactionPolicy(policy);
|
|
37
|
-
setState({ ...live, policy });
|
|
39
|
+
setState({ ...live, policy, attachments });
|
|
40
|
+
notify();
|
|
38
41
|
})
|
|
39
42
|
.finally(() => {
|
|
40
43
|
policyRecoveryInFlight = false;
|
|
@@ -131,12 +134,14 @@ export async function startSession(opts = {}) {
|
|
|
131
134
|
...(opts.environment ? { environment: opts.environment } : {}),
|
|
132
135
|
...(opts.driver ? { meta: { driver: opts.driver } } : {}),
|
|
133
136
|
});
|
|
134
|
-
void policyPromise.then((policy) => {
|
|
137
|
+
void policyPromise.then(({ policy, attachments }) => {
|
|
135
138
|
const rec = getState();
|
|
136
139
|
if (rec?.sessionId !== ses.id)
|
|
137
140
|
return;
|
|
138
141
|
setRedactionPolicy(policy);
|
|
139
|
-
setState({ ...rec, policy });
|
|
142
|
+
setState({ ...rec, policy, attachments });
|
|
143
|
+
// The sheets offer images from here on (canAttach).
|
|
144
|
+
notify();
|
|
140
145
|
});
|
|
141
146
|
setState({
|
|
142
147
|
sessionId: ses.id,
|
|
@@ -152,6 +157,8 @@ export async function startSession(opts = {}) {
|
|
|
152
157
|
resetQueues();
|
|
153
158
|
resetHealth();
|
|
154
159
|
resetIdle();
|
|
160
|
+
// Images an earlier session left in the blob journal (a tab closed mid-upload) never go now.
|
|
161
|
+
void pruneBlobJournal();
|
|
155
162
|
noteRecent({
|
|
156
163
|
sessionId: ses.id,
|
|
157
164
|
title: ses.title,
|
|
@@ -205,9 +212,29 @@ export async function togglePause() {
|
|
|
205
212
|
return rec.paused;
|
|
206
213
|
}
|
|
207
214
|
const route = () => ({ tabId: currentRoute.tabId, tabHost: currentRoute.tabHost });
|
|
208
|
-
/**
|
|
209
|
-
|
|
210
|
-
|
|
215
|
+
/**
|
|
216
|
+
* The images a note may carry: none unless this session's policy read said
|
|
217
|
+
* `attachments: true` (the workspace switch, D6) — the HUD offers none then,
|
|
218
|
+
* and another caller's are not uploaded against it.
|
|
219
|
+
*/
|
|
220
|
+
function imagesOf(list) {
|
|
221
|
+
if (!list?.length)
|
|
222
|
+
return [];
|
|
223
|
+
if (getState()?.attachments !== true) {
|
|
224
|
+
console.warn('vitrinka: this session takes no attachments — the note is sent without its images');
|
|
225
|
+
return [];
|
|
226
|
+
}
|
|
227
|
+
return stageAttachments(list);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* A plain note — `{text, route}`, the extension's shape. With attachments
|
|
231
|
+
* (recorder attachments) each image becomes an `attachment` event whose seq
|
|
232
|
+
* is allocated just before the note's, in this tab's lane, and the note
|
|
233
|
+
* lists them: `{text, route, attachments: [seq…]}`; `text` may then be
|
|
234
|
+
* empty. Their bytes upload through `/shot` before their rows ride (queue.ts).
|
|
235
|
+
*/
|
|
236
|
+
export function addNote(text, attachments) {
|
|
237
|
+
pushEvent('note', { text, route: currentRoute.pathname }, route(), imagesOf(attachments));
|
|
211
238
|
}
|
|
212
239
|
/** Scale a viewport rect to device pixels — the extension's `imageRect` space. */
|
|
213
240
|
export function imagePixels(r) {
|
|
@@ -224,7 +251,7 @@ export function imagePixels(r) {
|
|
|
224
251
|
* annotate: true}` (+ `task` when the tester chose the task destination);
|
|
225
252
|
* vitrinka projects it into a board annotation. `selector` is '' for a free
|
|
226
253
|
* region. The rect is in device pixels. An empty note is still a valid
|
|
227
|
-
* annotation, matching the extension.
|
|
254
|
+
* annotation, matching the extension. `attachments` ride as for `addNote`.
|
|
228
255
|
*/
|
|
229
256
|
export function addAnnotation(text, rect, selector, opts = {}) {
|
|
230
257
|
pushEvent('note', {
|
|
@@ -234,7 +261,7 @@ export function addAnnotation(text, rect, selector, opts = {}) {
|
|
|
234
261
|
annotate: true,
|
|
235
262
|
route: currentRoute.pathname,
|
|
236
263
|
...(opts.task ? { task: true } : {}),
|
|
237
|
-
}, route());
|
|
264
|
+
}, route(), imagesOf(opts.attachments));
|
|
238
265
|
}
|
|
239
266
|
/**
|
|
240
267
|
* Hooks that run at the top of Stop, before the drain snapshot — the rrweb
|
|
@@ -271,6 +298,7 @@ async function finishStop(rec, durationMs, peers) {
|
|
|
271
298
|
setState(null);
|
|
272
299
|
setRedactionPolicy(null);
|
|
273
300
|
resetQueues();
|
|
301
|
+
void pruneBlobJournal(rec.sessionId);
|
|
274
302
|
notify();
|
|
275
303
|
throw new Error(`${reason || 'session rejected by the server'} — recording ended locally` +
|
|
276
304
|
(kept ? `; ${kept} undelivered item(s) discarded` : ''));
|
|
@@ -324,6 +352,8 @@ async function finishStop(rec, durationMs, peers) {
|
|
|
324
352
|
setRedactionPolicy(null);
|
|
325
353
|
resetQueues();
|
|
326
354
|
}
|
|
355
|
+
// Every image of it is the server's (or never will be): the journal lets go of the session.
|
|
356
|
+
void pruneBlobJournal(rec.sessionId);
|
|
327
357
|
notify();
|
|
328
358
|
return done;
|
|
329
359
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The blob journal (recorder attachments D4): the bytes of an attached image
|
|
3
|
+
* waiting for upload, kept in IndexedDB so a queued image survives a tab
|
|
4
|
+
* reload the way the KV store's event tail does — the KV store (localStorage,
|
|
5
|
+
* a few MiB) cannot hold image bytes. Keys are `<sessionId>/<document>.<n>`;
|
|
6
|
+
* the queue writes one before the image's event is journaled, reads it back
|
|
7
|
+
* to upload after a reload, and deletes it once the server acknowledged the
|
|
8
|
+
* image's event. Shared by every tab of the origin, like the KV store.
|
|
9
|
+
*
|
|
10
|
+
* Where IndexedDB is absent the journal is memory; where it refuses to open
|
|
11
|
+
* or write (a storage-disabled profile, some private modes, the quota) its
|
|
12
|
+
* calls reject and the queue keeps the bytes in memory. Either way the image
|
|
13
|
+
* still uploads from this document, only the reload guarantee is lost — and
|
|
14
|
+
* the recorder says so.
|
|
15
|
+
*/
|
|
16
|
+
export interface RecorderBlobStore {
|
|
17
|
+
/** Survives a reload (false for the memory fallback). */
|
|
18
|
+
readonly durable: boolean;
|
|
19
|
+
put(key: string, blob: Blob): Promise<void>;
|
|
20
|
+
/** null when the key was never written or is gone. */
|
|
21
|
+
get(key: string): Promise<Blob | null>;
|
|
22
|
+
delete(key: string): Promise<void>;
|
|
23
|
+
keys(): Promise<string[]>;
|
|
24
|
+
}
|
|
25
|
+
/** The active journal; lazily IndexedDB, else memory. */
|
|
26
|
+
export declare function getRecorderBlobStore(): RecorderBlobStore;
|
|
27
|
+
/** Install a journal (tests; a host with its own store). */
|
|
28
|
+
export declare function configureRecorderBlobStore(store: RecorderBlobStore): void;
|
|
29
|
+
/** In-memory journal — tests, and the non-durable fallback. */
|
|
30
|
+
export declare function memoryBlobStore(): RecorderBlobStore;
|
|
31
|
+
/** Test-only: forget the installed journal. */
|
|
32
|
+
export declare function __resetBlobStoreForTests(): void;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const DB = 'vitrinka.recorder.blobs';
|
|
2
|
+
const STORE = 'blobs';
|
|
3
|
+
let current = null;
|
|
4
|
+
/** The active journal; lazily IndexedDB, else memory. */
|
|
5
|
+
export function getRecorderBlobStore() {
|
|
6
|
+
if (!current)
|
|
7
|
+
current = typeof indexedDB === 'undefined' ? memoryBlobStore() : indexedDbBlobStore();
|
|
8
|
+
return current;
|
|
9
|
+
}
|
|
10
|
+
/** Install a journal (tests; a host with its own store). */
|
|
11
|
+
export function configureRecorderBlobStore(store) {
|
|
12
|
+
current = store;
|
|
13
|
+
}
|
|
14
|
+
/** In-memory journal — tests, and the non-durable fallback. */
|
|
15
|
+
export function memoryBlobStore() {
|
|
16
|
+
const m = new Map();
|
|
17
|
+
return {
|
|
18
|
+
durable: false,
|
|
19
|
+
put: async (k, b) => void m.set(k, b),
|
|
20
|
+
get: async (k) => m.get(k) ?? null,
|
|
21
|
+
delete: async (k) => void m.delete(k),
|
|
22
|
+
keys: async () => [...m.keys()],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function indexedDbBlobStore() {
|
|
26
|
+
let db;
|
|
27
|
+
const open = () => {
|
|
28
|
+
db ??= new Promise((resolve, reject) => {
|
|
29
|
+
const request = indexedDB.open(DB, 1);
|
|
30
|
+
request.onupgradeneeded = () => request.result.createObjectStore(STORE);
|
|
31
|
+
request.onerror = () => reject(request.error ?? new Error('vitrinka: blob journal did not open'));
|
|
32
|
+
request.onsuccess = () => {
|
|
33
|
+
const opened = request.result;
|
|
34
|
+
opened.onversionchange = () => {
|
|
35
|
+
opened.close();
|
|
36
|
+
db = undefined;
|
|
37
|
+
};
|
|
38
|
+
// Closed by the browser (site data cleared, a lost IndexedDB server): the next call reopens.
|
|
39
|
+
opened.onclose = () => {
|
|
40
|
+
db = undefined;
|
|
41
|
+
};
|
|
42
|
+
resolve(opened);
|
|
43
|
+
};
|
|
44
|
+
}).catch((error) => {
|
|
45
|
+
db = undefined;
|
|
46
|
+
throw error;
|
|
47
|
+
});
|
|
48
|
+
return db;
|
|
49
|
+
};
|
|
50
|
+
const run = async (mode, op) => {
|
|
51
|
+
const conn = open();
|
|
52
|
+
let tx;
|
|
53
|
+
try {
|
|
54
|
+
tx = (await conn).transaction(STORE, mode);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
// A connection that closed without a close event (Safari) refuses every transaction: reopen next time.
|
|
58
|
+
if (db === conn)
|
|
59
|
+
db = undefined;
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
const request = op(tx.objectStore(STORE));
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
// A write counts once its transaction commits, not when the request succeeds.
|
|
65
|
+
tx.oncomplete = () => resolve(request.result);
|
|
66
|
+
tx.onabort = tx.onerror = () => reject(tx.error ?? request.error ?? new Error('vitrinka: blob journal transaction failed'));
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
durable: true,
|
|
71
|
+
put: async (k, b) => void (await run('readwrite', (s) => s.put(b, k))),
|
|
72
|
+
get: async (k) => {
|
|
73
|
+
const v = await run('readonly', (s) => s.get(k));
|
|
74
|
+
return v instanceof Blob ? v : null;
|
|
75
|
+
},
|
|
76
|
+
delete: async (k) => void (await run('readwrite', (s) => s.delete(k))),
|
|
77
|
+
keys: async () => (await run('readonly', (s) => s.getAllKeys())).filter((k) => typeof k === 'string'),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** Test-only: forget the installed journal. */
|
|
81
|
+
export function __resetBlobStoreForTests() {
|
|
82
|
+
current = null;
|
|
83
|
+
}
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
* document, only the reload-survival guarantee is lost — and it says so once.
|
|
12
12
|
*/
|
|
13
13
|
import { withRecorderLock } from './lock';
|
|
14
|
-
// Keys land as `vitrinka.recorder.<key>`: rec · buffer · chunks ·
|
|
15
|
-
// recorder) and dock · prefs · me · recents (the HUD).
|
|
14
|
+
// Keys land as `vitrinka.recorder.<key>`: rec · buffer · chunks · images ·
|
|
15
|
+
// blobs · link (the recorder) and dock · prefs · me · recents (the HUD). An
|
|
16
|
+
// attached image's bytes live in the blob journal (./blobs, IndexedDB).
|
|
16
17
|
const PREFIX = 'vitrinka.recorder.';
|
|
17
18
|
let current = null;
|
|
18
19
|
let used = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitrinka/web",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "vitrinka toolkit for React DOM apps — the journey recorder: capture manual-testing sessions (rrweb DOM stream, clicks, navigation, network, console, notes) straight into vitrinka boards.",
|
|
5
5
|
"license": "Elastic-2.0",
|
|
6
6
|
"repository": {
|