@vitrinka/web 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @vitrinka/web
2
2
 
3
+ ## 0.5.2
4
+
5
+ - **A page that leads keeps the recording against an extension that is only
6
+ starting.** 0.5.1's yield (a page holding the claim lets go when the
7
+ extension records in another tab) also fired on the `starting` the
8
+ extension's Start probe announces before it reads the page's claim. The
9
+ page stepped aside and the extension's Start went through instead of being
10
+ refused (extension 0.11.0 against web 0.5.1). The page now yields only to
11
+ an extension recording or paused elsewhere; a probe meets the claim and is
12
+ refused, as first-to-start-leads demands.
13
+
14
+ ## 0.5.1
15
+
16
+ - **A claim names its session.** The server answers a session's id as a
17
+ number, and 0.5.0 wrote it into `data-vitrinka-lead` as one. The codec
18
+ reads only a string, so the extension's refusals lost their `#N`, and the
19
+ page re-announced its hello on every state change. The recorder now keys a
20
+ session by the id's string from the moment it is created. The codec also
21
+ reads a 0.5.0 page's numeric id.
22
+ - **A page that holds the claim yields to the extension recording
23
+ elsewhere.** A tab that thaws after the extension started in another tab
24
+ (its Start probe could not reach a frozen tab) kept recording, so two
25
+ recordings ran. The page now releases its claim and waits, capturing
26
+ nothing, and resumes when the extension stops (D14). A Stop that is
27
+ already saving keeps its claim and its face.
28
+ - **`withRecorderLock` is exported** from `@vitrinka/web/recorder`. A custom
29
+ storage driver shared with the package's own driver on one origin (a
30
+ host's own dock key, say) can take the very lock the package numbers
31
+ events under, instead of copying it.
32
+
3
33
  ## 0.5.0
4
34
 
5
35
  - **The page recorder and the Vitrinka extension are one recorder.** A page
package/README.md CHANGED
@@ -362,6 +362,9 @@ Web Lock, or an IndexedDB transaction on hosts without Web Locks. Stop
362
362
  waits for these allocations before draining. A custom driver shared across
363
363
  documents must implement `withLock(name, run)` and run the synchronous
364
364
  callback exclusively across them; a document-local driver needs no lock.
365
+ A driver that shares an origin with the package's own (e.g. one that
366
+ re-keys a single entry) passes the package's `withRecorderLock` from
367
+ `@vitrinka/web/recorder`, so both number events under the same lock.
365
368
  Shared drivers also implement `keys()` to coordinate Stop: each mounted tab
366
369
  ships its last rrweb batch and drains its captures before acknowledging.
367
370
  An undelivered sibling tail refuses Stop and stays queued for retry.
