@vitrinka/web 0.9.1 → 0.9.3

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/build/one.iife.js CHANGED
@@ -1 +1 @@
1
- (()=>{var{defineProperty:H,getOwnPropertyNames:w,getOwnPropertyDescriptor:d}=Object,p=Object.prototype.hasOwnProperty;function E(k){return this[k]}var f=(k)=>{var j=(x??=new WeakMap).get(k),q;if(j)return j;if(j=H({},"__esModule",{value:!0}),k&&typeof k==="object"||typeof k==="function"){for(var F of w(k))if(!p.call(j,F))H(j,F,{get:E.bind(k,F),enumerable:!(q=d(k,F))||q.enumerable})}return x.set(k,j),j},x;var c=(k)=>k;function b(k,j){this[k]=c.bind(null,j)}var l=(k,j)=>{for(var q in j)H(k,q,{get:j[q],enumerable:!0,configurable:!0,set:b.bind(j,q)})};var Yj={};var g={};l(g,{watchClaim:()=>qj,updateClaim:()=>jj,unmarkPage:()=>Jj,takeClaim:()=>e,serveHello:()=>Uj,serveCommands:()=>Xj,serializeClaim:()=>o,sendCommand:()=>Wj,releaseClaim:()=>kj,readClaim:()=>P,parseHello:()=>S,parseCommand:()=>i,parseClaim:()=>y,parseAck:()=>N,pageMarked:()=>Qj,nonce:()=>L,markPage:()=>Fj,isLive:()=>I,holderAnswers:()=>h,documentEnv:()=>s,ask:()=>_,answeredBy:()=>A,announce:()=>T,PAGE_ATTR:()=>Z,ONE_VERSION:()=>X,LEAD_ATTR:()=>Y,HELLO_EVENT:()=>$,COMMAND_EVENT:()=>u,ACK_EVENT:()=>C});function O(k,j,q,F={}){let J=k,Q=J.__zone_symbol__addEventListener??k.addEventListener,W=J.__zone_symbol__removeEventListener??k.removeEventListener,z=F.capture??!1;return Q.call(k,j,q,{capture:z,passive:!1}),()=>W.call(k,j,q,z)}var X=1,Z="data-vitrinka-page",Y="data-vitrinka-lead",$="vitrinka:hello",u="vitrinka:command",C="vitrinka:ack";function s(){let j=globalThis.document?.documentElement;if(!j||typeof globalThis.dispatchEvent!=="function")return null;return{root:j,bus:globalThis}}function L(k){return`${k}.${Math.random().toString(36).slice(2,10)}`}var t=["page","extension"],a=["starting","recording","paused","stopping","saved"],n=["pause","stop","note"],v=["not_recording","stopping","not_here","bad_command"];function K(k){if(typeof k!=="string")return null;try{let j=JSON.parse(k);return j!==null&&typeof j==="object"&&!Array.isArray(j)?j:null}catch{return null}}var U=(k)=>typeof k==="string",B=(k)=>U(k)&&t.includes(k),R=(k)=>U(k)&&a.includes(k),M=(k)=>typeof k==="number"&&Number.isInteger(k)&&k>=1;function y(k){let j=K(k);if(!j||!M(j.v)||!B(j.by)||!U(j.id)||!j.id||!R(j.state))return null;return{v:j.v,by:j.by,id:j.id,state:j.state,sessionId:U(j.sessionId)?j.sessionId:Number.isFinite(j.sessionId)?String(j.sessionId):"",since:typeof j.since==="number"?j.since:0}}function o(k){return JSON.stringify({v:k.v,by:k.by,id:k.id,state:k.state,sessionId:k.sessionId,since:k.since})}function I(k){return k!==void 0&&k!==null&&k!=="saved"}function r(k){if(k===null||typeof k!=="object"||Array.isArray(k))return null;let j=k;if(!B(j.by)||!R(j.state))return null;return{by:j.by,state:j.state,here:j.here===!0,...U(j.id)&&j.id?{id:j.id}:{}}}function S(k){let j=K(k);if(!j||!M(j.v)||!B(j.from)||!U(j.inst)||!j.inst)return null;let q=r(j.live);return{v:j.v,from:j.from,inst:j.inst,...j.ask===!0?{ask:!0}:{},...j.live!==void 0?{live:q}:{},...j.gone===!0?{gone:!0}:{}}}function i(k){let j=K(k);if(!j||!M(j.v)||!B(j.from)||!U(j.inst)||!j.inst||!U(j.id)||!j.id)return null;if(!U(j.op)||!n.includes(j.op))return null;return{v:j.v,from:j.from,inst:j.inst,id:j.id,op:j.op,...U(j.text)?{text:j.text}:{}}}function N(k){let j=K(k);if(!j||!M(j.v)||!B(j.from)||!U(j.inst)||!U(j.id)||typeof j.ok!=="boolean")return null;return{v:j.v,from:j.from,inst:j.inst,id:j.id,ok:j.ok,...U(j.code)&&v.includes(j.code)?{code:j.code}:{},...U(j.error)?{error:j.error}:{}}}function P(k){return y(k.root.getAttribute(Y))}function m(k,j){let q=o(j);if(k.root.getAttribute(Y)!==q)k.root.setAttribute(Y,q)}function e(k,j,q){let F=P(k);if(F&&F.id!==q.id&&I(F.state)&&h(k,j,F))return{ok:!1,holder:F};let J={v:X,by:j.from,id:q.id,state:q.state,sessionId:q.sessionId??"",since:F?.id===q.id&&I(F.state)?F.since:Date.now()};return m(k,J),{ok:!0,claim:J}}function jj(k,j,q){let F=P(k);if(F?.id!==j)return!1;return m(k,{...F,v:X,state:q.state,sessionId:q.sessionId??F.sessionId}),!0}function kj(k,j){if(P(k)?.id!==j)return!1;return k.root.removeAttribute(Y),!0}function qj(k,j){if(k.watch)return k.watch(j);if(typeof MutationObserver!=="function"||typeof Node>"u"||!(k.root instanceof Node))return()=>{return};let q=new MutationObserver(j);return q.observe(k.root,{attributes:!0,attributeFilter:[Y]}),()=>q.disconnect()}function Fj(k,j){if(k.root.getAttribute(Z)!==j)k.root.setAttribute(Z,j)}function Jj(k){k.root.removeAttribute(Z)}function Qj(k){return k.root.getAttribute(Z)!==null}function V(k,j,q){k.bus.dispatchEvent(new CustomEvent(j,{detail:JSON.stringify(q)}))}function D(k,j,q){return O(k.bus,j,(F)=>q(F.detail))}function _(k,j){let q=[],F=D(k,$,(J)=>{let Q=S(J);if(Q&&!Q.ask&&Q.inst!==j.inst)q.push(Q)});try{V(k,$,{v:X,from:j.from,inst:j.inst,ask:!0})}finally{F()}return q}function T(k,j,q,F={}){V(k,$,{v:X,from:j.from,inst:j.inst,live:q,...F.gone?{gone:!0}:{}})}function Uj(k,j,q,F,J={}){return D(k,$,(Q)=>{let W=S(Q);if(!W||W.inst===j.inst)return;if(!W.ask)F?.(W);else if(J.answerIf?.()??!0)T(k,j,q())})}function A(k,j){return k.some((q)=>q.live?.here===!0&&(q.live.id?q.live.id===j.id:q.from===j.by))}function h(k,j,q){return A(_(k,j),q)}function Wj(k,j,q,F){let J=L("c"),Q=null,W=D(k,C,(z)=>{let G=N(z);if(G&&G.id===J&&G.inst!==j.inst&&!Q)Q=G});try{V(k,u,{v:X,from:j.from,inst:j.inst,id:J,op:q,...F!==void 0?{text:F}:{}})}finally{W()}return Q}function Xj(k,j,q){return D(k,u,(F)=>{let J=i(F);if(!J||J.inst===j.inst)return;let Q=q(J);if(!Q)return;V(k,C,{v:X,from:j.from,inst:j.inst,id:J.id,...Q})})}globalThis.VitrinkaOne=Object.freeze({...g});})();
1
+ (()=>{var{defineProperty:E,getOwnPropertyNames:z,getOwnPropertyDescriptor:K}=Object,B=Object.prototype.hasOwnProperty;function j(e){return this[e]}var G=(e)=>{var n=(S??=new WeakMap).get(e),t;if(n)return n;if(n=E({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var o of z(e))if(!B.call(n,o))E(n,o,{get:j.bind(e,o),enumerable:!(t=K(e,o))||t.enumerable})}return S.set(e,n),n},S;var J=(e)=>e;function W(e,n){this[e]=J.bind(null,n)}var F=(e,n)=>{for(var t in n)E(e,t,{get:n[t],enumerable:!0,configurable:!0,set:W.bind(n,t)})};var cn={};var _={};F(_,{ACK_EVENT:()=>C,COMMAND_EVENT:()=>x,HELLO_EVENT:()=>c,LEAD_ATTR:()=>l,ONE_VERSION:()=>u,PAGE_ATTR:()=>d,announce:()=>H,answeredBy:()=>D,ask:()=>M,documentEnv:()=>Z,holderAnswers:()=>V,isLive:()=>k,markPage:()=>rn,nonce:()=>h,pageMarked:()=>an,parseAck:()=>N,parseClaim:()=>L,parseCommand:()=>P,parseHello:()=>A,readClaim:()=>b,releaseClaim:()=>tn,sendCommand:()=>ln,serializeClaim:()=>I,serveCommands:()=>dn,serveHello:()=>un,takeClaim:()=>nn,unmarkPage:()=>sn,updateClaim:()=>en,watchClaim:()=>on});function w(e,n,t,o={}){let i=e,r=i.__zone_symbol__addEventListener??e.addEventListener,a=i.__zone_symbol__removeEventListener??e.removeEventListener,m=o.capture??!1;return r.call(e,n,t,{capture:m,passive:!1}),()=>a.call(e,n,t,m)}var u=1,d="data-vitrinka-page",l="data-vitrinka-lead",c="vitrinka:hello",x="vitrinka:command",C="vitrinka:ack";function Z(){let n=globalThis.document?.documentElement;if(!n||typeof globalThis.dispatchEvent!=="function")return null;return{root:n,bus:globalThis}}function h(e){return`${e}.${Math.random().toString(36).slice(2,10)}`}var q=["page","extension"],Q=["starting","recording","paused","stopping","saved"],U=["pause","stop","note"],X=["not_recording","stopping","not_here","bad_command"];function v(e){if(typeof e!=="string")return null;try{let n=JSON.parse(e);return n!==null&&typeof n==="object"&&!Array.isArray(n)?n:null}catch{return null}}var s=(e)=>typeof e==="string",f=(e)=>s(e)&&q.includes(e),T=(e)=>s(e)&&Q.includes(e),g=(e)=>typeof e==="number"&&Number.isInteger(e)&&e>=1;function L(e){let n=v(e);if(!n||!g(n.v)||!f(n.by)||!s(n.id)||!n.id||!T(n.state))return null;return{v:n.v,by:n.by,id:n.id,state:n.state,sessionId:s(n.sessionId)?n.sessionId:Number.isFinite(n.sessionId)?String(n.sessionId):"",since:typeof n.since==="number"?n.since:0}}function I(e){return JSON.stringify({v:e.v,by:e.by,id:e.id,state:e.state,sessionId:e.sessionId,since:e.since})}function k(e){return e!==void 0&&e!==null&&e!=="saved"}function Y(e){if(e===null||typeof e!=="object"||Array.isArray(e))return null;let n=e;if(!f(n.by)||!T(n.state))return null;return{by:n.by,state:n.state,here:n.here===!0,...s(n.id)&&n.id?{id:n.id}:{}}}function A(e){let n=v(e);if(!n||!g(n.v)||!f(n.from)||!s(n.inst)||!n.inst)return null;let t=Y(n.live);return{v:n.v,from:n.from,inst:n.inst,...n.ask===!0?{ask:!0}:{},...n.live!==void 0?{live:t}:{},...n.gone===!0?{gone:!0}:{}}}function P(e){let n=v(e);if(!n||!g(n.v)||!f(n.from)||!s(n.inst)||!n.inst||!s(n.id)||!n.id)return null;if(!s(n.op)||!U.includes(n.op))return null;return{v:n.v,from:n.from,inst:n.inst,id:n.id,op:n.op,...s(n.text)?{text:n.text}:{}}}function N(e){let n=v(e);if(!n||!g(n.v)||!f(n.from)||!s(n.inst)||!s(n.id)||typeof n.ok!=="boolean")return null;return{v:n.v,from:n.from,inst:n.inst,id:n.id,ok:n.ok,...s(n.code)&&X.includes(n.code)?{code:n.code}:{},...s(n.error)?{error:n.error}:{}}}function b(e){return L(e.root.getAttribute(l))}function R(e,n){let t=I(n);if(e.root.getAttribute(l)!==t)e.root.setAttribute(l,t)}function nn(e,n,t){let o=b(e);if(o&&o.id!==t.id&&k(o.state)&&V(e,n,o))return{ok:!1,holder:o};let i={v:u,by:n.from,id:t.id,state:t.state,sessionId:t.sessionId??"",since:o?.id===t.id&&k(o.state)?o.since:Date.now()};return R(e,i),{ok:!0,claim:i}}function en(e,n,t){let o=b(e);if(o?.id!==n)return!1;return R(e,{...o,v:u,state:t.state,sessionId:t.sessionId??o.sessionId}),!0}function tn(e,n){if(b(e)?.id!==n)return!1;return e.root.removeAttribute(l),!0}function on(e,n){if(e.watch)return e.watch(n);if(typeof MutationObserver!=="function"||typeof Node>"u"||!(e.root instanceof Node))return()=>{return};let t=new MutationObserver(n);return t.observe(e.root,{attributes:!0,attributeFilter:[l]}),()=>t.disconnect()}function rn(e,n){if(e.root.getAttribute(d)!==n)e.root.setAttribute(d,n)}function sn(e){e.root.removeAttribute(d)}function an(e){return e.root.getAttribute(d)!==null}function y(e,n,t){e.bus.dispatchEvent(new CustomEvent(n,{detail:JSON.stringify(t)}))}function O(e,n,t){return w(e.bus,n,(o)=>t(o.detail))}function M(e,n){let t=[],o=O(e,c,(i)=>{let r=A(i);if(r&&!r.ask&&r.inst!==n.inst)t.push(r)});try{y(e,c,{v:u,from:n.from,inst:n.inst,ask:!0})}finally{o()}return t}function H(e,n,t,o={}){y(e,c,{v:u,from:n.from,inst:n.inst,live:t,...o.gone?{gone:!0}:{}})}function un(e,n,t,o,i={}){return O(e,c,(r)=>{let a=A(r);if(!a||a.inst===n.inst)return;if(!a.ask)o?.(a);else if(i.answerIf?.()??!0)H(e,n,t())})}function D(e,n){return e.some((t)=>t.live?.here===!0&&(t.live.id?t.live.id===n.id:t.from===n.by))}function V(e,n,t){return D(M(e,n),t)}function ln(e,n,t,o){let i=h("c"),r=null,a=O(e,C,(m)=>{let p=N(m);if(p&&p.id===i&&p.inst!==n.inst&&!r)r=p});try{y(e,x,{v:u,from:n.from,inst:n.inst,id:i,op:t,...o!==void 0?{text:o}:{}})}finally{a()}return r}function dn(e,n,t){return O(e,x,(o)=>{let i=P(o);if(!i||i.inst===n.inst)return;let r=t(i);if(!r)return;y(e,C,{v:u,from:n.from,inst:n.inst,id:i.id,...r})})}globalThis.VitrinkaOne=Object.freeze({..._});})();
@@ -10,5 +10,5 @@
10
10
  * into) never pulls the HUD's React sheets in through styles.ts.
