@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/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();
|
|
@@ -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
|
|
@@ -112,6 +129,11 @@ export declare function runBeforeStopHooks(): void;
|
|
|
112
129
|
export declare function adoptStoredState(raw: string | null): StoredChange;
|
|
113
130
|
/** Write the in-memory buffer (and the pending chunks) to storage NOW. */
|
|
114
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>;
|
|
115
137
|
export declare function queuedCount(): number;
|
|
116
138
|
/** Fresh-session baseline; called by startSession before capture begins. */
|
|
117
139
|
export declare function resetHealth(baseSeq?: number): void;
|
|
@@ -159,12 +181,13 @@ export declare function isSessionLive(id: string): boolean;
|
|
|
159
181
|
* kind+payload plus the route they observed. With no session the event goes
|
|
160
182
|
* to the flight recorder when the idle pill keeps one (memory only — never
|
|
161
183
|
* storage, never the network), else it is dropped. Returns the stamped ts
|
|
162
|
-
* (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`.
|
|
163
186
|
*/
|
|
164
187
|
export declare function pushEvent(kind: string, payload: Record<string, unknown> | undefined, route: {
|
|
165
188
|
tabId: string;
|
|
166
189
|
tabHost: string;
|
|
167
|
-
}): string | null;
|
|
190
|
+
}, images?: readonly StagedImage[]): string | null;
|
|
168
191
|
/** Push a fully-formed event (chunk rows carry a pre-allocated seq). */
|
|
169
192
|
export declare function pushRawEvent(ev: RecorderEvent): void;
|
|
170
193
|
export declare function idleMs(): number;
|
|
@@ -195,7 +218,7 @@ export declare function scheduleFlush(): void;
|
|
|
195
218
|
export declare function flush(opts?: {
|
|
196
219
|
keepalive?: boolean;
|
|
197
220
|
}): Promise<boolean>;
|
|
198
|
-
/** Drain until buffer
|
|
221
|
+
/** Drain until buffer, chunks and images are empty or the deadline passes. */
|
|
199
222
|
export declare function drainBuffer(deadlineMs?: number): Promise<boolean>;
|
|
200
223
|
/** Reset buffers for a fresh session. */
|
|
201
224
|
export declare function resetQueues(): void;
|
|
@@ -209,5 +232,12 @@ export declare function __chunksForTests(): {
|
|
|
209
232
|
count: number;
|
|
210
233
|
sessionId: string;
|
|
211
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
|
+
}[];
|
|
212
242
|
/** Test-only: drop the in-memory caches while LEAVING storage intact (a reload). */
|
|
213
243
|
export declare function __dropCachesForTests(): void;
|