package/build/one.iife.js CHANGED
@@ -1 +1 @@
1
- (()=>{var{defineProperty:E,getOwnPropertyNames:z,getOwnPropertyDescriptor:K}=Object,B=Object.prototype.hasOwnProperty;function j(e){return this[e]}var G=(e)=>{var n=(w??=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 w.set(e,n),n},w;var J=(e)=>e;function W(e,n){this[e]=J.bind(null,n)}var Z=(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 _={};Z(_,{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:()=>F,holderAnswers:()=>V,isLive:()=>k,markPage:()=>rn,nonce:()=>h,pageMarked:()=>an,parseAck:()=>R,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 S(e,n,t,o={}){let r=e,i=r.__zone_symbol__addEventListener??e.addEventListener,a=r.__zone_symbol__removeEventListener??e.removeEventListener,p=o.capture??!1;return i.call(e,n,t,{capture:p,passive:!1}),()=>a.call(e,n,t,p)}var u=1,d="data-vitrinka-page",l="data-vitrinka-lead",c="vitrinka:hello",x="vitrinka:command",C="vitrinka:ack";function F(){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:"",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 R(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 N(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 r={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 N(e,r),{ok:!0,claim:r}}function en(e,n,t){let o=b(e);if(o?.id!==n)return!1;return N(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 S(e.bus,n,(o)=>t(o.detail))}function M(e,n){let t=[],o=O(e,c,(r)=>{let i=A(r);if(i&&!i.ask&&i.inst!==n.inst)t.push(i)});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,r={}){return O(e,c,(i)=>{let a=A(i);if(!a||a.inst===n.inst)return;if(!a.ask)o?.(a);else if(r.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 r=h("c"),i=null,a=O(e,C,(p)=>{let m=R(p);if(m&&m.id===r&&m.inst!==n.inst&&!i)i=m});try{y(e,x,{v:u,from:n.from,inst:n.inst,id:r,op:t,...o!==void 0?{text:o}:{}})}finally{a()}return i}function dn(e,n,t){return O(e,x,(o)=>{let r=P(o);if(!r||r.inst===n.inst)return;let i=t(r);if(!i)return;y(e,C,{v:u,from:n.from,inst:n.inst,id:r.id,...i})})}globalThis.VitrinkaOne=Object.freeze({..._});})();
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({..._});})();
@@ -15,6 +15,7 @@ export type { RecorderControl, RecorderStatus } from './control';
15
15
  export type { RecorderConfig } from './config';
16
16
  export { type Leader, RecorderBusyError } from './lead';
17
17
  export { configureRecorderStorage, type RecorderStorage } from './storage';
18
+ export { withRecorderLock } from './storage/lock';
18
19
  export interface VitrinkaRecorderRootProps {
19
20
  /** vitrinka base URL; defaults to `NEXT_PUBLIC_VITRINKA_URL`. */
20
21
  url?: string;
@@ -18,6 +18,7 @@ import { getRecorderStorage } from './storage';
18
18
  export { useRecorderRoute };
19
19
  export { RecorderBusyError } from './lead';
20
20
  export { configureRecorderStorage } from './storage';
21
+ export { withRecorderLock } from './storage/lock';
21
22
  /** Wrap the app root. Starts the capture lanes only when `url` + `key` are present. */
22
23
  export function VitrinkaRecorderRoot(props) {
23
24
  const env = envConfig();
@@ -42,6 +42,17 @@ function extensionLive() {
42
42
  return l;
43
43
  return null;
44
44
  }
45
+ /**
46
+ * The extension's recording is under way in another tab. Its Start probe
47
+ * announces `starting` before it reads this page's claim, and a draining
48
+ * Stop is ending: neither takes a document from the page that leads (D1).
49
+ */
50
+ function extensionRecordingElsewhere() {
51
+ for (const l of extension.values())
52
+ if (!l.here && (l.state === 'recording' || l.state === 'paused'))
53
+ return true;
54
+ return false;
55
+ }
45
56
  /** A claim of another holder (any state: a `saved` one keeps its face, D7), else the extension elsewhere. */
46
57
  function computeFollowing() {
47
58
  if (!env)
@@ -62,7 +73,8 @@ function desired(held) {
62
73
  const rec = getState();
63
74
  if (rec) {
64
75
  const state = stopping === rec.sessionId || stoppingElsewhere(rec) ? 'stopping' : rec.paused ? 'paused' : 'recording';
65
- return { state, sessionId: rec.sessionId };
76
+ // A session web 0.5.0 stored (and this version resumed) still carries the server's numeric id.
77
+ return { state, sessionId: String(rec.sessionId) };
66
78
  }
67
79
  // The stop's face still shows on this pill: hold the claim as `saved` (D7).
68
80
  if (held && (face === 'saving' || face === 'saved' || face === 'failed'))
@@ -82,6 +94,17 @@ function syncClaim() {
82
94
  return;
83
95
  }
84
96
  if (held) {
97
+ // The extension recording elsewhere keeps the browser even over a claim
98
+ // this page holds — a tab thawing after the extension's Start probe
99
+ // could not reach it, or a Start whose probe ran before this claim: let
100
+ // go and wait (D14), never two recordings. Only a recording under way
101
+ // counts — a probe's `starting` meets this claim and is refused (D13).
102
+ // A Stop already draining here keeps its face.
103
+ if (want.state !== 'saved' && want.state !== 'stopping' && extensionRecordingElsewhere()) {
104
+ if (releaseClaim(env, self.inst))
105
+ announce(env, self, null);
106
+ return;
107
+ }
85
108
  if (held.state !== want.state || held.sessionId !== want.sessionId) {
86
109
  updateClaim(env, self.inst, want);
87
110
  announce(env, self, liveOf());
@@ -74,7 +74,8 @@ export function parseClaim(raw) {
74
74
  by: b.by,
75
75
  id: b.id,
76
76
  state: b.state,
77
- sessionId: str(b.sessionId) ? b.sessionId : '',
77
+ // web 0.5.0 pages wrote the server's numeric id.
78
+ sessionId: str(b.sessionId) ? b.sessionId : Number.isFinite(b.sessionId) ? String(b.sessionId) : '',
78
79
  since: typeof b.since === 'number' ? b.since : 0,
79
80
  };
80
81
  }
@@ -148,7 +148,8 @@ export function createSession(title, opts = {}) {
148
148
  ...(cfg.appVersion ? { appVersion: cfg.appVersion } : {}),
149
149
  ...opts.meta,
150
150
  },
151
- });
151
+ // The server's id is an int64; the recorder keys a session by its string (claims, recents, storage).
152
+ }).then((s) => ({ ...s, id: String(s.id) }));
152
153
  }
153
154
  /**
154
155
  * Start a recording. The claim on this document comes first, synchronously
@@ -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.5.0";
3
- export declare const RECORDER_ID = "web/0.5.0";
2
+ export declare const RECORDER_VERSION = "0.5.2";
3
+ export declare const RECORDER_ID = "web/0.5.2";
@@ -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.5.0';
2
+ export const RECORDER_VERSION = '0.5.2';
3
3
  export const RECORDER_ID = `web/${RECORDER_VERSION}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitrinka/web",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
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": {