11
11
  */
12
12
  export declare const HOST_STYLE: string;
13
- /** Inline style of a sheet host portaled into a dialog — the same 0×0 origin box. */
13
+ /** A dialog-associated top-layer popover uses the same viewport-origin box. */
14
14
  export declare const SHEET_HOST_STYLE: string;
@@ -11,5 +11,5 @@
11
11
  */
12
12
  export const HOST_STYLE = 'all:initial;position:fixed;z-index:2147483647;inset:0 auto auto 0;margin:0;padding:0;border:0;' +
13
13
  'background:transparent;overflow:visible;width:0;height:0;pointer-events:none;color-scheme:normal;';
14
- /** Inline style of a sheet host portaled into a dialog — the same 0×0 origin box. */
14
+ /** A dialog-associated top-layer popover uses the same viewport-origin box. */
15
15
  export const SHEET_HOST_STYLE = HOST_STYLE;
@@ -29,8 +29,9 @@ export declare function createHudHost(): HudHost;
29
29
  */
30
30
  export declare function sheetTarget(): Element | null;
31
31
  /**
32
- * A sheet host: its own open shadow root (so the HUD stylesheet applies
33
- * inside a foreign dialog too), shielded, appended to `target`.
32
+ * A sheet host stays in the dialog's focus/inert subtree, but its manual
33
+ * popover paints in the browser's top layer: fixed children keep the viewport
34
+ * as their containing block, never the dialog's transform, filter or clipping.
34
35
  */
