@vitrinka/web 0.5.0 → 0.5.1

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,24 @@
1
1
  # @vitrinka/web
2
2
 
3
+ ## 0.5.1
4
+
5
+ - **A claim names its session.** The server answers a session's id as a
6
+ number, and 0.5.0 wrote it into `data-vitrinka-lead` as one. The codec
7
+ reads only a string, so the extension's refusals lost their `#N`, and the
8
+ page re-announced its hello on every state change. The recorder now keys a
9
+ session by the id's string from the moment it is created. The codec also
10
+ reads a 0.5.0 page's numeric id.
11
+ - **A page that holds the claim yields to the extension recording
12
+ elsewhere.** A tab that thaws after the extension started in another tab
13
+ (its Start probe could not reach a frozen tab) kept recording, so two
14
+ recordings ran. The page now releases its claim and waits, capturing
15
+ nothing, and resumes when the extension stops (D14). A Stop that is
16
+ already saving keeps its claim and its face.
17
+ - **`withRecorderLock` is exported** from `@vitrinka/web/recorder`. A custom
18
+ storage driver shared with the package's own driver on one origin (a
19
+ host's own dock key, say) can take the very lock the package numbers
20
+ events under, instead of copying it.
21
+
3
22
  ## 0.5.0
4
23
 
5
24
  - **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();
@@ -62,7 +62,8 @@ function desired(held) {
62
62
  const rec = getState();
63
63
  if (rec) {
64
64
  const state = stopping === rec.sessionId || stoppingElsewhere(rec) ? 'stopping' : rec.paused ? 'paused' : 'recording';
65
- return { state, sessionId: rec.sessionId };
65
+ // A session web 0.5.0 stored (and this version resumed) still carries the server's numeric id.
66
+ return { state, sessionId: String(rec.sessionId) };
66
67
  }
67
68
  // The stop's face still shows on this pill: hold the claim as `saved` (D7).
68
69
  if (held && (face === 'saving' || face === 'saved' || face === 'failed'))
@@ -82,6 +83,15 @@ function syncClaim() {
82
83
  return;
83
84
  }
84
85
  if (held) {
86
+ // The extension recording elsewhere keeps the browser even over a claim
87
+ // this page holds — a tab thawing after the extension's Start probe
88
+ // could not reach it, or a Start in the same instant: let go and wait
89
+ // (D14), never two recordings. A Stop already draining keeps its face.
90
+ if (want.state !== 'saved' && want.state !== 'stopping' && extensionLive()?.here === false) {
91
+ if (releaseClaim(env, self.inst))
92
+ announce(env, self, null);
93
+ return;
94
+ }
85
95
  if (held.state !== want.state || held.sessionId !== want.sessionId) {
86
96
  updateClaim(env, self.inst, want);
87
97
  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.1";
3
+ export declare const RECORDER_ID = "web/0.5.1";
@@ -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.1';
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.1",
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": {