@vitrinka/web 0.3.3 → 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 +82 -0
- package/README.md +77 -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 +42 -11
- package/build/recorder/queue.js +640 -47
- package/build/recorder/report.d.ts +9 -0
- package/build/recorder/report.js +46 -4
- package/build/recorder/session.d.ts +18 -6
- package/build/recorder/session.js +59 -29
- package/build/recorder/storage/blobs.d.ts +32 -0
- package/build/recorder/storage/blobs.js +83 -0
- package/build/recorder/storage/index.d.ts +4 -13
- package/build/recorder/storage/index.js +12 -6
- package/build/recorder/storage/lock.d.ts +2 -0
- package/build/recorder/storage/lock.js +48 -0
- package/build/recorder/tabs.d.ts +8 -0
- package/build/recorder/tabs.js +137 -0
- package/package.json +1 -1
package/build/recorder/me.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* GET /api/v1/recorder/me → {kind, workspace, user, project, label, prefs}
|
|
5
5
|
* PATCH /api/v1/recorder/me {prefs: {size?, verbose?}} → the same envelope
|
|
6
|
+
* PATCH /api/v1/recorder/me {prefs: {sheetW?, sheetH?}} → the same envelope
|
|
6
7
|
*
|
|
7
8
|
* Prefs live in the recorder storage first (`prefs`): the first paint, an
|
|
8
9
|
* offline page and a key build (`prefs: null`, PATCH answers 409) all read the
|
|
@@ -10,6 +11,12 @@
|
|
|
10
11
|
* or a network error means a server too old for the route or an offline one:
|
|
11
12
|
* the local copy stands, said once. A 401 keeps the session doors' semantics
|
|
12
13
|
* (api.ts forgets the link).
|
|
14
|
+
*
|
|
15
|
+
* The sheet size (`sheetW`/`sheetH`, CSS px 0..1600, 0 = the HUD's default)
|
|
16
|
+
* rides its OWN PATCH. A server that predates it answers that one 422: the
|
|
17
|
+
* size then stays on this device for the document's lifetime (never asked
|
|
18
|
+
* again, never an error to show), and an answer without the fields never
|
|
19
|
+
* resets the local size — size/verbose sync as before.
|
|
13
20
|
*/
|
|
14
21
|
import { DEFAULT_PREFS } from './hud/controller';
|
|
15
22
|
import { api, VitrinkaApiError } from './api';
|
|
@@ -19,6 +26,12 @@ import { getRecorderStorage } from './storage';
|
|
|
19
26
|
const PREFS_KEY = 'prefs';
|
|
20
27
|
const ME_KEY = 'me';
|
|
21
28
|
const SIZES = ['sm', 'md', 'lg'];
|
|
29
|
+
/** The largest sheet size the server stores. */
|
|
30
|
+
const SHEET_PX_MAX = 1600;
|
|
31
|
+
/** A sheet size: a finite number ≥ 0 (within what the server stores), else 0 = the default. */
|
|
32
|
+
function sheetPx(v) {
|
|
33
|
+
return typeof v === 'number' && Number.isFinite(v) && v >= 0 ? Math.min(v, SHEET_PX_MAX) : 0;
|
|
34
|
+
}
|
|
22
35
|
function parsePrefs(raw) {
|
|
23
36
|
if (!raw || typeof raw !== 'object')
|
|
24
37
|
return null;
|
|
@@ -26,6 +39,8 @@ function parsePrefs(raw) {
|
|
|
26
39
|
return {
|
|
27
40
|
size: SIZES.includes(o.size) ? o.size : DEFAULT_PREFS.size,
|
|
28
41
|
verbose: typeof o.verbose === 'boolean' ? o.verbose : DEFAULT_PREFS.verbose,
|
|
42
|
+
sheetW: sheetPx(o.sheetW),
|
|
43
|
+
sheetH: sheetPx(o.sheetH),
|
|
29
44
|
};
|
|
30
45
|
}
|
|
31
46
|
function readJson(key) {
|
|
@@ -87,6 +102,21 @@ function noteUnavailable(e) {
|
|
|
87
102
|
warned = true;
|
|
88
103
|
console.warn('vitrinka: /recorder/me unavailable — HUD prefs stay on this device', e);
|
|
89
104
|
}
|
|
105
|
+
/** A 422 to the sheet-size PATCH said the server predates it: kept local, not sent again this document. */
|
|
106
|
+
let sheetLocal = false;
|
|
107
|
+
/**
|
|
108
|
+
* The server's prefs, keeping the local sheet size where the answer has none
|
|
109
|
+
* (a server before sheetW/sheetH) or this document stopped sending it.
|
|
110
|
+
*/
|
|
111
|
+
function withLocalSheet(server, raw) {
|
|
112
|
+
const o = raw;
|
|
113
|
+
const local = cachedPrefs();
|
|
114
|
+
return {
|
|
115
|
+
...server,
|
|
116
|
+
sheetW: !sheetLocal && typeof o.sheetW === 'number' ? server.sheetW : local.sheetW,
|
|
117
|
+
sheetH: !sheetLocal && typeof o.sheetH === 'number' ? server.sheetH : local.sheetH,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
90
120
|
function isMe(o) {
|
|
91
121
|
if (!o || typeof o !== 'object')
|
|
92
122
|
return false;
|
|
@@ -117,7 +147,7 @@ function adopt(me, gen) {
|
|
|
117
147
|
write(ME_KEY, account);
|
|
118
148
|
const server = parsePrefs(me.prefs);
|
|
119
149
|
if (server && gen === edits)
|
|
120
|
-
storePrefs(server);
|
|
150
|
+
storePrefs(withLocalSheet(server, me.prefs));
|
|
121
151
|
notify();
|
|
122
152
|
return account;
|
|
123
153
|
}
|
|
@@ -143,23 +173,42 @@ export async function fetchMe() {
|
|
|
143
173
|
* account) and an unavailable server keep it local. Never rejects.
|
|
144
174
|
*/
|
|
145
175
|
export async function savePrefs(patch) {
|
|
146
|
-
const
|
|
176
|
+
const { sheetW, sheetH, ...hud } = patch;
|
|
177
|
+
const sheet = {
|
|
178
|
+
...(sheetW === undefined ? {} : { sheetW: sheetPx(sheetW) }),
|
|
179
|
+
...(sheetH === undefined ? {} : { sheetH: sheetPx(sheetH) }),
|
|
180
|
+
};
|
|
181
|
+
const next = { ...cachedPrefs(), ...hud, ...sheet };
|
|
147
182
|
storePrefs(next);
|
|
148
183
|
const gen = ++edits;
|
|
149
184
|
notify();
|
|
150
185
|
if (!vitrinkaLinked() || unavailable || cachedAccount()?.kind === 'key')
|
|
151
186
|
return next;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
187
|
+
// One PATCH per part: a server before the sheet size answers 422 for a body
|
|
188
|
+
// naming it, which must never cost size/verbose their server copy.
|
|
189
|
+
const parts = [hud, sheetLocal ? {} : sheet].filter((p) => Object.values(p).some((v) => v !== undefined));
|
|
190
|
+
let answer;
|
|
191
|
+
for (const prefs of parts) {
|
|
192
|
+
try {
|
|
193
|
+
answer = await api('PATCH', '/api/v1/recorder/me', { prefs });
|
|
194
|
+
}
|
|
195
|
+
catch (e) {
|
|
196
|
+
if (e instanceof VitrinkaApiError && e.status === 409)
|
|
197
|
+
return next;
|
|
198
|
+
if (prefs === sheet && e instanceof VitrinkaApiError && e.status === 422) {
|
|
199
|
+
sheetLocal = true;
|
|
200
|
+
console.warn('vitrinka: this server keeps no sheet size — it stays on this device', e);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (soft(e))
|
|
204
|
+
noteUnavailable(e);
|
|
205
|
+
else
|
|
206
|
+
console.warn('vitrinka: saving HUD prefs failed — kept on this device', e);
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
162
209
|
}
|
|
210
|
+
if (answer !== undefined)
|
|
211
|
+
adopt(answer, gen);
|
|
163
212
|
return cachedPrefs();
|
|
164
213
|
}
|
|
165
214
|
/** Test-only: drop the caches and the unavailable latch. */
|
|
@@ -168,5 +217,6 @@ export function __resetMeForTests() {
|
|
|
168
217
|
meCache = undefined;
|
|
169
218
|
unavailable = false;
|
|
170
219
|
warned = false;
|
|
220
|
+
sheetLocal = false;
|
|
171
221
|
edits = 0;
|
|
172
222
|
}
|
|
@@ -3,7 +3,7 @@ import { forgetLink, linkDevice } from './link';
|
|
|
3
3
|
import { cachedAccount, cachedPrefs, fetchMe, savePrefs } from './me';
|
|
4
4
|
import { getState, health } from './queue';
|
|
5
5
|
import { boardUrlOf, readRecents, refreshRecents } from './recents';
|
|
6
|
-
import { canReport, holdReport, sendReport } from './report';
|
|
6
|
+
import { canAttach, canReport, holdReport, sendReport } from './report';
|
|
7
7
|
import { addAnnotation, addNote, RECORDER_ID, startSession, stopSession, togglePause } from './session';
|
|
8
8
|
import { annotateState, setAnnotating, subscribe } from './state';
|
|
9
9
|
function build() {
|
|
@@ -47,6 +47,7 @@ function build() {
|
|
|
47
47
|
workspaceUrl: cfg.url,
|
|
48
48
|
version: RECORDER_ID,
|
|
49
49
|
canReport: canReport(),
|
|
50
|
+
canAttach: canAttach(),
|
|
50
51
|
};
|
|
51
52
|
}
|
|
52
53
|
export function createPageController() {
|
|
@@ -79,8 +80,8 @@ export function createPageController() {
|
|
|
79
80
|
const url = boardUrlOf(done) ?? boardUrl;
|
|
80
81
|
return { ...(url ? { boardUrl: url } : {}), ...(sessionId ? { sessionId } : {}) };
|
|
81
82
|
},
|
|
82
|
-
note: (text) => addNote(text),
|
|
83
|
-
annotate: ({ text, rect, selector, task }) => addAnnotation(text, rect, selector, { task }),
|
|
83
|
+
note: (text, attachments) => addNote(text, attachments),
|
|
84
|
+
annotate: ({ text, rect, selector, task, attachments }) => addAnnotation(text, rect, selector, { task, ...(attachments ? { attachments } : {}) }),
|
|
84
85
|
setAnnotating,
|
|
85
86
|
async link() {
|
|
86
87
|
const flow = await linkDevice();
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
*
|
|
5
5
|
* - A synchronous KV store (./storage — localStorage by default, memory when
|
|
6
6
|
* that is unavailable) holds the session record and the event buffer:
|
|
7
|
-
*
|
|
8
|
-
* flush()
|
|
9
|
-
* exactly the sent seqs on return.
|
|
7
|
+
* seq allocation is serialized across tabs by the driver's lock, reading
|
|
8
|
+
* the shared watermark inside it. flush() is single-flight within each
|
|
9
|
+
* document and removes exactly the sent seqs on return.
|
|
10
10
|
* - rrweb batches ride as CHUNKS the way the extension sends them: each batch
|
|
11
11
|
* is serialized once, split under the server's chunk cap, uploaded to
|
|
12
12
|
* `/chunk?seq=N` under a pre-allocated seq, and only then does its `rrweb`
|
|
@@ -14,6 +14,17 @@
|
|
|
14
14
|
* originally allocated seq (gap-fill), retried oldest-first AHEAD of the
|
|
15
15
|
* event flush. Chunks are kept in memory (they can be megabytes; the KV
|
|
16
16
|
* store is small) and persisted best-effort under a byte budget.
|
|
17
|
+
* - A note's attached images (recorder attachments) ride the same way: the
|
|
18
|
+
* note and its images take ONE allocation — the images' seqs first, the
|
|
19
|
+
* note's last, its payload listing theirs — and each image uploads to
|
|
20
|
+
* `/shot?seq=N` before its `attachment` row (blobKey) joins the stream.
|
|
21
|
+
* Their bytes wait in the blob journal (./storage/blobs — IndexedDB), so a
|
|
22
|
+
* queued image survives a reload and is uploaded before its row is
|
|
23
|
+
* delivered; they leave it once the server acknowledged the row. The
|
|
24
|
+
* capture journal of such a note is written only once those bytes are in
|
|
25
|
+
* (another tab must never recover an image it cannot read yet) and lives
|
|
26
|
+
* until every one of its seqs is acknowledged, so a reload or another tab
|
|
27
|
+
* can finish the lot.
|
|
17
28
|
* - A permanent server verdict (4xx minus 408/429) drops the item loudly;
|
|
18
29
|
* transient failures stop the pass and the next flush retries.
|
|
19
30
|
* - A reload keeps the undelivered event tail (KV store is durable).
|
|
@@ -28,6 +39,7 @@
|
|
|
28
39
|
*/
|
|
29
40
|
import type { RedactionPolicy } from '@vitrinka/redact';
|
|
30
41
|
import type { RecorderEvent } from '../protocol';
|
|
42
|
+
import type { StagedImage } from './attachments';
|
|
31
43
|
export declare const MAX_BATCH_BYTES: number;
|
|
32
44
|
/** The server's per-POST event cap. */
|
|
33
45
|
export declare const EVENTS_PER_POST = 500;
|
|
@@ -61,6 +73,11 @@ export interface SessionState {
|
|
|
61
73
|
* reload re-applies the same rules instead of silently reverting.
|
|
62
74
|
*/
|
|
63
75
|
policy?: RedactionPolicy | null;
|
|
76
|
+
/**
|
|
77
|
+
* The same read's `attachments` (recorder attachments D6): the sheets take
|
|
78
|
+
* images only on true. Durable with the session, like `policy`.
|
|
79
|
+
*/
|
|
80
|
+
attachments?: boolean;
|
|
64
81
|
/**
|
|
65
82
|
* When (ISO) another tab last renewed its claim to be stopping this
|
|
66
83
|
* session: the copy it stores reads as paused with its clock frozen at the
|
|
@@ -97,6 +114,8 @@ export declare function setState(rec: SessionState | null): void;
|
|
|
97
114
|
*/
|
|
98
115
|
export declare function markStopping(sessionId: string | null, activeMs?: number, renewMs?: number): void;
|
|
99
116
|
export type StoredChange = 'joined' | 'updated' | 'ended' | 'unchanged';
|
|
117
|
+
export declare function onBeforeStop(fn: () => void): () => void;
|
|
118
|
+
export declare function runBeforeStopHooks(): void;
|
|
100
119
|
/**
|
|
101
120
|
* Another document of this origin (a second tab) wrote the session record.
|
|
102
121
|
* The store is shared, this cache is not — a tab that joined a recording on
|
|
@@ -110,6 +129,11 @@ export type StoredChange = 'joined' | 'updated' | 'ended' | 'unchanged';
|
|
|
110
129
|
export declare function adoptStoredState(raw: string | null): StoredChange;
|
|
111
130
|
/** Write the in-memory buffer (and the pending chunks) to storage NOW. */
|
|
112
131
|
export declare function persistNow(): void;
|
|
132
|
+
/**
|
|
133
|
+
* Delete journaled images nothing will upload: `ended`'s (a session just
|
|
134
|
+
* stopped), or, without it, every session's but the live one.
|
|
135
|
+
*/
|
|
136
|
+
export declare function pruneBlobJournal(ended?: string): Promise<void>;
|
|
113
137
|
export declare function queuedCount(): number;
|
|
114
138
|
/** Fresh-session baseline; called by startSession before capture begins. */
|
|
115
139
|
export declare function resetHealth(baseSeq?: number): void;
|
|
@@ -141,11 +165,10 @@ export declare function markSessionDead(reason: string): void;
|
|
|
141
165
|
export declare function reconcile(): Promise<void>;
|
|
142
166
|
export declare function armReconcile(): void;
|
|
143
167
|
export declare function disarmReconcile(): void;
|
|
144
|
-
/**
|
|
145
|
-
export declare
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
} | null;
|
|
168
|
+
/** Document identity is not sessionStorage: duplicated tabs copy that store. */
|
|
169
|
+
export declare const RECORDER_DOCUMENT_KEY: string;
|
|
170
|
+
/** A departing document can be acknowledged by a helper only with a full journal. */
|
|
171
|
+
export declare function tailIsDurable(): boolean;
|
|
149
172
|
export declare function trackCapture(p: Promise<void>): Promise<void>;
|
|
150
173
|
export declare const CAPTURES_SETTLE_MS = 5000;
|
|
151
174
|
/** Wait for in-flight captures, bounded; false when stragglers were abandoned. */
|
|
@@ -158,12 +181,13 @@ export declare function isSessionLive(id: string): boolean;
|
|
|
158
181
|
* kind+payload plus the route they observed. With no session the event goes
|
|
159
182
|
* to the flight recorder when the idle pill keeps one (memory only — never
|
|
160
183
|
* storage, never the network), else it is dropped. Returns the stamped ts
|
|
161
|
-
* (null when dropped).
|
|
184
|
+
* (null when dropped). `images` (a note's attachments, live sessions only)
|
|
185
|
+
* take the seqs just before the event's, which lists them as `attachments`.
|
|
162
186
|
*/
|
|
163
187
|
export declare function pushEvent(kind: string, payload: Record<string, unknown> | undefined, route: {
|
|
164
188
|
tabId: string;
|
|
165
189
|
tabHost: string;
|
|
166
|
-
}): string | null;
|
|
190
|
+
}, images?: readonly StagedImage[]): string | null;
|
|
167
191
|
/** Push a fully-formed event (chunk rows carry a pre-allocated seq). */
|
|
168
192
|
export declare function pushRawEvent(ev: RecorderEvent): void;
|
|
169
193
|
export declare function idleMs(): number;
|
|
@@ -194,7 +218,7 @@ export declare function scheduleFlush(): void;
|
|
|
194
218
|
export declare function flush(opts?: {
|
|
195
219
|
keepalive?: boolean;
|
|
196
220
|
}): Promise<boolean>;
|
|
197
|
-
/** Drain until buffer
|
|
221
|
+
/** Drain until buffer, chunks and images are empty or the deadline passes. */
|
|
198
222
|
export declare function drainBuffer(deadlineMs?: number): Promise<boolean>;
|
|
199
223
|
/** Reset buffers for a fresh session. */
|
|
200
224
|
export declare function resetQueues(): void;
|
|
@@ -208,5 +232,12 @@ export declare function __chunksForTests(): {
|
|
|
208
232
|
count: number;
|
|
209
233
|
sessionId: string;
|
|
210
234
|
}[];
|
|
235
|
+
/** Test-only: the images waiting for upload (in order), with their blob journal keys. */
|
|
236
|
+
export declare function __imagesForTests(): {
|
|
237
|
+
seq: number;
|
|
238
|
+
sessionId: string;
|
|
239
|
+
blob: string;
|
|
240
|
+
name: string;
|
|
241
|
+
}[];
|
|
211
242
|
/** Test-only: drop the in-memory caches while LEAVING storage intact (a reload). */
|
|
212
243
|
export declare function __dropCachesForTests(): void;
|