35
36
  export declare function createSheetHost(target: Element): {
36
37
  mount: HTMLElement;
@@ -236,8 +236,9 @@ export function sheetTarget() {
236
236
  return aria[aria.length - 1] ?? null;
237
237
  }
238
238
  /**
239
- * A sheet host: its own open shadow root (so the HUD stylesheet applies
240
- * inside a foreign dialog too), shielded, appended to `target`.
239
+ * A sheet host stays in the dialog's focus/inert subtree, but its manual
240
+ * popover paints in the browser's top layer: fixed children keep the viewport
241
+ * as their containing block, never the dialog's transform, filter or clipping.
241
242
  */
242
243
  export function createSheetHost(target) {
243
244
  const el = document.createElement('div');
@@ -249,7 +250,10 @@ export function createSheetHost(target) {
249
250
  root.append(mount);
250
251
  shield(el);
251
252
  const releaseGuard = holdKeyGuard();
253
+ if (typeof el.showPopover === 'function')
254
+ el.popover = 'manual';
252
255
  target.append(el);
256
+ el.showPopover?.();
253
257
  return {
254
258
  mount,
255
259
  destroy: () => {
@@ -1,3 +1,3 @@
1
1
  /** Sent as `meta.recorder` and written as `data-vitrinka-page`; bumped with the package version. */
2
- export declare const RECORDER_VERSION = "0.9.1";
3
- export declare const RECORDER_ID = "web/0.9.1";
2
+ export declare const RECORDER_VERSION = "0.9.3";
3
+ export declare const RECORDER_ID = "web/0.9.3";
@@ -1,3 +1,3 @@
1
1
  /** Sent as `meta.recorder` and written as `data-vitrinka-page`; bumped with the package version. */
2
- export const RECORDER_VERSION = '0.9.1';
2
+ export const RECORDER_VERSION = '0.9.3';
3
3
  export const RECORDER_ID = `web/${RECORDER_VERSION}`;
@@ -7,6 +7,20 @@ export declare const FACE_KEY = "vitrinka.report.face";
7
7
  * workspace `base` addresses (any, for a bare origin).
8
8
  */
9
9
  export declare function memberLinked(base: string): boolean;
10
+ /**
11
+ * The member link a report and a reporter session prove to `base` (vt-8020):
12
+ * the stored link's own token wherever `memberLinked` holds, else ''. Never a
13
+ * link minted on another vitrinka, and never a `vkr_` key the host configured
14
+ * — that is a build's, kept in the recorder's config, not in the link.
15
+ */
16
+ export declare function memberTokenFor(base: string): string;
17
+ /**
18
+ * vitrinka's `memberError` says the link is gone for good — revoked, or its
19
+ * person no longer a member — rather than only not good here (another
20
+ * workspace). A gone link is forgotten as a 401 on a session door forgets it;
21
+ * any other answer keeps it.
22
+ */
23
+ export declare function memberLinkGone(err: string): boolean;
10
24
  /** The face this browser last picked here; null when it never picked (or storage is blocked). */
11
25
  export declare function rememberedFace(): ReportFace | null;
12
26
  export declare function rememberFace(face: ReportFace): void;
@@ -46,6 +46,24 @@ export function memberLinked(base) {
46
46
  return false; // not a URL: no link can be for it
47
47
  }
48
48
  }
49
+ /**
50
+ * The member link a report and a reporter session prove to `base` (vt-8020):
51
+ * the stored link's own token wherever `memberLinked` holds, else ''. Never a
52
+ * link minted on another vitrinka, and never a `vkr_` key the host configured
53
+ * — that is a build's, kept in the recorder's config, not in the link.
54
+ */
55
+ export function memberTokenFor(base) {
56
+ return memberLinked(base) ? (readLink()?.token ?? '') : '';
57
+ }
58
+ /**
59
+ * vitrinka's `memberError` says the link is gone for good — revoked, or its
60
+ * person no longer a member — rather than only not good here (another
61
+ * workspace). A gone link is forgotten as a 401 on a session door forgets it;
62
+ * any other answer keeps it.
63
+ */
64
+ export function memberLinkGone(err) {
65
+ return /revoked|not[\s_-]?(?:a[\s_-])?member|no longer a member/i.test(err);
66
+ }
49
67
  /** The face this browser last picked here; null when it never picked (or storage is blocked). */
50
68
  export function rememberedFace() {
51
69
  const v = store()?.getItem(FACE_KEY);
@@ -3,8 +3,11 @@
3
3
  * publishable key: the host's signed token is traded once for a short-lived
4
4
  * reporter session, which then lists the reporter's reports and their news.
5
5
  * A `vkb_` key alone reads nothing — every list call carries the session.
6
+ * A browser linked to a vitrinka member on the widget's base proves the link
7
+ * in the trade too (`memberToken`, vt-8020): the session then lists the
8
+ * reporter's reports and the member's, as the server joins them.
6
9
  *
7
- * POST /api/v1/report/session {token} → {reporter, session, expiresAt, portalUrl?}
10
+ * POST /api/v1/report/session {token, memberToken?} → {reporter, session, expiresAt, portalUrl?, memberError?}
8
11
  * GET /api/v1/report/mine?cursor= X-Vitrinka-Reporter → {reports, nextCursor}
9
12
  * GET /api/v1/report/updates?cursor= X-Vitrinka-Reporter → {updates, nextCursor}
10
13
  */
@@ -21,6 +24,8 @@ export interface ReporterSession {
21
24
  expiresAt: string;
22
25
  /** The project's reporter portal, when one is bound. */
23
26
  portalUrl?: string;
27
+ /** The server did not take the member link the trade carried (revoked, another workspace, no longer a member); the session is the reporter's alone. */
28
+ memberError?: string;
24
29
  }
25
30
  /** One of the reporter's reports, as the portal projects it. */
26
31
  export interface MyReport {
@@ -36,7 +41,19 @@ export interface MyReports {
36
41
  reports: MyReport[];
37
42
  nextCursor?: string;
38
43
  }
39
- export declare function openSession(target: ApiTarget, token: string): Promise<ReporterSession>;
44
+ /**
45
+ * Trade the host's token for a reporter session, proving `memberToken` beside
46
+ * it when there is one. A vitrinka older than the field refuses it by name:
47
+ * the session is the reporter's alone then, never lost — the trade goes again
48
+ * without it, once.
49
+ */
50
+ export declare function openSession(target: ApiTarget, token: string, memberToken?: string): Promise<ReporterSession>;
51
+ /**
52
+ * Whose session a widget holds: the host's signed token and the member link
53
+ * the trade proved — '' without a host token, which opens none. Linking,
54
+ * unlinking or relinking is another key, so another session and list.
55
+ */
56
+ export declare function sessionKey(hostToken: string, memberToken: string): string;
40
57
  /** Still good for at least a minute more. */
41
58
  export declare function sessionLive(s: ReporterSession | null, now?: number): s is ReporterSession;
42
59
  export declare function listMine(target: ApiTarget, session: string, cursor?: string): Promise<MyReports>;
@@ -3,12 +3,16 @@
3
3
  * publishable key: the host's signed token is traded once for a short-lived
4
4
  * reporter session, which then lists the reporter's reports and their news.
5
5
  * A `vkb_` key alone reads nothing — every list call carries the session.
6
+ * A browser linked to a vitrinka member on the widget's base proves the link
7
+ * in the trade too (`memberToken`, vt-8020): the session then lists the
8
+ * reporter's reports and the member's, as the server joins them.
6
9
  *
7
- * POST /api/v1/report/session {token} → {reporter, session, expiresAt, portalUrl?}
10
+ * POST /api/v1/report/session {token, memberToken?} → {reporter, session, expiresAt, portalUrl?, memberError?}
8
11
  * GET /api/v1/report/mine?cursor= X-Vitrinka-Reporter → {reports, nextCursor}
9
12
  * GET /api/v1/report/updates?cursor= X-Vitrinka-Reporter → {updates, nextCursor}
10
13
  */
11
14
  import { VitrinkaApiError } from '../recorder/api';
15
+ import { refusedField } from './wire';
12
16
  async function call(method, path, target, body, session) {
13
17
  const res = await fetch(target.url + path, {
14
18
  method,
@@ -26,8 +30,33 @@ async function call(method, path, target, body, session) {
26
30
  throw new VitrinkaApiError(`${method} ${path} → ${res.status}: ${text}`, res.status);
27
31
  return (text ? JSON.parse(text) : {});
28
32
  }
29
- export function openSession(target, token) {
30
- return call('POST', '/api/v1/report/session', target, { token });
33
+ /**
34
+ * Trade the host's token for a reporter session, proving `memberToken` beside
35
+ * it when there is one. A vitrinka older than the field refuses it by name:
36
+ * the session is the reporter's alone then, never lost — the trade goes again
37
+ * without it, once.
38
+ */
39
+ export async function openSession(target, token, memberToken = '') {
40
+ const path = '/api/v1/report/session';
41
+ if (!memberToken)
42
+ return call('POST', path, target, { token });
43
+ try {
44
+ return await call('POST', path, target, { token, memberToken });
45
+ }
46
+ catch (e) {
47
+ if (refusedField(e) !== 'memberToken')
48
+ throw e;
49
+ console.warn('vitrinka: this server takes no member link yet — the reporter session opens without it');
50
+ return call('POST', path, target, { token });
51
+ }
52
+ }
53
+ /**
54
+ * Whose session a widget holds: the host's signed token and the member link
55
+ * the trade proved — '' without a host token, which opens none. Linking,
56
+ * unlinking or relinking is another key, so another session and list.
57
+ */
58
+ export function sessionKey(hostToken, memberToken) {
59
+ return hostToken ? JSON.stringify([hostToken, memberToken]) : '';
31
60
  }
32
61
  /** Still good for at least a minute more. */
33
62
  export function sessionLive(s, now = Date.now()) {
@@ -82,9 +82,11 @@ export declare class ReportWidget {
82
82
  /** Swaps this widget for the recorder pill; set only for a linked member (setRecordSwitch). */
83
83
  private recordSwitch;
84
84
  private menu;
85
- /** The reporter session the host's signed token was traded for (vt-8020 D4), and that token. */
85
+ /** The reporter session the host's signed token was traded for (vt-8020 D4), and whose it is: that token and the member link it proved (reader.ts sessionKey). */
86
86
  private session;
87
- private sessionToken;
87
+ private sessionKey;
88
+ /** The member link this widget last saw for its base ('' none): a change is another person's session (linkChanged). */
89
+ private linkSeen;
88
90
  /** The vitrinka member this browser is linked to (vt-8020 D3), read with the link's own token. */
89
91
  private member;
90
92
  private mine;
@@ -108,10 +110,10 @@ export declare class ReportWidget {
108
110
  private readonly e;
109
111
  constructor(opts: WidgetOptions);
110
112
  /**
111
- * Live inside the topmost open dialog while there is one (the recorder's
112
- * sheet path, hud/host.ts): a modal makes everything outside it inert and
113
- * its focus trap pulls focus back. The one DOM tree moves, so the draft,
114
- * the marks and their notes go along; focus is restored after the move.
113
+ * Associate with the topmost open dialog so its inert/focus rules leave
114
+ * reporting usable. The sheet host's top-layer popover keeps the button,
115
+ * card and marks anchored to the viewport, independent of the dialog's box.
116
+ * The one DOM tree moves with its draft and marks; focus survives the move.
115
117
  */
116
118
  private followDialog;
117
119
  open(): void;
@@ -131,14 +133,35 @@ export declare class ReportWidget {
131
133
  private show;
132
134
  private target;
133
135
  private toggleMenu;
134
- /** The host's signed token traded once for a reporter session; renewed only when it is about to lapse. Answers the session in force. */
136
+ /**
137
+ * The host's signed token traded once for a reporter session, with the
138
+ * member link beside it when this browser holds one for the base; renewed
139
+ * only when it is about to lapse. Answers the session in force.
140
+ */
135
141
  private refreshWho;
142
+ /** Whose session the widget should hold now (reader.ts sessionKey). */
143
+ private whoKey;
136
144
  /**
137
- * identify() or the page-wide identity moved: a session and a list read for
138
- * the previous person never stay on screen for the next one, and an open My
139
- * reports reloads for whoever is here now.
145
+ * identify(), the page-wide identity or the member link moved: a session
146
+ * and a list read for the previous person never stay on screen for the
147
+ * next one, and an open My reports reloads for whoever is here now.
140
148
  */
141
149
  private whoChanged;
150
+ /**
151
+ * The stored link moved (watchMemberLink: Unlink, the link flow, another
152
+ * tab, a refused link forgotten). Only a change of this base's link counts;
153
+ * the recorder's other notifications pass. The member the popover named was
154
+ * the previous link's: an open card reads the new link's (refreshMember).
155
+ */
156
+ private linkChanged;
157
+ /**
158
+ * vitrinka did not take the member link a report or a session proved
159
+ * (`memberError`): they stand as the reporter's alone. A link revoked, or
160
+ * whose person is no longer a member, is forgotten as a 401 on a session
161
+ * door forgets it (recorder/link.ts) — only the one that was sent, never a
162
+ * link made since. Any other answer keeps it.
163
+ */
164
+ private memberRefused;
142
165
  private refreshMember;
143
166
  private openReports;
144
167
  private loadReports;
@@ -33,17 +33,18 @@ import { clearLink, defaultLinkLabel, readLink, storeLink } from '../recorder/co
33
33
  import { readRecents } from '../recorder/recents';
34
34
  import { createHudHost, createSheetHost, insideHud, sheetTarget } from '../recorder/hud/host';
35
35
  import { listen } from '../recorder/hud/listen';
36
+ import { forgetLink } from '../recorder/link';
36
37
  import { RECORDER_VERSION } from '../recorder/version';
37
38
  import { admit, DEFAULT_ATTACHMENT_CAPS, formatBytes, pastedName, typesLabel } from './attachments';
38
39
  import { cornerToward, DRAG_THRESHOLD, nearestCorner, readDock, saveDock } from './drag';
39
- import { memberLinked, rememberDisplayMode } from './face';
40
+ import { memberLinked, memberLinkGone, memberTokenFor, rememberDisplayMode, watchMemberLink } from './face';
40
41
  import { acquireEngine, releaseEngine } from './engine';
41
42
  import { browserLocale, parseLocale, REPORT_KINDS, strings } from './i18n';
42
43
  import { normalizeIdentity, onSharedIdentity, sharedIdentity } from './identity';
43
44
  import { keybindAria, keybindLabel, loadKeybind, matchesKeybind, readKeybindPress, saveKeybind, watchKeybind } from './keybind';
44
45
  import { arrowEnds, arrowHead, isMark, rectBetween, renumber, toWire, } from './markers';
45
46
  import { coachSide, cornerRect, pickCorner } from './place';
46
- import { listMine, openSession, sessionLive } from './reader';
47
+ import { listMine, openSession, sessionKey, sessionLive } from './reader';
47
48
  import { noteSent, readSent } from './sent';
48
49
  import { COACH_KEY, readCoach, readSize, SIZE_KEY, SIZE_SCALE, SIZES, techDetails, writePref } from './settings';
49
50
  import { REPORT_CSS } from './styles';
@@ -477,9 +478,11 @@ export class ReportWidget {
477
478
  /** Swaps this widget for the recorder pill; set only for a linked member (setRecordSwitch). */
478
479
  recordSwitch = null;
479
480
  menu = null;
480
- /** The reporter session the host's signed token was traded for (vt-8020 D4), and that token. */
481
+ /** The reporter session the host's signed token was traded for (vt-8020 D4), and whose it is: that token and the member link it proved (reader.ts sessionKey). */
481
482
  session = null;
482
- sessionToken = '';
483
+ sessionKey = '';
484
+ /** The member link this widget last saw for its base ('' none): a change is another person's session (linkChanged). */
485
+ linkSeen = '';
483
486
  /** The vitrinka member this browser is linked to (vt-8020 D3), read with the link's own token. */
484
487
  member = null;
485
488
  mine = { rows: [], state: 'ok' };
@@ -540,10 +543,10 @@ export class ReportWidget {
540
543
  this.followDialog();
541
544
  }
542
545
  /**
543
- * Live inside the topmost open dialog while there is one (the recorder's
544
- * sheet path, hud/host.ts): a modal makes everything outside it inert and
545
- * its focus trap pulls focus back. The one DOM tree moves, so the draft,
546
- * the marks and their notes go along; focus is restored after the move.
546
+ * Associate with the topmost open dialog so its inert/focus rules leave
547
+ * reporting usable. The sheet host's top-layer popover keeps the button,
548
+ * card and marks anchored to the viewport, independent of the dialog's box.
549
+ * The one DOM tree moves with its draft and marks; focus survives the move.
547
550
  */
548
551
  followDialog() {
549
552
  const target = this.activeDialog();
@@ -775,6 +778,7 @@ export class ReportWidget {
775
778
  on(e.accPortal, 'click', fromMenu(() => undefined));
776
779
  on(e.accLink, 'click', fromMenu(() => this.startLinkFlow()));
777
780
  on(e.accUnlink, 'click', () => {
781
+ // clearLink notifies: linkChanged drops the session and the list read with the link, a response in flight included.
778
782
  clearLink();
779
783
  this.member = null;
780
784
  this.paint();
@@ -911,6 +915,9 @@ export class ReportWidget {
911
915
  this.paint();
912
916
  }));
913
917
  this.offs.push(onSharedIdentity(() => this.whoChanged()));
918
+ // Linked, unlinked or relinked — here, in the link flow, or in another tab: the session belongs to the pairing it proved.
919
+ this.linkSeen = memberTokenFor(this.opts.base);
920
+ this.offs.push(watchMemberLink(() => this.linkChanged()));
914
921
  // The recorder took the page's capture over: stop saying minutes are attached.
915
922
  if (this.engine)
916
923
  this.offs.push(this.engine.onChange(() => this.paint()));
@@ -975,46 +982,88 @@ export class ReportWidget {
975
982
  const first = pop?.querySelector('button:not([hidden]), a:not([hidden])');
976
983
  first?.focus();
977
984
  }
978
- /** The host's signed token traded once for a reporter session; renewed only when it is about to lapse. Answers the session in force. */
985
+ /**
986
+ * The host's signed token traded once for a reporter session, with the
987
+ * member link beside it when this browser holds one for the base; renewed
988
+ * only when it is about to lapse. Answers the session in force.
989
+ */
979
990
  async refreshWho() {
980
- const who = this.who();
981
- if (!who || !('token' in who)) {
991
+ const token = this.whoToken();
992
+ if (!token) {
982
993
  this.session = null;
983
- this.sessionToken = '';
994
+ this.sessionKey = '';
984
995
  return null;
985
996
  }
986
- if (this.sessionToken === who.token && sessionLive(this.session))
997
+ const member = memberTokenFor(this.opts.base);
998
+ const key = sessionKey(token, member);
999
+ if (this.sessionKey === key && sessionLive(this.session))
987
1000
  return this.session;
988
- this.sessionToken = who.token;
1001
+ this.sessionKey = key;
989
1002
  let opened = null;
990
1003
  try {
991
- opened = await openSession(this.target(), who.token);
1004
+ opened = await openSession(this.target(), token, member);
992
1005
  }
993
1006
  catch (e) {
994
1007
  console.warn('vitrinka: the reporter session could not be opened — My reports shows this browser’s reports only', e);
995
1008
  }
996
- // The person changed while the trade was in flight (whoChanged): this session is someone else's now.
997
- if (this.sessionToken !== who.token)
1009
+ // The person or the member link changed while the trade was in flight (whoChanged): this session is someone else's now.
1010
+ if (this.sessionKey !== key)
998
1011
  return null;
999
1012
  this.session = opened;
1000
1013
  this.paint();
1001
- return this.session;
1014
+ // A link forgotten here moves the key (linkChanged), and the session for the reporter alone is opened instead.
1015
+ if (opened?.memberError)
1016
+ this.memberRefused(opened.memberError, member);
1017
+ return this.sessionKey === key ? this.session : null;
1018
+ }
1019
+ /** Whose session the widget should hold now (reader.ts sessionKey). */
1020
+ whoKey() {
1021
+ return sessionKey(this.whoToken(), memberTokenFor(this.opts.base));
1002
1022
  }
1003
1023
  /**
1004
- * identify() or the page-wide identity moved: a session and a list read for
1005
- * the previous person never stay on screen for the next one, and an open My
1006
- * reports reloads for whoever is here now.
1024
+ * identify(), the page-wide identity or the member link moved: a session
1025
+ * and a list read for the previous person never stay on screen for the
1026
+ * next one, and an open My reports reloads for whoever is here now.
1007
1027
  */
1008
1028
  whoChanged() {
1009
- if (this.whoToken() !== this.sessionToken) {
1029
+ if (this.whoKey() !== this.sessionKey) {
1010
1030
  this.session = null;
1011
- this.sessionToken = '';
1031
+ this.sessionKey = '';
1012
1032
  this.mine = { rows: [], state: 'ok' };
1013
1033
  if (this.isOpen)
1014
1034
  void (this.view === 'reports' ? this.loadReports() : this.refreshWho());
1015
1035
  }
1016
1036
  this.paint();
1017
1037
  }
1038
+ /**
1039
+ * The stored link moved (watchMemberLink: Unlink, the link flow, another
1040
+ * tab, a refused link forgotten). Only a change of this base's link counts;
1041
+ * the recorder's other notifications pass. The member the popover named was
1042
+ * the previous link's: an open card reads the new link's (refreshMember).
1043
+ */
1044
+ linkChanged() {
1045
+ const now = memberTokenFor(this.opts.base);
1046
+ if (now === this.linkSeen)
1047
+ return;
1048
+ this.linkSeen = now;
1049
+ this.member = null;
1050
+ if (now && this.isOpen)
1051
+ void this.refreshMember();
1052
+ this.whoChanged();
1053
+ }
1054
+ /**
1055
+ * vitrinka did not take the member link a report or a session proved
1056
+ * (`memberError`): they stand as the reporter's alone. A link revoked, or
1057
+ * whose person is no longer a member, is forgotten as a 401 on a session
1058
+ * door forgets it (recorder/link.ts) — only the one that was sent, never a
1059
+ * link made since. Any other answer keeps it.
1060
+ */
1061
+ memberRefused(err, sent) {
1062
+ const gone = memberLinkGone(err);
1063
+ console.warn(`vitrinka: vitrinka did not take this browser’s member link (${err}) — ${gone ? 'it is forgotten; link the account again' : 'it stays linked, and the reporter alone owns what goes with it'}`);
1064
+ if (gone && sent && readLink()?.token === sent)
1065
+ forgetLink();
1066
+ }
1018
1067
  async refreshMember() {
1019
1068
  // The browser-wide link goes only to the vitrinka it was minted on: its token never reaches another widget's base.
1020
1069
  const link = memberLinked(this.opts.base) ? readLink() : null;
@@ -1025,16 +1074,23 @@ export class ReportWidget {
1025
1074
  }
1026
1075
  return;
1027
1076
  }
1077
+ let member;
1078
+ let mode;
1028
1079
  try {
1029
1080
  const me = await api('GET', '/api/v1/recorder/me', undefined, { target: { url: this.opts.base, key: link.token } });
1030
- this.member = { email: me.user?.email ?? '', name: me.user?.name ?? '', workspace: me.workspace?.slug ?? link.workspace };
1031
- // A dev-mode member starts on the pill next mount (face.ts startFace).
1032
- rememberDisplayMode(me.displayMode);
1081
+ member = { email: me.user?.email ?? '', name: me.user?.name ?? '', workspace: me.workspace?.slug ?? link.workspace };
1082
+ mode = me.displayMode;
1033
1083
  }
1034
1084
  catch (e) {
1035
1085
  console.warn('vitrinka: the linked vitrinka account could not be read', e);
1036
- this.member = { email: '', name: '', workspace: link.workspace };
1086
+ member = { email: '', name: '', workspace: link.workspace };
1037
1087
  }
1088
+ // The link moved while vitrinka answered (linkChanged): this member, and their mode, are the previous link's.
1089
+ if (memberTokenFor(this.opts.base) !== link.token)
1090
+ return;
1091
+ this.member = member;
1092
+ // A dev-mode member starts on the pill next mount (face.ts startFace).
1093
+ rememberDisplayMode(mode);
1038
1094
  this.paint();
1039
1095
  }
1040
1096
  async openReports() {
@@ -1042,10 +1098,10 @@ export class ReportWidget {
1042
1098
  await this.loadReports();
1043
1099
  }
1044
1100
  async loadReports() {
1045
- const asked = this.whoToken();
1101
+ const asked = this.whoKey();
1046
1102
  const session = await this.refreshWho();
1047
- // The person changed meanwhile: whoChanged already reloads for the next one.
1048
- if (this.whoToken() !== asked)
1103
+ // The person or the member link changed meanwhile: whoChanged already reloads for the next one.
1104
+ if (this.whoKey() !== asked)
1049
1105
  return;
1050
1106
  if (!session) {
1051
1107
  this.mine = { rows: [], state: 'ok' };
@@ -1062,8 +1118,8 @@ export class ReportWidget {
1062
1118
  console.warn('vitrinka: My reports could not be loaded', e);
1063
1119
  mine = { rows: [], state: 'failed' };
1064
1120
  }
1065
- // A list read for the previous person is dropped; whoChanged already reloads for the next one.
1066
- if (this.whoToken() !== asked)
1121
+ // A list read for the previous person or link is dropped; whoChanged already reloads for the next one.
1122
+ if (this.whoKey() !== asked)
1067
1123
  return;
1068
1124
  this.mine = mine;
1069
1125
  this.paint();
@@ -1077,7 +1133,7 @@ export class ReportWidget {
1077
1133
  if (!(e instanceof VitrinkaApiError) || e.status !== 401)
1078
1134
  throw e;
1079
1135
  this.session = null;
1080
- this.sessionToken = '';
1136
+ this.sessionKey = '';
1081
1137
  const renewed = await this.refreshWho();
1082
1138
  if (!renewed)
1083
1139
  throw e;
@@ -1104,10 +1160,10 @@ export class ReportWidget {
1104
1160
  signal: flow.abort.signal,
1105
1161
  });
1106
1162
  // The link names the vitrinka it belongs to: face.ts offers the pill only on that base.
1163
+ // Storing it notifies: linkChanged reads the new member for an open card.
1107
1164
  storeLink({ ...linked, base });
1108
1165
  this.linkFlow = null;
1109
1166
  this.show('describe');
1110
- await this.refreshMember();
1111
1167
  }
1112
1168
  catch (e) {
1113
1169
  if (flow.abort.signal.aborted)
@@ -1626,6 +1682,7 @@ export class ReportWidget {
1626
1682
  // -- sending --------------------------------------------------------------
1627
1683
  envelope(description, capture) {
1628
1684
  const who = this.who();
1685
+ const member = memberTokenFor(this.opts.base);
1629
1686
  const loc = globalThis.location;
1630
1687
  return {
1631
1688
  title: titleOf(description),
@@ -1643,6 +1700,8 @@ export class ReportWidget {
1643
1700
  markers: toWire(this.markers),
1644
1701
  locale: this.locale,
1645
1702
  ...(this.kind ? { type: this.kind } : {}),
1703
+ // A member linked on this base co-owns the report; the `vkb_` key stays the bearer.
1704
+ ...(member ? { memberToken: member } : {}),
1646
1705
  };
1647
1706
  }
1648
1707
  /** The words the report goes with: the description, else the first mark's note — either one is enough to send. */
@@ -1684,7 +1743,8 @@ export class ReportWidget {
1684
1743
  const capture = engine ? await prepareCapture(() => engine.build(frozen, this.markers, marked)) : EMPTY_CAPTURE;
1685
1744
  this.job = new ReportJob(capture, globalThis.location?.host ?? '', { url: this.opts.base, key: this.opts.key }, this.files);
1686
1745
  }
1687
- this.result = await this.job.run(this.envelope(description, this.job.capture));
1746
+ // A refused member link is handled when the create answers, even if a later leg then fails.
1747
+ this.result = await this.job.run(this.envelope(description, this.job.capture), (err, sent) => this.memberRefused(err, sent));
1688
1748
  noteSent(this.opts.base, globalThis.location?.host ?? '', {
1689
1749
  title: titleOf(description),
1690
1750
  at: Date.now(),