@rxova/journey-devtools-bridge 0.7.0 → 1.0.0-rc.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/README.md CHANGED
@@ -1,49 +1,44 @@
1
1
  # @rxova/journey-devtools-bridge
2
2
 
3
- Bridge that connects Journey machines to the browser devtools extension.
3
+ Connect Journey machines to Chrome DevTools.
4
+
5
+ <p>
6
+ <a href="https://www.npmjs.com/package/@rxova/journey-devtools-bridge">
7
+ <img src="https://img.shields.io/npm/v/@rxova/journey-devtools-bridge?color=0f8f6a" alt="npm" />
8
+ </a>
9
+ <img src="https://img.shields.io/badge/3.2%20kB-brotli-0f8f6a" alt="size" />
10
+ </p>
4
11
 
5
12
  ## Install
6
13
 
7
14
  ```bash
8
- pnpm add @rxova/journey-devtools-bridge
9
- yarn add @rxova/journey-devtools-bridge
10
15
  npm i @rxova/journey-devtools-bridge
11
- bun add @rxova/journey-devtools-bridge
12
16
  ```
13
17
 
14
- The bridge can run in Bun-based browser apps; explicit `enabled: true` remains the safest option when your bundler does not expose a dev/prod env signal.
15
-
16
18
  ## Usage
17
19
 
18
20
  ```ts
19
21
  import { createJourneyMachine } from "@rxova/journey-core";
20
22
  import { attachJourneyDevtools } from "@rxova/journey-devtools-bridge";
21
23
 
22
- const machine = createJourneyMachine(journey);
24
+ const machine = createJourneyMachine(definition);
25
+ machine.startJourney();
23
26
 
24
- const detach = attachJourneyDevtools(machine, {
25
- label: "Checkout Flow"
26
- });
27
+ const detach = attachJourneyDevtools(machine, { label: "Checkout" });
27
28
  ```
28
29
 
29
- ## Protocol Notes
30
+ ## What It Does
30
31
 
31
- Bridge command support includes:
32
+ - Streams snapshots and lifecycle events to the Journey DevTools panel in Chrome
33
+ - Supports remote commands: navigate steps, reset, send events, inspect execution paths
34
+ - Enabled by default in development, disabled in production unless explicitly opted in
32
35
 
33
- - `goToNextStep`, `terminateMachine`, `completeJourney`, `resetMachine`
34
- - `goToStepById`
35
- - `goToPreviousStep`
36
- - `goToLastVisitedStep`
37
- - `updateStepMetadata`
38
- - `send` (custom event)
39
- - `clearStepError`
36
+ ## Documentation
40
37
 
41
- Snapshots include `history.timeline`, `history.index`, `currentStepId`, `visited`, `stepMeta`, `status`, and `async`.
38
+ - [Chrome DevTools Overview](https://rxova.org/docs/devtool/overview)
39
+ - [Panel Guide](https://rxova.org/docs/devtool/panel-guide)
40
+ - [Bridge API](https://rxova.org/docs/bridge/bridge-api)
42
41
 
43
- ## Runtime Defaults
42
+ ## License
44
43
 
45
- - Defaults use `import.meta.env.DEV` / `import.meta.env.PROD` when available, otherwise `process.env.NODE_ENV`.
46
- - Enabled by default in non-production browser runtimes.
47
- - Disabled in production unless `enabled: true`.
48
- - Commands disabled in production unless `commandsEnabled: true`.
49
- - If neither env source is available, bridge and commands default to disabled unless explicitly enabled.
44
+ MIT
@@ -0,0 +1,29 @@
1
+ import type { JourneyJsonObject, JourneyMachine } from "@rxova/journey-core";
2
+ type JourneyDevtoolsPersistencePluginMetadata = {
3
+ key?: string;
4
+ clearOnReset?: boolean;
5
+ };
6
+ export type JourneyDevtoolsBridgeOptions = {
7
+ machineId?: string;
8
+ label?: string;
9
+ enabled?: boolean;
10
+ appName?: string;
11
+ commandsEnabled?: boolean;
12
+ pluginMetadata?: {
13
+ persistence?: JourneyDevtoolsPersistencePluginMetadata;
14
+ };
15
+ };
16
+ type JourneyImportMetaEnv = {
17
+ DEV?: unknown;
18
+ PROD?: unknown;
19
+ };
20
+ export declare const resolveNonProductionEnvironment: (options?: {
21
+ bundlerEnv?: JourneyImportMetaEnv | null | undefined;
22
+ nodeEnv?: string | undefined;
23
+ }) => boolean;
24
+ /**
25
+ * Attaches a journey machine to the browser devtools transport and returns
26
+ * a detach function that unsubscribes listeners and unregisters the machine.
27
+ */
28
+ export declare const attachJourneyDevtools: <TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, TStepMeta = unknown, THandlers extends Record<string, unknown> = Record<never, never>>(machine: JourneyMachine<TContext, TStepId, TEventMap, TStepMeta, THandlers>, options?: JourneyDevtoolsBridgeOptions) => (() => void);
29
+ export {};
package/dist/bridge.d.ts CHANGED
@@ -1,10 +1,17 @@
1
- import type { JourneyEventPayloadMap, JourneyMachine } from "@rxova/journey-core";
1
+ import type { JourneyJsonObject, JourneyMachine } from "@rxova/journey-core";
2
+ type JourneyDevtoolsPersistencePluginMetadata = {
3
+ key?: string;
4
+ clearOnReset?: boolean;
5
+ };
2
6
  export type JourneyDevtoolsBridgeOptions = {
3
7
  machineId?: string;
4
8
  label?: string;
5
9
  enabled?: boolean;
6
10
  appName?: string;
7
11
  commandsEnabled?: boolean;
12
+ pluginMetadata?: {
13
+ persistence?: JourneyDevtoolsPersistencePluginMetadata;
14
+ };
8
15
  };
9
16
  type JourneyImportMetaEnv = {
10
17
  DEV?: unknown;
@@ -18,5 +25,5 @@ export declare const resolveNonProductionEnvironment: (options?: {
18
25
  * Attaches a journey machine to the browser devtools transport and returns
19
26
  * a detach function that unsubscribes listeners and unregisters the machine.
20
27
  */
21
- export declare const attachJourneyDevtools: <TContext, TStepId extends string, TEventType extends string, TPayloadMap extends JourneyEventPayloadMap<TEventType>, TStepMeta>(machine: JourneyMachine<TContext, TStepId, TEventType, TPayloadMap, TStepMeta>, options?: JourneyDevtoolsBridgeOptions) => (() => void);
28
+ export declare const attachJourneyDevtools: <TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, TStepMeta = unknown, THandlers extends Record<string, unknown> = Record<never, never>>(machine: JourneyMachine<TContext, TStepId, TEventMap, TStepMeta, THandlers>, options?: JourneyDevtoolsBridgeOptions) => (() => void);
22
29
  export {};
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var x=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var $=(e,t)=>{for(var n in t)x(e,n,{get:t[n],enumerable:!0})},Z=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of F(t))!W.call(e,a)&&a!==n&&x(e,a,{get:()=>t[a],enumerable:!(o=K(t,a))||o.enumerable});return e};var Q=e=>Z(x({},"__esModule",{value:!0}),e);var ye={};$(ye,{JOURNEY_DEVTOOLS_BRIDGE_SOURCE:()=>S,JOURNEY_DEVTOOLS_CHANNEL:()=>v,JOURNEY_DEVTOOLS_EXTENSION_SOURCE:()=>g,JOURNEY_DEVTOOLS_PROTOCOL_VERSION:()=>D,attachJourneyDevtools:()=>Y,isJourneyDevtoolsBridgeEnvelope:()=>b,isJourneyDevtoolsCommand:()=>_,isJourneyDevtoolsEnvelope:()=>O,isJourneyDevtoolsExtensionEnvelope:()=>C});module.exports=Q(ye);var D=3,v="__RXOVA_JOURNEY_DEVTOOLS__",S="rxova-journey-bridge",g="rxova-journey-extension",p=e=>typeof e=="object"&&e!==null,ee=e=>e===S||e===g;var E=e=>{try{let t=JSON.stringify(e);if(t!==void 0&&t.length>5e5)return!1}catch{return!1}return R(e,0)},R=(e,t)=>t>10?!1:e==null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"?!0:typeof e!="object"?!1:Array.isArray(e)?e.every(n=>R(n,t+1)):Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null?!1:Object.values(e).every(n=>R(n,t+1)),A=e=>p(e)?e.channel===v&&e.version===3&&ee(e.source)&&typeof e.kind=="string"&&typeof e.machineId=="string"&&typeof e.timestamp=="number":!1,te=e=>!p(e)||typeof e.type!="string"||e.type.length===0||e.type.length>100?!1:"payload"in e&&e.payload!==void 0?E(e.payload):!0,_=e=>{if(!p(e)||typeof e.type!="string"||e.type.length===0||e.type.length>50)return!1;switch(e.type){case"goToNextStep":case"terminateMachine":case"completeJourney":case"resetMachine":case"goToLastVisitedStep":return Object.keys(e).length===1;case"goToStepById":return typeof e.stepId=="string"&&e.stepId.length>0&&e.stepId.length<=100&&Object.keys(e).length===2;case"goToPreviousStep":return(e.steps===void 0||typeof e.steps=="number"&&Number.isInteger(e.steps)&&e.steps>=1&&e.steps<=1e4)&&Object.keys(e).length<=2;case"send":return te(e.event)&&Object.keys(e).length===2;case"updateStepMetadata":return typeof e.stepId=="string"&&e.stepId.length>0&&e.stepId.length<=100&&E(e.metadata)&&Object.keys(e).length===3;case"clearStepError":return(e.stepId===void 0||typeof e.stepId=="string"&&e.stepId.length<=100)&&Object.keys(e).length<=2;default:return!1}},b=e=>{if(!A(e)||e.source!==S)return!1;let t=e;switch(e.kind){case"register":return p(t.meta)&&p(t.snapshot)&&E(t.meta)&&E(t.snapshot);case"unregister":return!0;case"snapshot":return p(t.snapshot)&&E(t.snapshot);case"commandResult":return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&p(t.snapshot)&&E(t.snapshot)&&(!("error"in t)||p(t.error));case"commandError":return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&p(t.error);default:return!1}},C=e=>{if(!A(e)||e.source!==g||e.kind!=="command")return!1;let t=e;return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&_(t.command)},O=e=>b(e)||C(e);var le={},ne="Journey Machine",V=e=>typeof e=="object"&&e!==null,oe=e=>e==="idle"||e==="evaluating-when"||e==="running-effect"||e==="error",re=e=>V(e)?e.PROD===!0?!1:e.DEV===!0?!0:null:null,se=e=>typeof e!="string"?null:e!=="production",P=(e={})=>{let t="bundlerEnv"in e?e.bundlerEnv:le.env,n="nodeEnv"in e?e.nodeEnv:typeof process<"u"?process.env?.NODE_ENV:void 0;return re(t)??se(n)??!1},ie=()=>typeof window>"u"||window.location.origin==="null"?"*":window.location.origin,ae=e=>{if(e.length===0||typeof window>"u")return!1;let t=window.location.origin;return t==="null"?e==="null":e===t},pe=()=>`journey-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,B=class{constructor(t=100,n=1e4){this.commandTimestamps=[];this.maxCommandsPerWindow=t,this.windowMs=n}isAllowed(){let t=Date.now(),n=t-this.windowMs;return this.commandTimestamps=this.commandTimestamps.filter(o=>o>n),this.commandTimestamps.length>=this.maxCommandsPerWindow?!1:(this.commandTimestamps.push(t),!0)}reset(){this.commandTimestamps=[]}},f=e=>{let t=typeof structuredClone=="function"?(()=>{try{return structuredClone(e)}catch{return e}})():e,n=new WeakSet;try{let o=JSON.stringify(t,(a,s)=>{if(typeof s=="bigint")return s.toString();if(typeof s=="function")return`[Function ${s.name||"anonymous"}]`;if(typeof s=="symbol")return s.toString();if(typeof s=="object"&&s!==null){if(n.has(s))return"[Circular]";n.add(s)}return s});return o===void 0?void 0:JSON.parse(o)}catch{return String(e)}},T=e=>{if(e instanceof Error){let t="cause"in e&&e.cause!==void 0?e.cause:null;return{name:e.name,message:e.message,stack:typeof e.stack=="string"?e.stack:null,cause:f(t)}}return{name:null,message:typeof e=="string"?e:"Unknown error",stack:null,cause:f(e)}},M=e=>{let t={};for(let[n,o]of Object.entries(e.async.byStep))V(o)&&(t[n]={phase:oe(o.phase)?o.phase:"idle",eventType:typeof o.eventType=="string"?o.eventType:null,transitionId:typeof o.transitionId=="string"?o.transitionId:null,error:o.error===null?null:f(o.error)});return{currentStepId:String(e.currentStepId),context:f(e.context),history:{timeline:e.history.timeline.map(n=>String(n)),index:e.history.index},visited:Object.fromEntries(Object.entries(e.visited).map(([n,o])=>[String(n),o===!0])),stepMeta:f(e.stepMeta),status:e.status,async:{isLoading:e.async.isLoading,byStep:t}}},de=(e,t)=>t in e.stepMeta,N=(e,t,n)=>{if(!de(e.getSnapshot(),t))throw new Error(`Unknown stepId "${t}" for "${n}" command.`);return t},m=e=>({snapshot:e.snapshot,transitioned:e.transitioned,...e.transitionId?{transitionId:e.transitionId}:{},..."error"in e?{error:T(e.error)}:{}}),ue=async(e,t)=>{switch(t.type){case"goToNextStep":case"completeJourney":{let n=await e.send({type:t.type});return m(n)}case"terminateMachine":{let n=await e.send({type:"terminateJourney"});return m(n)}case"goToStepById":{let n=N(e,t.stepId,t.type),o=await e.send({type:"goToStepById",stepId:n});return m(o)}case"goToPreviousStep":{let n=await e.goToPreviousStep(t.steps);return m(n)}case"goToLastVisitedStep":{let n=await e.goToLastVisitedStep();return m(n)}case"send":{let n=t.event.payload===void 0?{type:t.event.type}:{type:t.event.type,payload:t.event.payload},o=await e.send(n);return m(o)}case"updateStepMetadata":{let n=N(e,t.stepId,t.type);return{snapshot:e.updateStepMetadata(n,()=>t.metadata)}}case"resetMachine":return{snapshot:e.resetMachine()};case"clearStepError":{let n=t.stepId===void 0?void 0:N(e,t.stepId,t.type);return{snapshot:e.clearStepError(n)}}}},Y=(e,t={})=>{if(!(t.enabled??P())||typeof window>"u")return()=>{};let o=t.commandsEnabled??P(),a=t.machineId?.trim()||pe(),s={machineId:a,label:t.label?.trim()||ne,appName:t.appName?.trim()||(typeof document<"u"?document.title:"")||null,commandsEnabled:o},j=ie(),u=r=>({channel:v,version:3,source:S,kind:r,machineId:a,timestamp:Date.now()}),l=r=>{try{window.postMessage(r,j)}catch{}},q=r=>{let d={...u("snapshot"),snapshot:M(r)};l(d)},y=!1,k=new B,h=null,c=null,J=null,I=()=>{h=null,c=null,J=null},L=()=>{let r=h;I(),!(!r||y)&&q(r)},z=r=>{if(h=r,c===null){if(typeof window.requestAnimationFrame=="function"){J="raf",c=window.requestAnimationFrame(()=>{L()});return}J="timeout",c=globalThis.setTimeout(()=>{L()},0)}},X=()=>{if(c===null){I();return}J==="raf"&&typeof window.cancelAnimationFrame=="function"?window.cancelAnimationFrame(c):globalThis.clearTimeout(c),I()},U=r=>{if(r.source!==window||!ae(r.origin)||y||!O(r.data)||r.data.source!==g||r.data.kind!=="command")return;let d=r.data;if(d.machineId!==a)return;if(!k.isAllowed()){let i={...u("commandError"),requestId:d.requestId,error:T("Command rate limit exceeded. Too many commands in a short time window.")};l(i);return}if(!o){let i={...u("commandError"),requestId:d.requestId,error:T("Bridge commands are disabled by configuration.")};l(i);return}(async()=>{try{let i=await ue(e,d.command);if(y)return;let w={...u("commandResult"),requestId:d.requestId,snapshot:M(i.snapshot),...i.transitioned!==void 0?{transitioned:i.transitioned}:{},...i.transitionId?{transitionId:i.transitionId}:{},..."error"in i?{error:i.error}:{}};l(w)}catch(i){if(y)return;let w={...u("commandError"),requestId:d.requestId,error:T(i)};l(w)}})()};window.addEventListener("message",U);let G=e.subscribe(()=>{y||z(e.getSnapshot())}),H={...u("register"),meta:s,snapshot:M(e.getSnapshot())};return l(H),()=>{if(y)return;y=!0,k.reset(),G(),window.removeEventListener("message",U),X();let r={...u("unregister")};l(r)}};0&&(module.exports={JOURNEY_DEVTOOLS_BRIDGE_SOURCE,JOURNEY_DEVTOOLS_CHANNEL,JOURNEY_DEVTOOLS_EXTENSION_SOURCE,JOURNEY_DEVTOOLS_PROTOCOL_VERSION,attachJourneyDevtools,isJourneyDevtoolsBridgeEnvelope,isJourneyDevtoolsCommand,isJourneyDevtoolsEnvelope,isJourneyDevtoolsExtensionEnvelope});
1
+ "use strict";var R=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var se=Object.prototype.hasOwnProperty;var ie=(e,t)=>{for(var n in t)R(e,n,{get:t[n],enumerable:!0})},ae=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of re(t))!se.call(e,a)&&a!==n&&R(e,a,{get:()=>t[a],enumerable:!(o=oe(t,a))||o.enumerable});return e};var ue=e=>ae(R({},"__esModule",{value:!0}),e);var ke={};ie(ke,{JOURNEY_DEVTOOLS_BRIDGE_SOURCE:()=>v,JOURNEY_DEVTOOLS_CHANNEL:()=>m,JOURNEY_DEVTOOLS_EXTENSION_SOURCE:()=>g,JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION:()=>A,JOURNEY_DEVTOOLS_PROTOCOL_VERSION:()=>T,attachJourneyDevtools:()=>G,isJourneyDevtoolsBridgeEnvelope:()=>_,isJourneyDevtoolsCommand:()=>C,isJourneyDevtoolsEnvelope:()=>f,isJourneyDevtoolsExtensionEnvelope:()=>P});module.exports=ue(ke);var T=4,A=3,m="__RXOVA_JOURNEY_DEVTOOLS__",v="rxova-journey-bridge",g="rxova-journey-extension",i=e=>typeof e=="object"&&e!==null,pe=e=>e===v||e===g,le=e=>e===3||e===4,de=["startJourney","goToNextStep","terminateJourney","completeJourney","goToStepById","goToPreviousStep","goToLastVisitedStep","send","resetJourney","clearStepError","getExecutionPaths"],ye=e=>typeof e=="string"&&de.includes(e);var S=e=>{try{let t=JSON.stringify(e);if(t!==void 0&&t.length>5e5)return!1}catch{return!1}return I(e,0)},I=(e,t)=>t>10?!1:e==null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"?!0:typeof e!="object"?!1:Array.isArray(e)?e.every(n=>I(n,t+1)):Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null?!1:Object.values(e).every(n=>I(n,t+1)),Y=e=>i(e)?e.channel===m&&le(e.version)&&pe(e.source)&&typeof e.kind=="string"&&typeof e.machineId=="string"&&typeof e.timestamp=="number":!1,w=(e,t=1e4)=>typeof e=="number"&&Number.isInteger(e)&&e>=1&&e<=t,ce=e=>i(e)?Object.keys(e).length<=2&&(e.maxDepth===void 0||w(e.maxDepth))&&(e.maxPaths===void 0||w(e.maxPaths)):!1,Ee=e=>!i(e)||typeof e.type!="string"||e.type.length===0||e.type.length>100?!1:"payload"in e&&e.payload!==void 0?S(e.payload):!0,V=e=>!i(e)||typeof e.observe!="boolean"||typeof e.executionPaths!="boolean"||!Array.isArray(e.commands)||!e.commands.every(t=>ye(t))?!1:e.persistence===void 0?!0:i(e.persistence)?(e.persistence.key===null||typeof e.persistence.key=="string")&&(e.persistence.clearOnReset===null||typeof e.persistence.clearOnReset=="boolean"):!1,ve=(e,t)=>i(e)?typeof e.machineId=="string"&&typeof e.label=="string"&&(e.appName===null||typeof e.appName=="string")&&(e.commandsEnabled===void 0||typeof e.commandsEnabled=="boolean")&&(t===3&&e.capabilities===void 0||V(e.capabilities)):!1,ge=e=>i(e)?typeof e.type=="string"&&e.type.length>0&&e.type.length<=100&&typeof e.timestamp=="number"&&S(e):!1,Je=e=>{if(!i(e)||!Array.isArray(e.paths))return!1;let t=n=>n==="final"||n==="depth"||n==="cycle"||n==="limit";return e.paths.every(n=>i(n)&&Array.isArray(n.steps)&&n.steps.every(o=>typeof o=="string")&&Array.isArray(n.events)&&n.events.every(o=>typeof o=="string")&&t(n.terminated))&&typeof e.truncated=="boolean"&&typeof e.cyclesDetected=="boolean"},C=e=>{if(!i(e)||typeof e.type!="string"||e.type.length===0||e.type.length>50)return!1;switch(e.type){case"startJourney":case"goToNextStep":case"terminateJourney":case"completeJourney":case"resetJourney":case"goToLastVisitedStep":return Object.keys(e).length===1;case"goToStepById":return typeof e.stepId=="string"&&e.stepId.length>0&&e.stepId.length<=100&&Object.keys(e).length===2;case"goToPreviousStep":return(e.steps===void 0||w(e.steps))&&Object.keys(e).length<=2;case"send":return Ee(e.event)&&Object.keys(e).length===2;case"clearStepError":return(e.stepId===void 0||typeof e.stepId=="string"&&e.stepId.length<=100)&&Object.keys(e).length<=2;case"getExecutionPaths":return(e.options===void 0||ce(e.options))&&Object.keys(e).length<=2;default:return!1}},_=e=>{if(!Y(e)||e.source!==v)return!1;let t=e;switch(e.kind){case"register":return ve(t.meta,e.version)&&i(t.snapshot)&&S(t.snapshot);case"unregister":return!0;case"snapshot":return i(t.snapshot)&&S(t.snapshot);case"observation":return ge(t.event);case"commandResult":return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&i(t.snapshot)&&S(t.snapshot)&&(!("error"in t)||i(t.error));case"executionPathsResult":return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&Je(t.result);case"commandError":return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&i(t.error);default:return!1}},P=e=>{if(!Y(e)||e.source!==g||e.kind!=="command")return!1;let t=e;return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&C(t.command)},f=e=>_(e)||P(e);var Pe={},Se="Journey Machine",me=["startJourney","goToNextStep","terminateJourney","completeJourney","goToStepById","goToPreviousStep","goToLastVisitedStep","send","resetJourney","clearStepError"],q=e=>typeof e=="object"&&e!==null,Oe=e=>e==="idle"||e==="evaluating-when"||e==="error",he=e=>q(e)?e.PROD===!0?!1:e.DEV===!0?!0:null:null,Te=e=>typeof e!="string"?null:e!=="production",j=(e={})=>{let t="bundlerEnv"in e?e.bundlerEnv:Pe.env,n="nodeEnv"in e?e.nodeEnv:typeof process<"u"?process.env?.NODE_ENV:void 0;return he(t)??Te(n)??!1},fe=()=>typeof window>"u"||window.location.origin==="null"?"*":window.location.origin,De=e=>{if(e.length===0||typeof window>"u")return!1;let t=window.location.origin;return t==="null"?e==="null":e===t},xe=()=>`journey-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,N=class{constructor(t=100,n=1e4){this.commandTimestamps=[];this.maxCommandsPerWindow=t,this.windowMs=n}isAllowed(){let t=Date.now(),n=t-this.windowMs;return this.commandTimestamps=this.commandTimestamps.filter(o=>o>n),this.commandTimestamps.length>=this.maxCommandsPerWindow?!1:(this.commandTimestamps.push(t),!0)}reset(){this.commandTimestamps=[]}},E=e=>{let t=typeof structuredClone=="function"?(()=>{try{return structuredClone(e)}catch{return e}})():e,n=new WeakSet;try{let o=JSON.stringify(t,(a,p)=>{if(typeof p=="bigint")return p.toString();if(typeof p=="function")return`[Function ${p.name||"anonymous"}]`;if(typeof p=="symbol")return p.toString();if(typeof p=="object"&&p!==null){if(n.has(p))return"[Circular]";n.add(p)}return p});return o===void 0?void 0:JSON.parse(o)}catch{return String(e)}},O=e=>{if(e instanceof Error){let t="cause"in e&&e.cause!==void 0?e.cause:null;return{name:e.name,message:e.message,stack:typeof e.stack=="string"?e.stack:null,cause:E(t)}}return{name:null,message:typeof e=="string"?e:"Unknown error",stack:null,cause:E(e)}},k=e=>{let t={};for(let[n,o]of Object.entries(e.async.byStep))q(o)&&(t[n]={phase:Oe(o.phase)?o.phase:"idle",eventType:typeof o.eventType=="string"?o.eventType:null,transitionId:typeof o.transitionId=="string"?o.transitionId:null,error:o.error===null?null:E(o.error)});return{currentStepId:String(e.currentStepId),context:E(e.context),history:{timeline:e.history.timeline.map(n=>String(n)),index:e.history.index},visited:Object.fromEntries(Object.entries(e.visited).map(([n,o])=>[String(n),o===!0])),status:e.status,async:{isLoading:e.async.isLoading,byStep:t}}},be=e=>e.type==="transition.error"?E({...e,error:O(e.error)}):E(e),Re=e=>E(e),Ie=(e,t)=>t in e.async.byStep,z=(e,t,n)=>{if(!Ie(e.getSnapshot(),t))throw new Error(`Unknown stepId "${t}" for "${n}" command.`);return t},J=e=>({kind:"snapshot",snapshot:e.snapshot,transitioned:e.transitioned,...e.transitionId?{transitionId:e.transitionId}:{},..."error"in e?{error:O(e.error)}:{}}),H=e=>typeof e.getExecutionPaths=="function",we=e=>e.type==="getExecutionPaths",Ce=(e,t,n)=>{let o=H(e),a=[];return n&&a.push(...me),o&&a.push("getExecutionPaths"),{commands:a,observe:!0,executionPaths:o,...t.pluginMetadata?.persistence?{persistence:{key:t.pluginMetadata.persistence.key?.trim()||null,clearOnReset:typeof t.pluginMetadata.persistence.clearOnReset=="boolean"?t.pluginMetadata.persistence.clearOnReset:null}}:{}}},_e=async(e,t)=>{switch(t.type){case"startJourney":return{kind:"snapshot",snapshot:await e.startJourney()};case"goToNextStep":case"completeJourney":{let n=await e.send({type:t.type});return J(n)}case"terminateJourney":{let n=await e.send({type:"terminateJourney"});return J(n)}case"goToStepById":{let n=z(e,t.stepId,t.type),o=await e.send({type:"goToStepById",stepId:n});return J(o)}case"goToPreviousStep":{let n=await e.goToPreviousStep(t.steps);return J(n)}case"goToLastVisitedStep":{let n=await e.goToLastVisitedStep();return J(n)}case"send":{let n=t.event.payload===void 0?{type:t.event.type}:{type:t.event.type,payload:t.event.payload},o=await e.send(n);return J(o)}case"resetJourney":return{kind:"snapshot",snapshot:await e.resetJourney()};case"clearStepError":{let n=t.stepId===void 0?void 0:z(e,t.stepId,t.type);return{kind:"snapshot",snapshot:await e.clearStepError(n)}}case"getExecutionPaths":{if(!H(e))throw new Error('Machine does not support "getExecutionPaths".');return{kind:"executionPaths",result:e.getExecutionPaths(t.options)}}}},G=(e,t={})=>{if(!(t.enabled??j())||typeof window>"u")return()=>{};let o=t.commandsEnabled??j(),a=t.machineId?.trim()||xe(),p=fe(),X=Ce(e,t,o),K={machineId:a,label:t.label?.trim()||Se,appName:t.appName?.trim()||(typeof document<"u"?document.title:"")||null,commandsEnabled:o,capabilities:X},l=r=>({channel:m,version:4,source:v,kind:r,machineId:a,timestamp:Date.now()}),d=r=>{try{window.postMessage(r,p)}catch{}},F=r=>{let u={...l("snapshot"),snapshot:k(r)};d(u)},W=r=>{let u={...l("observation"),event:be(r)};d(u)},$=(r,u)=>{let U={...l("executionPathsResult"),requestId:r,result:Re(u)};d(U)},y=!1,M=new N,D=null,c=null,h=null,x=()=>{D=null,c=null,h=null},B=()=>{let r=D;x(),!(!r||y)&&F(r)},Z=r=>{if(D=r,c===null){if(typeof window.requestAnimationFrame=="function"){h="raf",c=window.requestAnimationFrame(()=>{B()});return}h="timeout",c=globalThis.setTimeout(()=>{B()},0)}},Q=()=>{if(c===null){x();return}h==="raf"&&typeof window.cancelAnimationFrame=="function"?window.cancelAnimationFrame(c):globalThis.clearTimeout(c),x()},L=r=>{if(r.source!==window||!De(r.origin)||y||!f(r.data)||r.data.source!==g||r.data.kind!=="command")return;let u=r.data;if(u.machineId!==a)return;if(!M.isAllowed()){let s={...l("commandError"),requestId:u.requestId,error:O("Command rate limit exceeded. Too many commands in a short time window.")};d(s);return}if(!o&&!we(u.command)){let s={...l("commandError"),requestId:u.requestId,error:O("Bridge commands are disabled by configuration.")};d(s);return}(async()=>{try{let s=await _e(e,u.command);if(y)return;if(s.kind==="executionPaths"){$(u.requestId,s.result);return}let b={...l("commandResult"),requestId:u.requestId,snapshot:k(s.snapshot),...s.transitioned!==void 0?{transitioned:s.transitioned}:{},...s.transitionId?{transitionId:s.transitionId}:{},..."error"in s?{error:s.error}:{}};d(b)}catch(s){if(y)return;let b={...l("commandError"),requestId:u.requestId,error:O(s)};d(b)}})()};window.addEventListener("message",L);let ee=e.subscribe(()=>{y||Z(e.getSnapshot())}),te={...l("register"),meta:K,snapshot:k(e.getSnapshot())};d(te);let ne=e.subscribeEvent(r=>{y||W(r)});return()=>{if(y)return;y=!0,M.reset(),ne(),ee(),window.removeEventListener("message",L),Q();let r={...l("unregister")};d(r)}};0&&(module.exports={JOURNEY_DEVTOOLS_BRIDGE_SOURCE,JOURNEY_DEVTOOLS_CHANNEL,JOURNEY_DEVTOOLS_EXTENSION_SOURCE,JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION,JOURNEY_DEVTOOLS_PROTOCOL_VERSION,attachJourneyDevtools,isJourneyDevtoolsBridgeEnvelope,isJourneyDevtoolsCommand,isJourneyDevtoolsEnvelope,isJourneyDevtoolsExtensionEnvelope});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts", "../src/protocol.ts", "../src/bridge.ts"],
4
- "sourcesContent": ["export { attachJourneyDevtools, type JourneyDevtoolsBridgeOptions } from \"./bridge\";\n\nexport {\n JOURNEY_DEVTOOLS_CHANNEL,\n JOURNEY_DEVTOOLS_PROTOCOL_VERSION,\n JOURNEY_DEVTOOLS_BRIDGE_SOURCE,\n JOURNEY_DEVTOOLS_EXTENSION_SOURCE,\n isJourneyDevtoolsCommand,\n isJourneyDevtoolsEnvelope,\n isJourneyDevtoolsBridgeEnvelope,\n isJourneyDevtoolsExtensionEnvelope,\n type JourneyDevtoolsBridgeCommandErrorEnvelope,\n type JourneyDevtoolsBridgeCommandResultEnvelope,\n type JourneyDevtoolsBridgeEnvelope,\n type JourneyDevtoolsBridgeRegisterEnvelope,\n type JourneyDevtoolsBridgeSnapshotEnvelope,\n type JourneyDevtoolsBridgeUnregisterEnvelope,\n type JourneyDevtoolsCommand,\n type JourneyDevtoolsEnvelope,\n type JourneyDevtoolsExtensionEnvelope,\n type JourneyDevtoolsExtensionCommandEnvelope,\n type JourneyDevtoolsMachineMeta,\n type JourneyDevtoolsSerializableSnapshot,\n type JourneyDevtoolsSerializedError\n} from \"./protocol\";\n", "import type { JourneySnapshot, JourneyStepAsyncState } from \"@rxova/journey-core\";\n\nexport const JOURNEY_DEVTOOLS_PROTOCOL_VERSION = 3 as const;\nexport const JOURNEY_DEVTOOLS_CHANNEL = \"__RXOVA_JOURNEY_DEVTOOLS__\" as const;\n\nexport const JOURNEY_DEVTOOLS_BRIDGE_SOURCE = \"rxova-journey-bridge\" as const;\nexport const JOURNEY_DEVTOOLS_EXTENSION_SOURCE = \"rxova-journey-extension\" as const;\n\nexport type JourneyDevtoolsSource =\n | typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE\n | typeof JOURNEY_DEVTOOLS_EXTENSION_SOURCE;\n\nexport type JourneyDevtoolsStepAsyncState = JourneyStepAsyncState;\n\nexport type JourneyDevtoolsSerializableSnapshot = JourneySnapshot<unknown, string>;\n\nexport type JourneyDevtoolsMachineMeta = {\n machineId: string;\n label: string;\n appName: string | null;\n commandsEnabled?: boolean;\n};\n\nexport type JourneyDevtoolsSerializedError = {\n name: string | null;\n message: string;\n stack: string | null;\n cause: unknown;\n};\n\nexport type JourneyDevtoolsCommand =\n | { type: \"goToNextStep\" }\n | { type: \"terminateMachine\" }\n | { type: \"completeJourney\" }\n | { type: \"goToStepById\"; stepId: string }\n | { type: \"goToPreviousStep\"; steps?: number }\n | { type: \"goToLastVisitedStep\" }\n | { type: \"send\"; event: { type: string; payload?: unknown } }\n | { type: \"updateStepMetadata\"; stepId: string; metadata: unknown }\n | { type: \"resetMachine\" }\n | { type: \"clearStepError\"; stepId?: string };\n\nexport type JourneyDevtoolsEnvelopeBase = {\n channel: typeof JOURNEY_DEVTOOLS_CHANNEL;\n version: typeof JOURNEY_DEVTOOLS_PROTOCOL_VERSION;\n source: JourneyDevtoolsSource;\n kind: string;\n machineId: string;\n timestamp: number;\n};\n\nexport type JourneyDevtoolsBridgeRegisterEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"register\";\n meta: JourneyDevtoolsMachineMeta;\n snapshot: JourneyDevtoolsSerializableSnapshot;\n};\n\nexport type JourneyDevtoolsBridgeUnregisterEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"unregister\";\n};\n\nexport type JourneyDevtoolsBridgeSnapshotEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"snapshot\";\n snapshot: JourneyDevtoolsSerializableSnapshot;\n};\n\nexport type JourneyDevtoolsBridgeCommandResultEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"commandResult\";\n requestId: string;\n snapshot: JourneyDevtoolsSerializableSnapshot;\n transitioned?: boolean;\n transitionId?: string;\n error?: JourneyDevtoolsSerializedError;\n};\n\nexport type JourneyDevtoolsBridgeCommandErrorEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"commandError\";\n requestId: string;\n error: JourneyDevtoolsSerializedError;\n};\n\nexport type JourneyDevtoolsExtensionCommandEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_EXTENSION_SOURCE;\n kind: \"command\";\n requestId: string;\n command: JourneyDevtoolsCommand;\n};\n\nexport type JourneyDevtoolsBridgeEnvelope =\n | JourneyDevtoolsBridgeRegisterEnvelope\n | JourneyDevtoolsBridgeUnregisterEnvelope\n | JourneyDevtoolsBridgeSnapshotEnvelope\n | JourneyDevtoolsBridgeCommandResultEnvelope\n | JourneyDevtoolsBridgeCommandErrorEnvelope;\n\nexport type JourneyDevtoolsExtensionEnvelope = JourneyDevtoolsExtensionCommandEnvelope;\n\nexport type JourneyDevtoolsEnvelope =\n | JourneyDevtoolsBridgeEnvelope\n | JourneyDevtoolsExtensionEnvelope;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nconst isKnownSource = (value: unknown): value is JourneyDevtoolsSource =>\n value === JOURNEY_DEVTOOLS_BRIDGE_SOURCE || value === JOURNEY_DEVTOOLS_EXTENSION_SOURCE;\n\n/**\n * Maximum depth for nested object validation.\n * Prevents stack overflow and excessive processing from deeply nested malicious payloads.\n */\nconst MAX_PAYLOAD_DEPTH = 10;\n\n/**\n * Maximum size (in JSON string length) for serialized payloads.\n * Prevents memory exhaustion from extremely large payloads.\n */\nconst MAX_PAYLOAD_SIZE = 500_000; // 500KB\n\n/**\n * Validates that a value is safe for transport.\n * Checks size via a single serialization pass, then validates\n * depth, types, and prototype safety via a structure walk.\n */\nconst isSafePayload = (value: unknown): boolean => {\n try {\n const serialized = JSON.stringify(value);\n if (serialized !== undefined && serialized.length > MAX_PAYLOAD_SIZE) {\n return false;\n }\n } catch {\n return false;\n }\n\n return isStructureSafe(value, 0);\n};\n\nconst isStructureSafe = (value: unknown, depth: number): boolean => {\n if (depth > MAX_PAYLOAD_DEPTH) {\n return false;\n }\n\n if (value === null || value === undefined) {\n return true;\n }\n\n if (typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\") {\n return true;\n }\n\n if (typeof value !== \"object\") {\n return false;\n }\n\n if (Array.isArray(value)) {\n return value.every((item) => isStructureSafe(item, depth + 1));\n }\n\n if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {\n return false;\n }\n\n return Object.values(value).every((prop) => isStructureSafe(prop, depth + 1));\n};\n\nconst hasBaseEnvelopeShape = (value: unknown): value is JourneyDevtoolsEnvelopeBase => {\n if (!isRecord(value)) {\n return false;\n }\n\n return (\n value.channel === JOURNEY_DEVTOOLS_CHANNEL &&\n value.version === JOURNEY_DEVTOOLS_PROTOCOL_VERSION &&\n isKnownSource(value.source) &&\n typeof value.kind === \"string\" &&\n typeof value.machineId === \"string\" &&\n typeof value.timestamp === \"number\"\n );\n};\n\nconst isSendEvent = (value: unknown): value is { type: string; payload?: unknown } => {\n if (!isRecord(value)) {\n return false;\n }\n\n if (typeof value.type !== \"string\" || value.type.length === 0 || value.type.length > 100) {\n return false;\n }\n\n // Validate payload if present\n if (\"payload\" in value && value.payload !== undefined) {\n return isSafePayload(value.payload);\n }\n\n return true;\n};\n\n/**\n * Validates whether an unknown value is a supported devtools command payload.\n */\nexport const isJourneyDevtoolsCommand = (value: unknown): value is JourneyDevtoolsCommand => {\n if (!isRecord(value) || typeof value.type !== \"string\") {\n return false;\n }\n\n // Validate command type is within reasonable length\n if (value.type.length === 0 || value.type.length > 50) {\n return false;\n }\n\n switch (value.type) {\n case \"goToNextStep\":\n case \"terminateMachine\":\n case \"completeJourney\":\n case \"resetMachine\":\n case \"goToLastVisitedStep\":\n // These commands should have no extra properties beyond type\n return Object.keys(value).length === 1;\n case \"goToStepById\":\n return (\n typeof value.stepId === \"string\" &&\n value.stepId.length > 0 &&\n value.stepId.length <= 100 &&\n Object.keys(value).length === 2\n );\n case \"goToPreviousStep\":\n return (\n (value.steps === undefined ||\n (typeof value.steps === \"number\" &&\n Number.isInteger(value.steps) &&\n value.steps >= 1 &&\n value.steps <= 10000)) &&\n Object.keys(value).length <= 2\n );\n case \"send\":\n return isSendEvent(value.event) && Object.keys(value).length === 2;\n case \"updateStepMetadata\":\n return (\n typeof value.stepId === \"string\" &&\n value.stepId.length > 0 &&\n value.stepId.length <= 100 &&\n isSafePayload(value.metadata) &&\n Object.keys(value).length === 3\n );\n case \"clearStepError\":\n return (\n (value.stepId === undefined ||\n (typeof value.stepId === \"string\" && value.stepId.length <= 100)) &&\n Object.keys(value).length <= 2\n );\n default:\n return false;\n }\n};\n\n/**\n * Validates whether an unknown value is a bridge-origin envelope.\n */\nexport const isJourneyDevtoolsBridgeEnvelope = (\n value: unknown\n): value is JourneyDevtoolsBridgeEnvelope => {\n if (!hasBaseEnvelopeShape(value) || value.source !== JOURNEY_DEVTOOLS_BRIDGE_SOURCE) {\n return false;\n }\n\n const envelope = value as Record<string, unknown>;\n\n switch (value.kind) {\n case \"register\":\n return (\n isRecord(envelope.meta) &&\n isRecord(envelope.snapshot) &&\n isSafePayload(envelope.meta) &&\n isSafePayload(envelope.snapshot)\n );\n case \"unregister\":\n return true;\n case \"snapshot\":\n return isRecord(envelope.snapshot) && isSafePayload(envelope.snapshot);\n case \"commandResult\":\n return (\n typeof envelope.requestId === \"string\" &&\n envelope.requestId.length > 0 &&\n envelope.requestId.length <= 100 &&\n isRecord(envelope.snapshot) &&\n isSafePayload(envelope.snapshot) &&\n (!(\"error\" in envelope) || isRecord(envelope.error))\n );\n case \"commandError\":\n return (\n typeof envelope.requestId === \"string\" &&\n envelope.requestId.length > 0 &&\n envelope.requestId.length <= 100 &&\n isRecord(envelope.error)\n );\n default:\n return false;\n }\n};\n\n/**\n * Validates whether an unknown value is an extension-origin command envelope.\n */\nexport const isJourneyDevtoolsExtensionEnvelope = (\n value: unknown\n): value is JourneyDevtoolsExtensionEnvelope => {\n if (!hasBaseEnvelopeShape(value) || value.source !== JOURNEY_DEVTOOLS_EXTENSION_SOURCE) {\n return false;\n }\n\n if (value.kind !== \"command\") {\n return false;\n }\n\n const envelope = value as Record<string, unknown>;\n return (\n typeof envelope.requestId === \"string\" &&\n envelope.requestId.length > 0 &&\n envelope.requestId.length <= 100 &&\n isJourneyDevtoolsCommand(envelope.command)\n );\n};\n\n/**\n * Validates whether an unknown value matches either supported devtools envelope shape.\n */\nexport const isJourneyDevtoolsEnvelope = (value: unknown): value is JourneyDevtoolsEnvelope =>\n isJourneyDevtoolsBridgeEnvelope(value) || isJourneyDevtoolsExtensionEnvelope(value);\n", "import type {\n JourneyEventPayloadMap,\n JourneyMachine,\n JourneySendResult,\n JourneySnapshot\n} from \"@rxova/journey-core\";\nimport {\n JOURNEY_DEVTOOLS_BRIDGE_SOURCE,\n JOURNEY_DEVTOOLS_CHANNEL,\n JOURNEY_DEVTOOLS_EXTENSION_SOURCE,\n JOURNEY_DEVTOOLS_PROTOCOL_VERSION,\n isJourneyDevtoolsEnvelope,\n type JourneyDevtoolsBridgeCommandErrorEnvelope,\n type JourneyDevtoolsBridgeCommandResultEnvelope,\n type JourneyDevtoolsBridgeEnvelope,\n type JourneyDevtoolsBridgeRegisterEnvelope,\n type JourneyDevtoolsBridgeSnapshotEnvelope,\n type JourneyDevtoolsBridgeUnregisterEnvelope,\n type JourneyDevtoolsCommand,\n type JourneyDevtoolsExtensionCommandEnvelope,\n type JourneyDevtoolsMachineMeta,\n type JourneyDevtoolsSerializableSnapshot,\n type JourneyDevtoolsSerializedError\n} from \"./protocol\";\n\ndeclare const process: { env?: { NODE_ENV?: string } } | undefined;\n\nexport type JourneyDevtoolsBridgeOptions = {\n machineId?: string;\n label?: string;\n enabled?: boolean;\n appName?: string;\n commandsEnabled?: boolean;\n};\n\ntype SendOutcome<TContext, TStepId extends string, TStepMeta> = {\n snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>;\n transitioned?: boolean;\n transitionId?: string;\n error?: JourneyDevtoolsSerializedError;\n};\n\ntype SnapshotScheduleKind = \"raf\" | \"timeout\";\n\nconst DEFAULT_MACHINE_LABEL = \"Journey Machine\";\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nconst isJourneyAsyncPhase = (\n value: unknown\n): value is JourneyDevtoolsSerializableSnapshot[\"async\"][\"byStep\"][string][\"phase\"] =>\n value === \"idle\" ||\n value === \"evaluating-when\" ||\n value === \"running-effect\" ||\n value === \"error\";\n\ntype JourneyImportMetaEnv = {\n DEV?: unknown;\n PROD?: unknown;\n};\n\nconst resolveImportMetaEnvironment = (\n bundlerEnv: JourneyImportMetaEnv | null | undefined\n): boolean | null => {\n if (!isRecord(bundlerEnv)) {\n return null;\n }\n\n if (bundlerEnv.PROD === true) {\n return false;\n }\n\n if (bundlerEnv.DEV === true) {\n return true;\n }\n\n return null;\n};\n\nconst resolveNodeEnvironment = (nodeEnv: string | undefined): boolean | null => {\n if (typeof nodeEnv !== \"string\") {\n return null;\n }\n\n return nodeEnv !== \"production\";\n};\n\nexport const resolveNonProductionEnvironment = (\n options: {\n bundlerEnv?: JourneyImportMetaEnv | null | undefined;\n nodeEnv?: string | undefined;\n } = {}\n): boolean => {\n const resolvedBundlerEnv =\n \"bundlerEnv\" in options\n ? options.bundlerEnv\n : (import.meta as ImportMeta & { env?: JourneyImportMetaEnv }).env;\n const resolvedNodeEnv =\n \"nodeEnv\" in options\n ? options.nodeEnv\n : typeof process !== \"undefined\"\n ? process.env?.NODE_ENV\n : undefined;\n\n return (\n resolveImportMetaEnvironment(resolvedBundlerEnv) ??\n resolveNodeEnvironment(resolvedNodeEnv) ??\n false\n );\n};\n\nconst resolveWindowTargetOrigin = (): string => {\n if (typeof window === \"undefined\") {\n return \"*\";\n }\n\n return window.location.origin === \"null\" ? \"*\" : window.location.origin;\n};\n\n// No session token infrastructure needed\n\n/**\n * Validates that the message origin matches the current window origin.\n * This prevents messages from other origins from being processed.\n *\n * Note: This is part of defense-in-depth but not a hard security boundary.\n * Code running in the same origin can still send messages.\n */\nconst isExpectedWindowOrigin = (origin: string): boolean => {\n if (origin.length === 0) {\n return false;\n }\n\n if (typeof window === \"undefined\") {\n return false;\n }\n\n const expected = window.location.origin;\n if (expected === \"null\") {\n // For file:// or sandboxed contexts where origin is \"null\"\n return origin === \"null\";\n }\n\n // Strict equality check - no wildcard matching\n return origin === expected;\n};\n\nconst createMachineId = (): string =>\n `journey-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;\n\n/**\n * Simple rate limiter to prevent command abuse.\n * Tracks command timestamps and enforces a maximum rate.\n */\nclass CommandRateLimiter {\n private commandTimestamps: number[] = [];\n private readonly maxCommandsPerWindow: number;\n private readonly windowMs: number;\n\n constructor(maxCommandsPerWindow = 100, windowMs = 10000) {\n this.maxCommandsPerWindow = maxCommandsPerWindow;\n this.windowMs = windowMs;\n }\n\n /**\n * Checks if a command is allowed based on rate limits.\n * Returns true if allowed, false if rate limit exceeded.\n */\n isAllowed(): boolean {\n const now = Date.now();\n const windowStart = now - this.windowMs;\n\n // Remove old timestamps outside the window\n this.commandTimestamps = this.commandTimestamps.filter((ts) => ts > windowStart);\n\n if (this.commandTimestamps.length >= this.maxCommandsPerWindow) {\n return false;\n }\n\n this.commandTimestamps.push(now);\n return true;\n }\n\n reset(): void {\n this.commandTimestamps = [];\n }\n}\n\nconst cloneForTransport = (value: unknown): unknown => {\n const transportValue =\n typeof structuredClone === \"function\"\n ? (() => {\n try {\n return structuredClone(value);\n } catch {\n return value;\n }\n })()\n : value;\n const seen = new WeakSet<object>();\n\n try {\n const serialized = JSON.stringify(transportValue, (_key, currentValue) => {\n if (typeof currentValue === \"bigint\") {\n return currentValue.toString();\n }\n if (typeof currentValue === \"function\") {\n return `[Function ${currentValue.name || \"anonymous\"}]`;\n }\n if (typeof currentValue === \"symbol\") {\n return currentValue.toString();\n }\n if (typeof currentValue === \"object\" && currentValue !== null) {\n if (seen.has(currentValue)) {\n return \"[Circular]\";\n }\n seen.add(currentValue);\n }\n return currentValue;\n });\n\n if (serialized === undefined) {\n return undefined;\n }\n\n return JSON.parse(serialized) as unknown;\n } catch {\n return String(value);\n }\n};\n\nconst serializeError = (error: unknown): JourneyDevtoolsSerializedError => {\n if (error instanceof Error) {\n const cause =\n \"cause\" in error && (error as { cause?: unknown }).cause !== undefined\n ? (error as { cause?: unknown }).cause\n : null;\n return {\n name: error.name,\n message: error.message,\n stack: typeof error.stack === \"string\" ? error.stack : null,\n cause: cloneForTransport(cause)\n };\n }\n\n return {\n name: null,\n message: typeof error === \"string\" ? error : \"Unknown error\",\n stack: null,\n cause: cloneForTransport(error)\n };\n};\n\nconst serializeSnapshot = <TContext, TStepId extends string, TStepMeta>(\n snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>\n): JourneyDevtoolsSerializableSnapshot => {\n const byStep: Record<string, JourneyDevtoolsSerializableSnapshot[\"async\"][\"byStep\"][string]> = {};\n\n for (const [stepId, stepState] of Object.entries(\n snapshot.async.byStep as Record<string, unknown>\n )) {\n if (!isRecord(stepState)) {\n continue;\n }\n\n byStep[stepId] = {\n phase: isJourneyAsyncPhase(stepState.phase) ? stepState.phase : \"idle\",\n eventType: typeof stepState.eventType === \"string\" ? stepState.eventType : null,\n transitionId: typeof stepState.transitionId === \"string\" ? stepState.transitionId : null,\n error: stepState.error === null ? null : cloneForTransport(stepState.error)\n };\n }\n\n return {\n currentStepId: String(snapshot.currentStepId),\n context: cloneForTransport(snapshot.context),\n history: {\n timeline: snapshot.history.timeline.map((stepId) => String(stepId)),\n index: snapshot.history.index\n },\n visited: Object.fromEntries(\n Object.entries(snapshot.visited as Record<string, boolean>).map(([stepId, isVisited]) => [\n String(stepId),\n isVisited === true\n ])\n ),\n stepMeta: cloneForTransport(snapshot.stepMeta) as Record<string, unknown>,\n status: snapshot.status,\n async: {\n isLoading: snapshot.async.isLoading,\n byStep\n }\n };\n};\n\nconst isKnownStepId = <TContext, TStepId extends string, TStepMeta>(\n snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>,\n stepId: string\n): stepId is TStepId => stepId in snapshot.stepMeta;\n\nconst assertKnownStepId = <TContext, TStepId extends string, TStepMeta>(\n machine: JourneyMachine<TContext, TStepId, string, Record<never, never>, TStepMeta>,\n stepId: string,\n commandType: JourneyDevtoolsCommand[\"type\"]\n): TStepId => {\n if (!isKnownStepId(machine.getSnapshot(), stepId)) {\n throw new Error(`Unknown stepId \"${stepId}\" for \"${commandType}\" command.`);\n }\n return stepId;\n};\n\nconst toSendOutcome = <TContext, TStepId extends string, TStepMeta>(\n result: JourneySendResult<TContext, TStepId, TStepMeta>\n): SendOutcome<TContext, TStepId, TStepMeta> => ({\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {}),\n ...(\"error\" in result ? { error: serializeError(result.error) } : {})\n});\n\nconst runCommand = async <TContext, TStepId extends string, TStepMeta>(\n machine: JourneyMachine<TContext, TStepId, string, Record<never, never>, TStepMeta>,\n command: JourneyDevtoolsCommand\n): Promise<SendOutcome<TContext, TStepId, TStepMeta>> => {\n switch (command.type) {\n case \"goToNextStep\":\n case \"completeJourney\": {\n const result = await machine.send({ type: command.type });\n return toSendOutcome(result);\n }\n case \"terminateMachine\": {\n const result = await machine.send({ type: \"terminateJourney\" });\n return toSendOutcome(result);\n }\n case \"goToStepById\": {\n const stepId = assertKnownStepId(machine, command.stepId, command.type);\n const result = await machine.send({\n type: \"goToStepById\",\n stepId\n });\n return toSendOutcome(result);\n }\n case \"goToPreviousStep\": {\n const result = await machine.goToPreviousStep(command.steps);\n return toSendOutcome(result);\n }\n case \"goToLastVisitedStep\": {\n const result = await machine.goToLastVisitedStep();\n return toSendOutcome(result);\n }\n case \"send\": {\n const sendEvent =\n command.event.payload === undefined\n ? { type: command.event.type }\n : { type: command.event.type, payload: command.event.payload };\n const result: JourneySendResult<TContext, TStepId, TStepMeta> = await machine.send(sendEvent);\n return toSendOutcome(result);\n }\n case \"updateStepMetadata\": {\n const stepId = assertKnownStepId(machine, command.stepId, command.type);\n return {\n snapshot: machine.updateStepMetadata(stepId, () => command.metadata as TStepMeta)\n };\n }\n case \"resetMachine\":\n return {\n snapshot: machine.resetMachine()\n };\n case \"clearStepError\": {\n const stepId =\n command.stepId === undefined\n ? undefined\n : assertKnownStepId(machine, command.stepId, command.type);\n return {\n snapshot: machine.clearStepError(stepId)\n };\n }\n }\n};\n\n/**\n * Attaches a journey machine to the browser devtools transport and returns\n * a detach function that unsubscribes listeners and unregisters the machine.\n */\nexport const attachJourneyDevtools = <\n TContext,\n TStepId extends string,\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType>,\n TStepMeta\n>(\n machine: JourneyMachine<TContext, TStepId, TEventType, TPayloadMap, TStepMeta>,\n options: JourneyDevtoolsBridgeOptions = {}\n): (() => void) => {\n const enabled = options.enabled ?? resolveNonProductionEnvironment();\n if (!enabled || typeof window === \"undefined\") {\n return () => {};\n }\n const commandsEnabled = options.commandsEnabled ?? resolveNonProductionEnvironment();\n\n const machineId = options.machineId?.trim() || createMachineId();\n const meta: JourneyDevtoolsMachineMeta = {\n machineId,\n label: options.label?.trim() || DEFAULT_MACHINE_LABEL,\n appName:\n options.appName?.trim() || (typeof document !== \"undefined\" ? document.title : \"\") || null,\n commandsEnabled\n };\n const targetOrigin = resolveWindowTargetOrigin();\n\n const createBaseEnvelope = <TKind extends JourneyDevtoolsBridgeEnvelope[\"kind\"]>(\n kind: TKind\n ) => ({\n channel: JOURNEY_DEVTOOLS_CHANNEL,\n version: JOURNEY_DEVTOOLS_PROTOCOL_VERSION,\n source: JOURNEY_DEVTOOLS_BRIDGE_SOURCE,\n kind,\n machineId,\n timestamp: Date.now()\n });\n\n const post = (envelope: JourneyDevtoolsBridgeEnvelope) => {\n try {\n window.postMessage(envelope, targetOrigin);\n } catch {\n // Swallow transport failures so bridge lifecycle and commands remain non-throwing.\n }\n };\n\n const postSnapshot = (snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>) => {\n const envelope: JourneyDevtoolsBridgeSnapshotEnvelope = {\n ...createBaseEnvelope(\"snapshot\"),\n snapshot: serializeSnapshot(snapshot)\n };\n post(envelope);\n };\n\n let isDetached = false;\n const rateLimiter = new CommandRateLimiter();\n let pendingSnapshot: JourneySnapshot<TContext, TStepId, TStepMeta> | null = null;\n let scheduledSnapshotHandle: number | ReturnType<typeof globalThis.setTimeout> | null = null;\n let scheduledSnapshotKind: SnapshotScheduleKind | null = null;\n\n const clearScheduledSnapshotState = () => {\n pendingSnapshot = null;\n scheduledSnapshotHandle = null;\n scheduledSnapshotKind = null;\n };\n\n const flushScheduledSnapshot = () => {\n const snapshot = pendingSnapshot;\n clearScheduledSnapshotState();\n\n if (!snapshot || isDetached) {\n return;\n }\n\n postSnapshot(snapshot);\n };\n\n const scheduleSnapshotPost = (snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>) => {\n pendingSnapshot = snapshot;\n if (scheduledSnapshotHandle !== null) {\n return;\n }\n\n if (typeof window.requestAnimationFrame === \"function\") {\n scheduledSnapshotKind = \"raf\";\n scheduledSnapshotHandle = window.requestAnimationFrame(() => {\n flushScheduledSnapshot();\n });\n return;\n }\n\n scheduledSnapshotKind = \"timeout\";\n scheduledSnapshotHandle = globalThis.setTimeout(() => {\n flushScheduledSnapshot();\n }, 0);\n };\n\n const cancelScheduledSnapshot = () => {\n if (scheduledSnapshotHandle === null) {\n clearScheduledSnapshotState();\n return;\n }\n\n if (scheduledSnapshotKind === \"raf\" && typeof window.cancelAnimationFrame === \"function\") {\n window.cancelAnimationFrame(scheduledSnapshotHandle as number);\n } else {\n globalThis.clearTimeout(scheduledSnapshotHandle);\n }\n\n clearScheduledSnapshotState();\n };\n\n const onMessage = (event: MessageEvent<unknown>) => {\n if (\n event.source !== window ||\n !isExpectedWindowOrigin(event.origin) ||\n isDetached ||\n !isJourneyDevtoolsEnvelope(event.data)\n ) {\n return;\n }\n\n if (event.data.source !== JOURNEY_DEVTOOLS_EXTENSION_SOURCE || event.data.kind !== \"command\") {\n return;\n }\n\n const commandEnvelope: JourneyDevtoolsExtensionCommandEnvelope = event.data;\n if (commandEnvelope.machineId !== machineId) {\n return;\n }\n\n // Rate limiting to prevent command abuse\n if (!rateLimiter.isAllowed()) {\n const errorEnvelope: JourneyDevtoolsBridgeCommandErrorEnvelope = {\n ...createBaseEnvelope(\"commandError\"),\n requestId: commandEnvelope.requestId,\n error: serializeError(\n \"Command rate limit exceeded. Too many commands in a short time window.\"\n )\n };\n post(errorEnvelope);\n return;\n }\n\n if (!commandsEnabled) {\n const errorEnvelope: JourneyDevtoolsBridgeCommandErrorEnvelope = {\n ...createBaseEnvelope(\"commandError\"),\n requestId: commandEnvelope.requestId,\n error: serializeError(\"Bridge commands are disabled by configuration.\")\n };\n post(errorEnvelope);\n return;\n }\n\n const run = async () => {\n try {\n const outcome = await runCommand(\n machine as JourneyMachine<TContext, TStepId, string, Record<never, never>, TStepMeta>,\n commandEnvelope.command\n );\n if (isDetached) {\n return;\n }\n\n const resultEnvelope: JourneyDevtoolsBridgeCommandResultEnvelope = {\n ...createBaseEnvelope(\"commandResult\"),\n requestId: commandEnvelope.requestId,\n snapshot: serializeSnapshot(outcome.snapshot),\n ...(outcome.transitioned !== undefined ? { transitioned: outcome.transitioned } : {}),\n ...(outcome.transitionId ? { transitionId: outcome.transitionId } : {}),\n ...(\"error\" in outcome ? { error: outcome.error } : {})\n };\n post(resultEnvelope);\n } catch (error) {\n if (isDetached) {\n return;\n }\n\n const errorEnvelope: JourneyDevtoolsBridgeCommandErrorEnvelope = {\n ...createBaseEnvelope(\"commandError\"),\n requestId: commandEnvelope.requestId,\n error: serializeError(error)\n };\n post(errorEnvelope);\n }\n };\n\n void run();\n };\n\n window.addEventListener(\"message\", onMessage);\n\n const unsubscribe = machine.subscribe(() => {\n if (isDetached) {\n return;\n }\n scheduleSnapshotPost(machine.getSnapshot());\n });\n\n const registerEnvelope: JourneyDevtoolsBridgeRegisterEnvelope = {\n ...createBaseEnvelope(\"register\"),\n meta,\n snapshot: serializeSnapshot(machine.getSnapshot())\n };\n post(registerEnvelope);\n\n return () => {\n if (isDetached) {\n return;\n }\n\n isDetached = true;\n rateLimiter.reset();\n unsubscribe();\n window.removeEventListener(\"message\", onMessage);\n cancelScheduledSnapshot();\n\n const unregisterEnvelope: JourneyDevtoolsBridgeUnregisterEnvelope = {\n ...createBaseEnvelope(\"unregister\")\n };\n post(unregisterEnvelope);\n };\n};\n"],
5
- "mappings": "yaAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,oCAAAE,EAAA,6BAAAC,EAAA,sCAAAC,EAAA,sCAAAC,EAAA,0BAAAC,EAAA,oCAAAC,EAAA,6BAAAC,EAA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GACbC,EAAY,MAAM,EAClBgB,EAAY,EACZ,OAAO,oBAAoB,UAAWR,CAAS,EAC/CD,EAAwB,EAExB,IAAMW,EAA8D,CAClE,GAAG1B,EAAmB,YAAY,CACpC,EACAI,EAAKsB,CAAkB,CACzB,CACF",
6
- "names": ["index_exports", "__export", "JOURNEY_DEVTOOLS_BRIDGE_SOURCE", "JOURNEY_DEVTOOLS_CHANNEL", "JOURNEY_DEVTOOLS_EXTENSION_SOURCE", "JOURNEY_DEVTOOLS_PROTOCOL_VERSION", "attachJourneyDevtools", "isJourneyDevtoolsBridgeEnvelope", "isJourneyDevtoolsCommand", "isJourneyDevtoolsEnvelope", "isJourneyDevtoolsExtensionEnvelope", "__toCommonJS", "JOURNEY_DEVTOOLS_PROTOCOL_VERSION", "JOURNEY_DEVTOOLS_CHANNEL", "JOURNEY_DEVTOOLS_BRIDGE_SOURCE", "JOURNEY_DEVTOOLS_EXTENSION_SOURCE", "isRecord", "value", "isKnownSource", "isSafePayload", "value", "serialized", "isStructureSafe", "depth", "item", "prop", "hasBaseEnvelopeShape", "isRecord", "JOURNEY_DEVTOOLS_CHANNEL", "isKnownSource", "isSendEvent", "isJourneyDevtoolsCommand", "isJourneyDevtoolsBridgeEnvelope", "JOURNEY_DEVTOOLS_BRIDGE_SOURCE", "envelope", "isJourneyDevtoolsExtensionEnvelope", "JOURNEY_DEVTOOLS_EXTENSION_SOURCE", "isJourneyDevtoolsEnvelope", "import_meta", "DEFAULT_MACHINE_LABEL", "isRecord", "value", "isJourneyAsyncPhase", "resolveImportMetaEnvironment", "bundlerEnv", "resolveNodeEnvironment", "nodeEnv", "resolveNonProductionEnvironment", "options", "resolvedBundlerEnv", "resolvedNodeEnv", "resolveWindowTargetOrigin", "isExpectedWindowOrigin", "origin", "expected", "createMachineId", "CommandRateLimiter", "maxCommandsPerWindow", "windowMs", "now", "windowStart", "ts", "cloneForTransport", "transportValue", "seen", "serialized", "_key", "currentValue", "serializeError", "error", "cause", "serializeSnapshot", "snapshot", "byStep", "stepId", "stepState", "isVisited", "isKnownStepId", "assertKnownStepId", "machine", "commandType", "toSendOutcome", "result", "runCommand", "command", "sendEvent", "attachJourneyDevtools", "commandsEnabled", "machineId", "meta", "targetOrigin", "createBaseEnvelope", "kind", "JOURNEY_DEVTOOLS_CHANNEL", "JOURNEY_DEVTOOLS_BRIDGE_SOURCE", "post", "envelope", "postSnapshot", "isDetached", "rateLimiter", "pendingSnapshot", "scheduledSnapshotHandle", "scheduledSnapshotKind", "clearScheduledSnapshotState", "flushScheduledSnapshot", "scheduleSnapshotPost", "cancelScheduledSnapshot", "onMessage", "event", "isJourneyDevtoolsEnvelope", "JOURNEY_DEVTOOLS_EXTENSION_SOURCE", "commandEnvelope", "errorEnvelope", "outcome", "resultEnvelope", "unsubscribe", "registerEnvelope", "unregisterEnvelope"]
4
+ "sourcesContent": ["export { attachJourneyDevtools, type JourneyDevtoolsBridgeOptions } from \"./bridge\";\n\nexport {\n JOURNEY_DEVTOOLS_CHANNEL,\n JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION,\n JOURNEY_DEVTOOLS_PROTOCOL_VERSION,\n JOURNEY_DEVTOOLS_BRIDGE_SOURCE,\n JOURNEY_DEVTOOLS_EXTENSION_SOURCE,\n isJourneyDevtoolsCommand,\n isJourneyDevtoolsEnvelope,\n isJourneyDevtoolsBridgeEnvelope,\n isJourneyDevtoolsExtensionEnvelope,\n type JourneyDevtoolsBridgeCommandErrorEnvelope,\n type JourneyDevtoolsBridgeCommandResultEnvelope,\n type JourneyDevtoolsBridgeExecutionPathsResultEnvelope,\n type JourneyDevtoolsBridgeEnvelope,\n type JourneyDevtoolsBridgeObservationEnvelope,\n type JourneyDevtoolsBridgeRegisterEnvelope,\n type JourneyDevtoolsBridgeSnapshotEnvelope,\n type JourneyDevtoolsBridgeUnregisterEnvelope,\n type JourneyDevtoolsCommand,\n type JourneyDevtoolsEnvelope,\n type JourneyDevtoolsExtensionEnvelope,\n type JourneyDevtoolsExtensionCommandEnvelope,\n type JourneyDevtoolsMachineCapabilities,\n type JourneyDevtoolsMachineMeta,\n type JourneyDevtoolsProtocolVersion,\n type JourneyDevtoolsSerializableExecutionPathsResult,\n type JourneyDevtoolsSerializableObservationEvent,\n type JourneyDevtoolsSerializableSnapshot,\n type JourneyDevtoolsSerializedError\n} from \"./protocol\";\n", "import type {\n JourneyExecutionPathOptions,\n JourneyExecutionPathsResult,\n JourneyJsonObject,\n JourneyObservationEvent,\n JourneySnapshot,\n JourneyStepAsyncState\n} from \"@rxova/journey-core\";\n\nexport const JOURNEY_DEVTOOLS_PROTOCOL_VERSION = 4 as const;\nexport const JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION = 3 as const;\nexport const JOURNEY_DEVTOOLS_CHANNEL = \"__RXOVA_JOURNEY_DEVTOOLS__\" as const;\n\nexport const JOURNEY_DEVTOOLS_BRIDGE_SOURCE = \"rxova-journey-bridge\" as const;\nexport const JOURNEY_DEVTOOLS_EXTENSION_SOURCE = \"rxova-journey-extension\" as const;\n\nexport type JourneyDevtoolsProtocolVersion =\n | typeof JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION\n | typeof JOURNEY_DEVTOOLS_PROTOCOL_VERSION;\n\nexport type JourneyDevtoolsSource =\n | typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE\n | typeof JOURNEY_DEVTOOLS_EXTENSION_SOURCE;\n\nexport type JourneyDevtoolsStepAsyncState = JourneyStepAsyncState;\n\nexport type JourneyDevtoolsSerializableSnapshot = JourneySnapshot<JourneyJsonObject, string>;\nexport type JourneyDevtoolsSerializableObservationEvent = JourneyObservationEvent<\n string,\n Record<never, never>\n>;\nexport type JourneyDevtoolsSerializableExecutionPathsResult = JourneyExecutionPathsResult<\n string,\n string\n>;\n\nexport type JourneyDevtoolsMachineCapabilities = {\n commands: JourneyDevtoolsCommand[\"type\"][];\n observe: boolean;\n executionPaths: boolean;\n persistence?: {\n key: string | null;\n clearOnReset: boolean | null;\n };\n};\n\nexport type JourneyDevtoolsMachineMeta = {\n machineId: string;\n label: string;\n appName: string | null;\n commandsEnabled?: boolean;\n capabilities?: JourneyDevtoolsMachineCapabilities;\n};\n\nexport type JourneyDevtoolsSerializedError = {\n name: string | null;\n message: string;\n stack: string | null;\n cause: unknown;\n};\n\nexport type JourneyDevtoolsCommand =\n | { type: \"startJourney\" }\n | { type: \"goToNextStep\" }\n | { type: \"terminateJourney\" }\n | { type: \"completeJourney\" }\n | { type: \"goToStepById\"; stepId: string }\n | { type: \"goToPreviousStep\"; steps?: number }\n | { type: \"goToLastVisitedStep\" }\n | { type: \"send\"; event: { type: string; payload?: unknown } }\n | { type: \"resetJourney\" }\n | { type: \"clearStepError\"; stepId?: string }\n | { type: \"getExecutionPaths\"; options?: JourneyExecutionPathOptions };\n\nexport type JourneyDevtoolsEnvelopeBase = {\n channel: typeof JOURNEY_DEVTOOLS_CHANNEL;\n version: JourneyDevtoolsProtocolVersion;\n source: JourneyDevtoolsSource;\n kind: string;\n machineId: string;\n timestamp: number;\n};\n\nexport type JourneyDevtoolsBridgeRegisterEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"register\";\n meta: JourneyDevtoolsMachineMeta;\n snapshot: JourneyDevtoolsSerializableSnapshot;\n};\n\nexport type JourneyDevtoolsBridgeUnregisterEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"unregister\";\n};\n\nexport type JourneyDevtoolsBridgeSnapshotEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"snapshot\";\n snapshot: JourneyDevtoolsSerializableSnapshot;\n};\n\nexport type JourneyDevtoolsBridgeObservationEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"observation\";\n event: JourneyDevtoolsSerializableObservationEvent;\n};\n\nexport type JourneyDevtoolsBridgeCommandResultEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"commandResult\";\n requestId: string;\n snapshot: JourneyDevtoolsSerializableSnapshot;\n transitioned?: boolean;\n transitionId?: string;\n error?: JourneyDevtoolsSerializedError;\n};\n\nexport type JourneyDevtoolsBridgeExecutionPathsResultEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"executionPathsResult\";\n requestId: string;\n result: JourneyDevtoolsSerializableExecutionPathsResult;\n};\n\nexport type JourneyDevtoolsBridgeCommandErrorEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"commandError\";\n requestId: string;\n error: JourneyDevtoolsSerializedError;\n};\n\nexport type JourneyDevtoolsExtensionCommandEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_EXTENSION_SOURCE;\n kind: \"command\";\n requestId: string;\n command: JourneyDevtoolsCommand;\n};\n\nexport type JourneyDevtoolsBridgeEnvelope =\n | JourneyDevtoolsBridgeRegisterEnvelope\n | JourneyDevtoolsBridgeUnregisterEnvelope\n | JourneyDevtoolsBridgeSnapshotEnvelope\n | JourneyDevtoolsBridgeObservationEnvelope\n | JourneyDevtoolsBridgeCommandResultEnvelope\n | JourneyDevtoolsBridgeExecutionPathsResultEnvelope\n | JourneyDevtoolsBridgeCommandErrorEnvelope;\n\nexport type JourneyDevtoolsExtensionEnvelope = JourneyDevtoolsExtensionCommandEnvelope;\n\nexport type JourneyDevtoolsEnvelope =\n | JourneyDevtoolsBridgeEnvelope\n | JourneyDevtoolsExtensionEnvelope;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nconst isKnownSource = (value: unknown): value is JourneyDevtoolsSource =>\n value === JOURNEY_DEVTOOLS_BRIDGE_SOURCE || value === JOURNEY_DEVTOOLS_EXTENSION_SOURCE;\n\nconst isSupportedProtocolVersion = (value: unknown): value is JourneyDevtoolsProtocolVersion =>\n value === JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION || value === JOURNEY_DEVTOOLS_PROTOCOL_VERSION;\n\nconst JOURNEY_COMMAND_TYPES = [\n \"startJourney\",\n \"goToNextStep\",\n \"terminateJourney\",\n \"completeJourney\",\n \"goToStepById\",\n \"goToPreviousStep\",\n \"goToLastVisitedStep\",\n \"send\",\n \"resetJourney\",\n \"clearStepError\",\n \"getExecutionPaths\"\n] as const;\n\nconst isKnownCommandType = (value: unknown): value is JourneyDevtoolsCommand[\"type\"] =>\n typeof value === \"string\" && (JOURNEY_COMMAND_TYPES as readonly string[]).includes(value);\n\n/**\n * Maximum depth for nested object validation.\n * Prevents stack overflow and excessive processing from deeply nested malicious payloads.\n */\nconst MAX_PAYLOAD_DEPTH = 10;\n\n/**\n * Maximum size (in JSON string length) for serialized payloads.\n * Prevents memory exhaustion from extremely large payloads.\n */\nconst MAX_PAYLOAD_SIZE = 500_000; // 500KB\n\n/**\n * Validates that a value is safe for transport.\n * Checks size via a single serialization pass, then validates\n * depth, types, and prototype safety via a structure walk.\n */\nconst isSafePayload = (value: unknown): boolean => {\n try {\n const serialized = JSON.stringify(value);\n if (serialized !== undefined && serialized.length > MAX_PAYLOAD_SIZE) {\n return false;\n }\n } catch {\n return false;\n }\n\n return isStructureSafe(value, 0);\n};\n\nconst isStructureSafe = (value: unknown, depth: number): boolean => {\n if (depth > MAX_PAYLOAD_DEPTH) {\n return false;\n }\n\n if (value === null || value === undefined) {\n return true;\n }\n\n if (typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\") {\n return true;\n }\n\n if (typeof value !== \"object\") {\n return false;\n }\n\n if (Array.isArray(value)) {\n return value.every((item) => isStructureSafe(item, depth + 1));\n }\n\n if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {\n return false;\n }\n\n return Object.values(value).every((prop) => isStructureSafe(prop, depth + 1));\n};\n\nconst hasBaseEnvelopeShape = (value: unknown): value is JourneyDevtoolsEnvelopeBase => {\n if (!isRecord(value)) {\n return false;\n }\n\n return (\n value.channel === JOURNEY_DEVTOOLS_CHANNEL &&\n isSupportedProtocolVersion(value.version) &&\n isKnownSource(value.source) &&\n typeof value.kind === \"string\" &&\n typeof value.machineId === \"string\" &&\n typeof value.timestamp === \"number\"\n );\n};\n\nconst isPositiveInteger = (value: unknown, max = 10000): value is number =>\n typeof value === \"number\" && Number.isInteger(value) && value >= 1 && value <= max;\n\nconst isExecutionPathOptionsShape = (value: unknown): value is JourneyExecutionPathOptions => {\n if (!isRecord(value)) {\n return false;\n }\n\n return (\n Object.keys(value).length <= 2 &&\n (value.maxDepth === undefined || isPositiveInteger(value.maxDepth)) &&\n (value.maxPaths === undefined || isPositiveInteger(value.maxPaths))\n );\n};\n\nconst isSendEvent = (value: unknown): value is { type: string; payload?: unknown } => {\n if (!isRecord(value)) {\n return false;\n }\n\n if (typeof value.type !== \"string\" || value.type.length === 0 || value.type.length > 100) {\n return false;\n }\n\n if (\"payload\" in value && value.payload !== undefined) {\n return isSafePayload(value.payload);\n }\n\n return true;\n};\n\nconst isMachineCapabilities = (value: unknown): value is JourneyDevtoolsMachineCapabilities => {\n if (\n !isRecord(value) ||\n typeof value.observe !== \"boolean\" ||\n typeof value.executionPaths !== \"boolean\"\n ) {\n return false;\n }\n\n if (\n !Array.isArray(value.commands) ||\n !value.commands.every((command) => isKnownCommandType(command))\n ) {\n return false;\n }\n\n if (value.persistence === undefined) {\n return true;\n }\n\n if (!isRecord(value.persistence)) {\n return false;\n }\n\n return (\n (value.persistence.key === null || typeof value.persistence.key === \"string\") &&\n (value.persistence.clearOnReset === null || typeof value.persistence.clearOnReset === \"boolean\")\n );\n};\n\nconst isMachineMeta = (\n value: unknown,\n version: JourneyDevtoolsProtocolVersion\n): value is JourneyDevtoolsMachineMeta => {\n if (!isRecord(value)) {\n return false;\n }\n\n return (\n typeof value.machineId === \"string\" &&\n typeof value.label === \"string\" &&\n (value.appName === null || typeof value.appName === \"string\") &&\n (value.commandsEnabled === undefined || typeof value.commandsEnabled === \"boolean\") &&\n (version === JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION\n ? value.capabilities === undefined || isMachineCapabilities(value.capabilities)\n : isMachineCapabilities(value.capabilities))\n );\n};\n\nconst isSerializableObservationEvent = (\n value: unknown\n): value is JourneyDevtoolsSerializableObservationEvent => {\n if (!isRecord(value)) {\n return false;\n }\n\n return (\n typeof value.type === \"string\" &&\n value.type.length > 0 &&\n value.type.length <= 100 &&\n typeof value.timestamp === \"number\" &&\n isSafePayload(value)\n );\n};\n\nconst isExecutionPathResult = (\n value: unknown\n): value is JourneyDevtoolsSerializableExecutionPathsResult => {\n if (!isRecord(value) || !Array.isArray(value.paths)) {\n return false;\n }\n\n const isPathTerminated = (terminated: unknown): terminated is string =>\n terminated === \"final\" ||\n terminated === \"depth\" ||\n terminated === \"cycle\" ||\n terminated === \"limit\";\n\n return (\n value.paths.every(\n (path) =>\n isRecord(path) &&\n Array.isArray(path.steps) &&\n path.steps.every((step) => typeof step === \"string\") &&\n Array.isArray(path.events) &&\n path.events.every((event) => typeof event === \"string\") &&\n isPathTerminated(path.terminated)\n ) &&\n typeof value.truncated === \"boolean\" &&\n typeof value.cyclesDetected === \"boolean\"\n );\n};\n\n/**\n * Validates whether an unknown value is a supported devtools command payload.\n */\nexport const isJourneyDevtoolsCommand = (value: unknown): value is JourneyDevtoolsCommand => {\n if (!isRecord(value) || typeof value.type !== \"string\") {\n return false;\n }\n\n if (value.type.length === 0 || value.type.length > 50) {\n return false;\n }\n\n switch (value.type) {\n case \"startJourney\":\n case \"goToNextStep\":\n case \"terminateJourney\":\n case \"completeJourney\":\n case \"resetJourney\":\n case \"goToLastVisitedStep\":\n return Object.keys(value).length === 1;\n case \"goToStepById\":\n return (\n typeof value.stepId === \"string\" &&\n value.stepId.length > 0 &&\n value.stepId.length <= 100 &&\n Object.keys(value).length === 2\n );\n case \"goToPreviousStep\":\n return (\n (value.steps === undefined || isPositiveInteger(value.steps)) &&\n Object.keys(value).length <= 2\n );\n case \"send\":\n return isSendEvent(value.event) && Object.keys(value).length === 2;\n case \"clearStepError\":\n return (\n (value.stepId === undefined ||\n (typeof value.stepId === \"string\" && value.stepId.length <= 100)) &&\n Object.keys(value).length <= 2\n );\n case \"getExecutionPaths\":\n return (\n (value.options === undefined || isExecutionPathOptionsShape(value.options)) &&\n Object.keys(value).length <= 2\n );\n default:\n return false;\n }\n};\n\n/**\n * Validates whether an unknown value is a bridge-origin envelope.\n */\nexport const isJourneyDevtoolsBridgeEnvelope = (\n value: unknown\n): value is JourneyDevtoolsBridgeEnvelope => {\n if (!hasBaseEnvelopeShape(value) || value.source !== JOURNEY_DEVTOOLS_BRIDGE_SOURCE) {\n return false;\n }\n\n const envelope = value as Record<string, unknown>;\n\n switch (value.kind) {\n case \"register\":\n return (\n isMachineMeta(envelope.meta, value.version) &&\n isRecord(envelope.snapshot) &&\n isSafePayload(envelope.snapshot)\n );\n case \"unregister\":\n return true;\n case \"snapshot\":\n return isRecord(envelope.snapshot) && isSafePayload(envelope.snapshot);\n case \"observation\":\n return isSerializableObservationEvent(envelope.event);\n case \"commandResult\":\n return (\n typeof envelope.requestId === \"string\" &&\n envelope.requestId.length > 0 &&\n envelope.requestId.length <= 100 &&\n isRecord(envelope.snapshot) &&\n isSafePayload(envelope.snapshot) &&\n (!(\"error\" in envelope) || isRecord(envelope.error))\n );\n case \"executionPathsResult\":\n return (\n typeof envelope.requestId === \"string\" &&\n envelope.requestId.length > 0 &&\n envelope.requestId.length <= 100 &&\n isExecutionPathResult(envelope.result)\n );\n case \"commandError\":\n return (\n typeof envelope.requestId === \"string\" &&\n envelope.requestId.length > 0 &&\n envelope.requestId.length <= 100 &&\n isRecord(envelope.error)\n );\n default:\n return false;\n }\n};\n\n/**\n * Validates whether an unknown value is an extension-origin command envelope.\n */\nexport const isJourneyDevtoolsExtensionEnvelope = (\n value: unknown\n): value is JourneyDevtoolsExtensionEnvelope => {\n if (!hasBaseEnvelopeShape(value) || value.source !== JOURNEY_DEVTOOLS_EXTENSION_SOURCE) {\n return false;\n }\n\n if (value.kind !== \"command\") {\n return false;\n }\n\n const envelope = value as Record<string, unknown>;\n return (\n typeof envelope.requestId === \"string\" &&\n envelope.requestId.length > 0 &&\n envelope.requestId.length <= 100 &&\n isJourneyDevtoolsCommand(envelope.command)\n );\n};\n\n/**\n * Validates whether an unknown value matches either supported devtools envelope shape.\n */\nexport const isJourneyDevtoolsEnvelope = (value: unknown): value is JourneyDevtoolsEnvelope =>\n isJourneyDevtoolsBridgeEnvelope(value) || isJourneyDevtoolsExtensionEnvelope(value);\n", "import type {\n JourneyExecutionPathOptions,\n JourneyExecutionPathsResult,\n JourneyJsonObject,\n JourneyMachine,\n JourneyObservationEvent,\n JourneySendResult,\n JourneySnapshot\n} from \"@rxova/journey-core\";\nimport {\n JOURNEY_DEVTOOLS_BRIDGE_SOURCE,\n JOURNEY_DEVTOOLS_CHANNEL,\n JOURNEY_DEVTOOLS_EXTENSION_SOURCE,\n JOURNEY_DEVTOOLS_PROTOCOL_VERSION,\n isJourneyDevtoolsEnvelope,\n type JourneyDevtoolsBridgeCommandErrorEnvelope,\n type JourneyDevtoolsBridgeCommandResultEnvelope,\n type JourneyDevtoolsBridgeEnvelope,\n type JourneyDevtoolsBridgeExecutionPathsResultEnvelope,\n type JourneyDevtoolsBridgeObservationEnvelope,\n type JourneyDevtoolsBridgeRegisterEnvelope,\n type JourneyDevtoolsBridgeSnapshotEnvelope,\n type JourneyDevtoolsBridgeUnregisterEnvelope,\n type JourneyDevtoolsCommand,\n type JourneyDevtoolsExtensionCommandEnvelope,\n type JourneyDevtoolsMachineMeta,\n type JourneyDevtoolsSerializableExecutionPathsResult,\n type JourneyDevtoolsSerializableObservationEvent,\n type JourneyDevtoolsSerializableSnapshot,\n type JourneyDevtoolsSerializedError\n} from \"./protocol\";\n\ndeclare const process: { env?: { NODE_ENV?: string } } | undefined;\n\ntype JourneyDevtoolsPersistencePluginMetadata = {\n key?: string;\n clearOnReset?: boolean;\n};\n\nexport type JourneyDevtoolsBridgeOptions = {\n machineId?: string;\n label?: string;\n enabled?: boolean;\n appName?: string;\n commandsEnabled?: boolean;\n pluginMetadata?: {\n persistence?: JourneyDevtoolsPersistencePluginMetadata;\n };\n};\n\ntype SnapshotCommandOutcome<TContext extends JourneyJsonObject, TStepId extends string> = {\n kind: \"snapshot\";\n snapshot: JourneySnapshot<TContext, TStepId>;\n transitioned?: boolean;\n transitionId?: string;\n error?: JourneyDevtoolsSerializedError;\n};\n\ntype ExecutionPathsCommandOutcome<TStepId extends string, TEventType extends string> = {\n kind: \"executionPaths\";\n result: JourneyExecutionPathsResult<TStepId, TEventType>;\n};\n\ntype CommandOutcome<\n TContext extends JourneyJsonObject,\n TStepId extends string,\n TEventType extends string\n> = SnapshotCommandOutcome<TContext, TStepId> | ExecutionPathsCommandOutcome<TStepId, TEventType>;\n\ntype SnapshotScheduleKind = \"raf\" | \"timeout\";\n\ntype JourneyImportMetaEnv = {\n DEV?: unknown;\n PROD?: unknown;\n};\n\ntype ExecutionPathsJourneyMachine<\n TContext extends JourneyJsonObject,\n TStepId extends string,\n TEventMap extends Record<string, unknown>,\n TStepMeta,\n THandlers extends Record<string, unknown>\n> = JourneyMachine<TContext, TStepId, TEventMap, TStepMeta, THandlers> & {\n getExecutionPaths: (\n options?: JourneyExecutionPathOptions\n ) => JourneyExecutionPathsResult<TStepId, string>;\n};\n\nconst DEFAULT_MACHINE_LABEL = \"Journey Machine\";\nconst MUTATING_COMMAND_TYPES = [\n \"startJourney\",\n \"goToNextStep\",\n \"terminateJourney\",\n \"completeJourney\",\n \"goToStepById\",\n \"goToPreviousStep\",\n \"goToLastVisitedStep\",\n \"send\",\n \"resetJourney\",\n \"clearStepError\"\n] as const satisfies readonly Exclude<JourneyDevtoolsCommand[\"type\"], \"getExecutionPaths\">[];\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nconst isJourneyAsyncPhase = (\n value: unknown\n): value is JourneyDevtoolsSerializableSnapshot[\"async\"][\"byStep\"][string][\"phase\"] =>\n value === \"idle\" || value === \"evaluating-when\" || value === \"error\";\n\nconst resolveImportMetaEnvironment = (\n bundlerEnv: JourneyImportMetaEnv | null | undefined\n): boolean | null => {\n if (!isRecord(bundlerEnv)) {\n return null;\n }\n\n if (bundlerEnv.PROD === true) {\n return false;\n }\n\n if (bundlerEnv.DEV === true) {\n return true;\n }\n\n return null;\n};\n\nconst resolveNodeEnvironment = (nodeEnv: string | undefined): boolean | null => {\n if (typeof nodeEnv !== \"string\") {\n return null;\n }\n\n return nodeEnv !== \"production\";\n};\n\nexport const resolveNonProductionEnvironment = (\n options: {\n bundlerEnv?: JourneyImportMetaEnv | null | undefined;\n nodeEnv?: string | undefined;\n } = {}\n): boolean => {\n const resolvedBundlerEnv =\n \"bundlerEnv\" in options\n ? options.bundlerEnv\n : (import.meta as ImportMeta & { env?: JourneyImportMetaEnv }).env;\n const resolvedNodeEnv =\n \"nodeEnv\" in options\n ? options.nodeEnv\n : typeof process !== \"undefined\"\n ? process.env?.NODE_ENV\n : undefined;\n\n return (\n resolveImportMetaEnvironment(resolvedBundlerEnv) ??\n resolveNodeEnvironment(resolvedNodeEnv) ??\n false\n );\n};\n\nconst resolveWindowTargetOrigin = (): string => {\n if (typeof window === \"undefined\") {\n return \"*\";\n }\n\n return window.location.origin === \"null\" ? \"*\" : window.location.origin;\n};\n\nconst isExpectedWindowOrigin = (origin: string): boolean => {\n if (origin.length === 0) {\n return false;\n }\n\n if (typeof window === \"undefined\") {\n return false;\n }\n\n const expected = window.location.origin;\n if (expected === \"null\") {\n return origin === \"null\";\n }\n\n return origin === expected;\n};\n\nconst createJourneyMachineId = (): string =>\n `journey-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;\n\nclass CommandRateLimiter {\n private commandTimestamps: number[] = [];\n private readonly maxCommandsPerWindow: number;\n private readonly windowMs: number;\n\n constructor(maxCommandsPerWindow = 100, windowMs = 10000) {\n this.maxCommandsPerWindow = maxCommandsPerWindow;\n this.windowMs = windowMs;\n }\n\n isAllowed(): boolean {\n const now = Date.now();\n const windowStart = now - this.windowMs;\n\n this.commandTimestamps = this.commandTimestamps.filter((timestamp) => timestamp > windowStart);\n\n if (this.commandTimestamps.length >= this.maxCommandsPerWindow) {\n return false;\n }\n\n this.commandTimestamps.push(now);\n return true;\n }\n\n reset(): void {\n this.commandTimestamps = [];\n }\n}\n\nconst cloneForTransport = (value: unknown): unknown => {\n const transportValue =\n typeof structuredClone === \"function\"\n ? (() => {\n try {\n return structuredClone(value);\n } catch {\n return value;\n }\n })()\n : value;\n const seen = new WeakSet<object>();\n\n try {\n const serialized = JSON.stringify(transportValue, (_key, currentValue) => {\n if (typeof currentValue === \"bigint\") {\n return currentValue.toString();\n }\n if (typeof currentValue === \"function\") {\n return `[Function ${currentValue.name || \"anonymous\"}]`;\n }\n if (typeof currentValue === \"symbol\") {\n return currentValue.toString();\n }\n if (typeof currentValue === \"object\" && currentValue !== null) {\n if (seen.has(currentValue)) {\n return \"[Circular]\";\n }\n seen.add(currentValue);\n }\n return currentValue;\n });\n\n if (serialized === undefined) {\n return undefined;\n }\n\n return JSON.parse(serialized) as unknown;\n } catch {\n return String(value);\n }\n};\n\nconst serializeError = (error: unknown): JourneyDevtoolsSerializedError => {\n if (error instanceof Error) {\n const cause =\n \"cause\" in error && (error as { cause?: unknown }).cause !== undefined\n ? (error as { cause?: unknown }).cause\n : null;\n return {\n name: error.name,\n message: error.message,\n stack: typeof error.stack === \"string\" ? error.stack : null,\n cause: cloneForTransport(cause)\n };\n }\n\n return {\n name: null,\n message: typeof error === \"string\" ? error : \"Unknown error\",\n stack: null,\n cause: cloneForTransport(error)\n };\n};\n\nconst serializeSnapshot = <TContext extends JourneyJsonObject, TStepId extends string>(\n snapshot: JourneySnapshot<TContext, TStepId>\n): JourneyDevtoolsSerializableSnapshot => {\n const byStep: Record<string, JourneyDevtoolsSerializableSnapshot[\"async\"][\"byStep\"][string]> = {};\n\n for (const [stepId, stepState] of Object.entries(\n snapshot.async.byStep as Record<string, unknown>\n )) {\n if (!isRecord(stepState)) {\n continue;\n }\n\n byStep[stepId] = {\n phase: isJourneyAsyncPhase(stepState.phase) ? stepState.phase : \"idle\",\n eventType: typeof stepState.eventType === \"string\" ? stepState.eventType : null,\n transitionId: typeof stepState.transitionId === \"string\" ? stepState.transitionId : null,\n error: stepState.error === null ? null : cloneForTransport(stepState.error)\n };\n }\n\n return {\n currentStepId: String(snapshot.currentStepId),\n context: cloneForTransport(snapshot.context) as JourneyJsonObject,\n history: {\n timeline: snapshot.history.timeline.map((stepId) => String(stepId)),\n index: snapshot.history.index\n },\n visited: Object.fromEntries(\n Object.entries(snapshot.visited as Record<string, boolean>).map(([stepId, isVisited]) => [\n String(stepId),\n isVisited === true\n ])\n ),\n status: snapshot.status,\n async: {\n isLoading: snapshot.async.isLoading,\n byStep\n }\n };\n};\n\nconst serializeObservationEvent = <\n TStepId extends string,\n TEventMap extends Record<string, unknown>\n>(\n event: JourneyObservationEvent<TStepId, TEventMap>\n): JourneyDevtoolsSerializableObservationEvent => {\n if (event.type === \"transition.error\") {\n return cloneForTransport({\n ...event,\n error: serializeError(event.error)\n }) as JourneyDevtoolsSerializableObservationEvent;\n }\n return cloneForTransport(event) as JourneyDevtoolsSerializableObservationEvent;\n};\n\nconst serializeExecutionPathsResult = <TStepId extends string, TEventType extends string>(\n result: JourneyExecutionPathsResult<TStepId, TEventType>\n): JourneyDevtoolsSerializableExecutionPathsResult =>\n cloneForTransport(result) as JourneyDevtoolsSerializableExecutionPathsResult;\n\nconst isKnownStepId = <TContext extends JourneyJsonObject, TStepId extends string>(\n snapshot: JourneySnapshot<TContext, TStepId>,\n stepId: string\n): stepId is TStepId => stepId in (snapshot.async.byStep as Record<string, unknown>);\n\nconst assertKnownStepId = <TContext extends JourneyJsonObject, TStepId extends string>(\n machine: { getSnapshot: () => JourneySnapshot<TContext, TStepId> },\n stepId: string,\n commandType: JourneyDevtoolsCommand[\"type\"]\n): TStepId => {\n if (!isKnownStepId(machine.getSnapshot(), stepId)) {\n throw new Error(`Unknown stepId \"${stepId}\" for \"${commandType}\" command.`);\n }\n return stepId;\n};\n\nconst toSnapshotCommandOutcome = <TContext extends JourneyJsonObject, TStepId extends string>(\n result: JourneySendResult<TContext, TStepId>\n): SnapshotCommandOutcome<TContext, TStepId> => ({\n kind: \"snapshot\",\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {}),\n ...(\"error\" in result ? { error: serializeError(result.error) } : {})\n});\n\nconst hasExecutionPathsSupport = <\n TContext extends JourneyJsonObject,\n TStepId extends string,\n TEventMap extends Record<string, unknown>,\n TStepMeta,\n THandlers extends Record<string, unknown>\n>(\n machine: JourneyMachine<TContext, TStepId, TEventMap, TStepMeta, THandlers>\n): machine is ExecutionPathsJourneyMachine<TContext, TStepId, TEventMap, TStepMeta, THandlers> =>\n typeof (machine as Record<string, unknown>).getExecutionPaths === \"function\";\n\nconst isReadOnlyCommand = (command: JourneyDevtoolsCommand): boolean =>\n command.type === \"getExecutionPaths\";\n\nconst createCapabilities = <\n TContext extends JourneyJsonObject,\n TStepId extends string,\n TEventMap extends Record<string, unknown>,\n TStepMeta,\n THandlers extends Record<string, unknown>\n>(\n machine: JourneyMachine<TContext, TStepId, TEventMap, TStepMeta, THandlers>,\n options: JourneyDevtoolsBridgeOptions,\n commandsEnabled: boolean\n) => {\n const executionPaths = hasExecutionPathsSupport(machine);\n const commands: JourneyDevtoolsCommand[\"type\"][] = [];\n\n if (commandsEnabled) {\n commands.push(...MUTATING_COMMAND_TYPES);\n }\n\n if (executionPaths) {\n commands.push(\"getExecutionPaths\");\n }\n\n return {\n commands,\n observe: true as const,\n executionPaths,\n ...(options.pluginMetadata?.persistence\n ? {\n persistence: {\n key: options.pluginMetadata.persistence.key?.trim() || null,\n clearOnReset:\n typeof options.pluginMetadata.persistence.clearOnReset === \"boolean\"\n ? options.pluginMetadata.persistence.clearOnReset\n : null\n }\n }\n : {})\n };\n};\n\nconst runCommand = async <\n TContext extends JourneyJsonObject,\n TStepId extends string,\n TStepMeta,\n THandlers extends Record<string, unknown>\n>(\n machine: JourneyMachine<TContext, TStepId, Record<never, never>, TStepMeta, THandlers>,\n command: JourneyDevtoolsCommand\n): Promise<CommandOutcome<TContext, TStepId, string>> => {\n switch (command.type) {\n case \"startJourney\":\n return {\n kind: \"snapshot\",\n snapshot: await machine.startJourney()\n };\n case \"goToNextStep\":\n case \"completeJourney\": {\n const result = await machine.send({ type: command.type });\n return toSnapshotCommandOutcome(result);\n }\n case \"terminateJourney\": {\n const result = await machine.send({ type: \"terminateJourney\" });\n return toSnapshotCommandOutcome(result);\n }\n case \"goToStepById\": {\n const stepId = assertKnownStepId(machine, command.stepId, command.type);\n const result = await machine.send({\n type: \"goToStepById\",\n stepId\n });\n return toSnapshotCommandOutcome(result);\n }\n case \"goToPreviousStep\": {\n const result = await machine.goToPreviousStep(command.steps);\n return toSnapshotCommandOutcome(result);\n }\n case \"goToLastVisitedStep\": {\n const result = await machine.goToLastVisitedStep();\n return toSnapshotCommandOutcome(result);\n }\n case \"send\": {\n const sendEvent =\n command.event.payload === undefined\n ? { type: command.event.type }\n : { type: command.event.type, payload: command.event.payload };\n const result: JourneySendResult<TContext, TStepId> = await machine.send(\n sendEvent as Parameters<typeof machine.send>[0]\n );\n return toSnapshotCommandOutcome(result);\n }\n case \"resetJourney\":\n return {\n kind: \"snapshot\",\n snapshot: await machine.resetJourney()\n };\n case \"clearStepError\": {\n const stepId =\n command.stepId === undefined\n ? undefined\n : assertKnownStepId(machine, command.stepId, command.type);\n return {\n kind: \"snapshot\",\n snapshot: await machine.clearStepError(stepId)\n };\n }\n case \"getExecutionPaths\": {\n if (!hasExecutionPathsSupport(machine)) {\n throw new Error('Machine does not support \"getExecutionPaths\".');\n }\n\n return {\n kind: \"executionPaths\",\n result: machine.getExecutionPaths(command.options)\n };\n }\n }\n};\n\n/**\n * Attaches a journey machine to the browser devtools transport and returns\n * a detach function that unsubscribes listeners and unregisters the machine.\n */\nexport const attachJourneyDevtools = <\n TContext extends JourneyJsonObject,\n TStepId extends string,\n TEventMap extends Record<string, unknown> = Record<never, never>,\n TStepMeta = unknown,\n THandlers extends Record<string, unknown> = Record<never, never>\n>(\n machine: JourneyMachine<TContext, TStepId, TEventMap, TStepMeta, THandlers>,\n options: JourneyDevtoolsBridgeOptions = {}\n): (() => void) => {\n const enabled = options.enabled ?? resolveNonProductionEnvironment();\n if (!enabled || typeof window === \"undefined\") {\n return () => {};\n }\n\n const commandsEnabled = options.commandsEnabled ?? resolveNonProductionEnvironment();\n const machineId = options.machineId?.trim() || createJourneyMachineId();\n const targetOrigin = resolveWindowTargetOrigin();\n const capabilities = createCapabilities(machine, options, commandsEnabled);\n\n const meta: JourneyDevtoolsMachineMeta = {\n machineId,\n label: options.label?.trim() || DEFAULT_MACHINE_LABEL,\n appName:\n options.appName?.trim() || (typeof document !== \"undefined\" ? document.title : \"\") || null,\n commandsEnabled,\n capabilities\n };\n\n const createBaseEnvelope = <TKind extends JourneyDevtoolsBridgeEnvelope[\"kind\"]>(\n kind: TKind\n ) => ({\n channel: JOURNEY_DEVTOOLS_CHANNEL,\n version: JOURNEY_DEVTOOLS_PROTOCOL_VERSION,\n source: JOURNEY_DEVTOOLS_BRIDGE_SOURCE,\n kind,\n machineId,\n timestamp: Date.now()\n });\n\n const post = (envelope: JourneyDevtoolsBridgeEnvelope) => {\n try {\n window.postMessage(envelope, targetOrigin);\n } catch {\n // Swallow transport failures so bridge lifecycle and commands remain non-throwing.\n }\n };\n\n const postSnapshot = (snapshot: JourneySnapshot<TContext, TStepId>) => {\n const envelope: JourneyDevtoolsBridgeSnapshotEnvelope = {\n ...createBaseEnvelope(\"snapshot\"),\n snapshot: serializeSnapshot(snapshot)\n };\n post(envelope);\n };\n\n const postObservation = (event: JourneyObservationEvent<TStepId, TEventMap>) => {\n const envelope: JourneyDevtoolsBridgeObservationEnvelope = {\n ...createBaseEnvelope(\"observation\"),\n event: serializeObservationEvent(event)\n };\n post(envelope);\n };\n\n const postExecutionPathsResult = (\n requestId: string,\n result: JourneyExecutionPathsResult<TStepId, string>\n ) => {\n const envelope: JourneyDevtoolsBridgeExecutionPathsResultEnvelope = {\n ...createBaseEnvelope(\"executionPathsResult\"),\n requestId,\n result: serializeExecutionPathsResult(result)\n };\n post(envelope);\n };\n\n let isDetached = false;\n const rateLimiter = new CommandRateLimiter();\n let pendingSnapshot: JourneySnapshot<TContext, TStepId> | null = null;\n let scheduledSnapshotHandle: number | ReturnType<typeof globalThis.setTimeout> | null = null;\n let scheduledSnapshotKind: SnapshotScheduleKind | null = null;\n\n const clearScheduledSnapshotState = () => {\n pendingSnapshot = null;\n scheduledSnapshotHandle = null;\n scheduledSnapshotKind = null;\n };\n\n const flushScheduledSnapshot = () => {\n const snapshot = pendingSnapshot;\n clearScheduledSnapshotState();\n\n if (!snapshot || isDetached) {\n return;\n }\n\n postSnapshot(snapshot);\n };\n\n const scheduleSnapshotPost = (snapshot: JourneySnapshot<TContext, TStepId>) => {\n pendingSnapshot = snapshot;\n if (scheduledSnapshotHandle !== null) {\n return;\n }\n\n if (typeof window.requestAnimationFrame === \"function\") {\n scheduledSnapshotKind = \"raf\";\n scheduledSnapshotHandle = window.requestAnimationFrame(() => {\n flushScheduledSnapshot();\n });\n return;\n }\n\n scheduledSnapshotKind = \"timeout\";\n scheduledSnapshotHandle = globalThis.setTimeout(() => {\n flushScheduledSnapshot();\n }, 0);\n };\n\n const cancelScheduledSnapshot = () => {\n if (scheduledSnapshotHandle === null) {\n clearScheduledSnapshotState();\n return;\n }\n\n if (scheduledSnapshotKind === \"raf\" && typeof window.cancelAnimationFrame === \"function\") {\n window.cancelAnimationFrame(scheduledSnapshotHandle as number);\n } else {\n globalThis.clearTimeout(scheduledSnapshotHandle);\n }\n\n clearScheduledSnapshotState();\n };\n\n const onMessage = (event: MessageEvent<unknown>) => {\n if (\n event.source !== window ||\n !isExpectedWindowOrigin(event.origin) ||\n isDetached ||\n !isJourneyDevtoolsEnvelope(event.data)\n ) {\n return;\n }\n\n if (event.data.source !== JOURNEY_DEVTOOLS_EXTENSION_SOURCE || event.data.kind !== \"command\") {\n return;\n }\n\n const commandEnvelope: JourneyDevtoolsExtensionCommandEnvelope = event.data;\n if (commandEnvelope.machineId !== machineId) {\n return;\n }\n\n if (!rateLimiter.isAllowed()) {\n const errorEnvelope: JourneyDevtoolsBridgeCommandErrorEnvelope = {\n ...createBaseEnvelope(\"commandError\"),\n requestId: commandEnvelope.requestId,\n error: serializeError(\n \"Command rate limit exceeded. Too many commands in a short time window.\"\n )\n };\n post(errorEnvelope);\n return;\n }\n\n if (!commandsEnabled && !isReadOnlyCommand(commandEnvelope.command)) {\n const errorEnvelope: JourneyDevtoolsBridgeCommandErrorEnvelope = {\n ...createBaseEnvelope(\"commandError\"),\n requestId: commandEnvelope.requestId,\n error: serializeError(\"Bridge commands are disabled by configuration.\")\n };\n post(errorEnvelope);\n return;\n }\n\n const run = async () => {\n try {\n const outcome = await runCommand(\n machine as unknown as JourneyMachine<\n TContext,\n TStepId,\n Record<never, never>,\n TStepMeta,\n THandlers\n >,\n commandEnvelope.command\n );\n\n if (isDetached) {\n return;\n }\n\n if (outcome.kind === \"executionPaths\") {\n postExecutionPathsResult(commandEnvelope.requestId, outcome.result);\n return;\n }\n\n const resultEnvelope: JourneyDevtoolsBridgeCommandResultEnvelope = {\n ...createBaseEnvelope(\"commandResult\"),\n requestId: commandEnvelope.requestId,\n snapshot: serializeSnapshot(outcome.snapshot),\n ...(outcome.transitioned !== undefined ? { transitioned: outcome.transitioned } : {}),\n ...(outcome.transitionId ? { transitionId: outcome.transitionId } : {}),\n ...(\"error\" in outcome ? { error: outcome.error } : {})\n };\n post(resultEnvelope);\n } catch (error) {\n if (isDetached) {\n return;\n }\n\n const errorEnvelope: JourneyDevtoolsBridgeCommandErrorEnvelope = {\n ...createBaseEnvelope(\"commandError\"),\n requestId: commandEnvelope.requestId,\n error: serializeError(error)\n };\n post(errorEnvelope);\n }\n };\n\n void run();\n };\n\n window.addEventListener(\"message\", onMessage);\n\n const unsubscribeSnapshot = machine.subscribe(() => {\n if (isDetached) {\n return;\n }\n\n scheduleSnapshotPost(machine.getSnapshot());\n });\n\n const registerEnvelope: JourneyDevtoolsBridgeRegisterEnvelope = {\n ...createBaseEnvelope(\"register\"),\n meta,\n snapshot: serializeSnapshot(machine.getSnapshot())\n };\n post(registerEnvelope);\n\n const unsubscribeObservation = machine.subscribeEvent((event) => {\n if (isDetached) {\n return;\n }\n\n postObservation(event);\n });\n\n return () => {\n if (isDetached) {\n return;\n }\n\n isDetached = true;\n rateLimiter.reset();\n unsubscribeObservation();\n unsubscribeSnapshot();\n window.removeEventListener(\"message\", onMessage);\n cancelScheduledSnapshot();\n\n const unregisterEnvelope: JourneyDevtoolsBridgeUnregisterEnvelope = {\n ...createBaseEnvelope(\"unregister\")\n };\n post(unregisterEnvelope);\n };\n};\n"],
5
+ "mappings": "mbAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,oCAAAE,EAAA,6BAAAC,EAAA,sCAAAC,EAAA,6CAAAC,EAAA,sCAAAC,EAAA,0BAAAC,EAAA,oCAAAC,EAAA,6BAAAC,EAAA,8BAAAC,EAAA,uCAAAC,IAAA,eAAAC,GAAAZ,ICSO,IAAMa,EAAoC,EACpCC,EAA2C,EAC3CC,EAA2B,6BAE3BC,EAAiC,uBACjCC,EAAoC,0BA2I3CC,EAAYC,GAChB,OAAOA,GAAU,UAAYA,IAAU,KAEnCC,GAAiBD,GACrBA,IAAUH,GAAkCG,IAAUF,EAElDI,GAA8BF,GAClCA,IAAU,GAA4CA,IAAU,EAE5DG,GAAwB,CAC5B,eACA,eACA,mBACA,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2D,CAC/D,GAAGvB,EAAmB,cAAc,EACpC,UAAWsB,EAAgB,UAC3B,MAAOtD,EAAeC,CAAK,CAC7B,EACAmC,EAAKmB,CAAa,CACpB,CACF,GAES,CACX,EAEA,OAAO,iBAAiB,UAAWJ,CAAS,EAE5C,IAAMO,GAAsB3C,EAAQ,UAAU,IAAM,CAC9C2B,GAIJO,EAAqBlC,EAAQ,YAAY,CAAC,CAC5C,CAAC,EAEK4C,GAA0D,CAC9D,GAAG3B,EAAmB,UAAU,EAChC,KAAAD,EACA,SAAU5B,EAAkBY,EAAQ,YAAY,CAAC,CACnD,EACAqB,EAAKuB,EAAgB,EAErB,IAAMC,GAAyB7C,EAAQ,eAAgBL,GAAU,CAC3DgC,GAIJH,EAAgB7B,CAAK,CACvB,CAAC,EAED,MAAO,IAAM,CACX,GAAIgC,EACF,OAGFA,EAAa,GACbC,EAAY,MAAM,EAClBiB,GAAuB,EACvBF,GAAoB,EACpB,OAAO,oBAAoB,UAAWP,CAAS,EAC/CD,EAAwB,EAExB,IAAMW,EAA8D,CAClE,GAAG7B,EAAmB,YAAY,CACpC,EACAI,EAAKyB,CAAkB,CACzB,CACF",
6
+ "names": ["index_exports", "__export", "JOURNEY_DEVTOOLS_BRIDGE_SOURCE", "JOURNEY_DEVTOOLS_CHANNEL", "JOURNEY_DEVTOOLS_EXTENSION_SOURCE", "JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION", "JOURNEY_DEVTOOLS_PROTOCOL_VERSION", "attachJourneyDevtools", "isJourneyDevtoolsBridgeEnvelope", "isJourneyDevtoolsCommand", "isJourneyDevtoolsEnvelope", "isJourneyDevtoolsExtensionEnvelope", "__toCommonJS", "JOURNEY_DEVTOOLS_PROTOCOL_VERSION", "JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION", "JOURNEY_DEVTOOLS_CHANNEL", "JOURNEY_DEVTOOLS_BRIDGE_SOURCE", "JOURNEY_DEVTOOLS_EXTENSION_SOURCE", "isRecord", "value", "isKnownSource", "isSupportedProtocolVersion", "JOURNEY_COMMAND_TYPES", "isKnownCommandType", "isSafePayload", "value", "serialized", "isStructureSafe", "depth", "item", "prop", "hasBaseEnvelopeShape", "isRecord", "JOURNEY_DEVTOOLS_CHANNEL", "isSupportedProtocolVersion", "isKnownSource", "isPositiveInteger", "max", "isExecutionPathOptionsShape", "isSendEvent", "isMachineCapabilities", "command", "isKnownCommandType", "isMachineMeta", "version", "isSerializableObservationEvent", "isExecutionPathResult", "isPathTerminated", "terminated", "path", "step", "event", "isJourneyDevtoolsCommand", "isJourneyDevtoolsBridgeEnvelope", "JOURNEY_DEVTOOLS_BRIDGE_SOURCE", "envelope", "isJourneyDevtoolsExtensionEnvelope", "JOURNEY_DEVTOOLS_EXTENSION_SOURCE", "isJourneyDevtoolsEnvelope", "import_meta", "DEFAULT_MACHINE_LABEL", "MUTATING_COMMAND_TYPES", "isRecord", "value", "isJourneyAsyncPhase", "resolveImportMetaEnvironment", "bundlerEnv", "resolveNodeEnvironment", "nodeEnv", "resolveNonProductionEnvironment", "options", "resolvedBundlerEnv", "resolvedNodeEnv", "resolveWindowTargetOrigin", "isExpectedWindowOrigin", "origin", "expected", "createJourneyMachineId", "CommandRateLimiter", "maxCommandsPerWindow", "windowMs", "now", "windowStart", "timestamp", "cloneForTransport", "transportValue", "seen", "serialized", "_key", "currentValue", "serializeError", "error", "cause", "serializeSnapshot", "snapshot", "byStep", "stepId", "stepState", "isVisited", "serializeObservationEvent", "event", "serializeExecutionPathsResult", "result", "isKnownStepId", "assertKnownStepId", "machine", "commandType", "toSnapshotCommandOutcome", "hasExecutionPathsSupport", "isReadOnlyCommand", "command", "createCapabilities", "commandsEnabled", "executionPaths", "commands", "runCommand", "sendEvent", "attachJourneyDevtools", "machineId", "targetOrigin", "capabilities", "meta", "createBaseEnvelope", "kind", "JOURNEY_DEVTOOLS_CHANNEL", "JOURNEY_DEVTOOLS_BRIDGE_SOURCE", "post", "envelope", "postSnapshot", "postObservation", "postExecutionPathsResult", "requestId", "isDetached", "rateLimiter", "pendingSnapshot", "scheduledSnapshotHandle", "scheduledSnapshotKind", "clearScheduledSnapshotState", "flushScheduledSnapshot", "scheduleSnapshotPost", "cancelScheduledSnapshot", "onMessage", "isJourneyDevtoolsEnvelope", "JOURNEY_DEVTOOLS_EXTENSION_SOURCE", "commandEnvelope", "errorEnvelope", "outcome", "resultEnvelope", "unsubscribeSnapshot", "registerEnvelope", "unsubscribeObservation", "unregisterEnvelope"]
7
7
  }
package/dist/index.d.cts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { attachJourneyDevtools, type JourneyDevtoolsBridgeOptions } from "./bridge";
2
- export { JOURNEY_DEVTOOLS_CHANNEL, JOURNEY_DEVTOOLS_PROTOCOL_VERSION, JOURNEY_DEVTOOLS_BRIDGE_SOURCE, JOURNEY_DEVTOOLS_EXTENSION_SOURCE, isJourneyDevtoolsCommand, isJourneyDevtoolsEnvelope, isJourneyDevtoolsBridgeEnvelope, isJourneyDevtoolsExtensionEnvelope, type JourneyDevtoolsBridgeCommandErrorEnvelope, type JourneyDevtoolsBridgeCommandResultEnvelope, type JourneyDevtoolsBridgeEnvelope, type JourneyDevtoolsBridgeRegisterEnvelope, type JourneyDevtoolsBridgeSnapshotEnvelope, type JourneyDevtoolsBridgeUnregisterEnvelope, type JourneyDevtoolsCommand, type JourneyDevtoolsEnvelope, type JourneyDevtoolsExtensionEnvelope, type JourneyDevtoolsExtensionCommandEnvelope, type JourneyDevtoolsMachineMeta, type JourneyDevtoolsSerializableSnapshot, type JourneyDevtoolsSerializedError } from "./protocol";
2
+ export { JOURNEY_DEVTOOLS_CHANNEL, JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION, JOURNEY_DEVTOOLS_PROTOCOL_VERSION, JOURNEY_DEVTOOLS_BRIDGE_SOURCE, JOURNEY_DEVTOOLS_EXTENSION_SOURCE, isJourneyDevtoolsCommand, isJourneyDevtoolsEnvelope, isJourneyDevtoolsBridgeEnvelope, isJourneyDevtoolsExtensionEnvelope, type JourneyDevtoolsBridgeCommandErrorEnvelope, type JourneyDevtoolsBridgeCommandResultEnvelope, type JourneyDevtoolsBridgeExecutionPathsResultEnvelope, type JourneyDevtoolsBridgeEnvelope, type JourneyDevtoolsBridgeObservationEnvelope, type JourneyDevtoolsBridgeRegisterEnvelope, type JourneyDevtoolsBridgeSnapshotEnvelope, type JourneyDevtoolsBridgeUnregisterEnvelope, type JourneyDevtoolsCommand, type JourneyDevtoolsEnvelope, type JourneyDevtoolsExtensionEnvelope, type JourneyDevtoolsExtensionCommandEnvelope, type JourneyDevtoolsMachineCapabilities, type JourneyDevtoolsMachineMeta, type JourneyDevtoolsProtocolVersion, type JourneyDevtoolsSerializableExecutionPathsResult, type JourneyDevtoolsSerializableObservationEvent, type JourneyDevtoolsSerializableSnapshot, type JourneyDevtoolsSerializedError } from "./protocol";
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { attachJourneyDevtools, type JourneyDevtoolsBridgeOptions } from "./bridge";
2
- export { JOURNEY_DEVTOOLS_CHANNEL, JOURNEY_DEVTOOLS_PROTOCOL_VERSION, JOURNEY_DEVTOOLS_BRIDGE_SOURCE, JOURNEY_DEVTOOLS_EXTENSION_SOURCE, isJourneyDevtoolsCommand, isJourneyDevtoolsEnvelope, isJourneyDevtoolsBridgeEnvelope, isJourneyDevtoolsExtensionEnvelope, type JourneyDevtoolsBridgeCommandErrorEnvelope, type JourneyDevtoolsBridgeCommandResultEnvelope, type JourneyDevtoolsBridgeEnvelope, type JourneyDevtoolsBridgeRegisterEnvelope, type JourneyDevtoolsBridgeSnapshotEnvelope, type JourneyDevtoolsBridgeUnregisterEnvelope, type JourneyDevtoolsCommand, type JourneyDevtoolsEnvelope, type JourneyDevtoolsExtensionEnvelope, type JourneyDevtoolsExtensionCommandEnvelope, type JourneyDevtoolsMachineMeta, type JourneyDevtoolsSerializableSnapshot, type JourneyDevtoolsSerializedError } from "./protocol";
2
+ export { JOURNEY_DEVTOOLS_CHANNEL, JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION, JOURNEY_DEVTOOLS_PROTOCOL_VERSION, JOURNEY_DEVTOOLS_BRIDGE_SOURCE, JOURNEY_DEVTOOLS_EXTENSION_SOURCE, isJourneyDevtoolsCommand, isJourneyDevtoolsEnvelope, isJourneyDevtoolsBridgeEnvelope, isJourneyDevtoolsExtensionEnvelope, type JourneyDevtoolsBridgeCommandErrorEnvelope, type JourneyDevtoolsBridgeCommandResultEnvelope, type JourneyDevtoolsBridgeExecutionPathsResultEnvelope, type JourneyDevtoolsBridgeEnvelope, type JourneyDevtoolsBridgeObservationEnvelope, type JourneyDevtoolsBridgeRegisterEnvelope, type JourneyDevtoolsBridgeSnapshotEnvelope, type JourneyDevtoolsBridgeUnregisterEnvelope, type JourneyDevtoolsCommand, type JourneyDevtoolsEnvelope, type JourneyDevtoolsExtensionEnvelope, type JourneyDevtoolsExtensionCommandEnvelope, type JourneyDevtoolsMachineCapabilities, type JourneyDevtoolsMachineMeta, type JourneyDevtoolsProtocolVersion, type JourneyDevtoolsSerializableExecutionPathsResult, type JourneyDevtoolsSerializableObservationEvent, type JourneyDevtoolsSerializableSnapshot, type JourneyDevtoolsSerializedError } from "./protocol";
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var w=3,J="__RXOVA_JOURNEY_DEVTOOLS__",S="rxova-journey-bridge",g="rxova-journey-extension",a=e=>typeof e=="object"&&e!==null,G=e=>e===S||e===g;var c=e=>{try{let t=JSON.stringify(e);if(t!==void 0&&t.length>5e5)return!1}catch{return!1}return I(e,0)},I=(e,t)=>t>10?!1:e==null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"?!0:typeof e!="object"?!1:Array.isArray(e)?e.every(n=>I(n,t+1)):Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null?!1:Object.values(e).every(n=>I(n,t+1)),B=e=>a(e)?e.channel===J&&e.version===3&&G(e.source)&&typeof e.kind=="string"&&typeof e.machineId=="string"&&typeof e.timestamp=="number":!1,H=e=>!a(e)||typeof e.type!="string"||e.type.length===0||e.type.length>100?!1:"payload"in e&&e.payload!==void 0?c(e.payload):!0,k=e=>{if(!a(e)||typeof e.type!="string"||e.type.length===0||e.type.length>50)return!1;switch(e.type){case"goToNextStep":case"terminateMachine":case"completeJourney":case"resetMachine":case"goToLastVisitedStep":return Object.keys(e).length===1;case"goToStepById":return typeof e.stepId=="string"&&e.stepId.length>0&&e.stepId.length<=100&&Object.keys(e).length===2;case"goToPreviousStep":return(e.steps===void 0||typeof e.steps=="number"&&Number.isInteger(e.steps)&&e.steps>=1&&e.steps<=1e4)&&Object.keys(e).length<=2;case"send":return H(e.event)&&Object.keys(e).length===2;case"updateStepMetadata":return typeof e.stepId=="string"&&e.stepId.length>0&&e.stepId.length<=100&&c(e.metadata)&&Object.keys(e).length===3;case"clearStepError":return(e.stepId===void 0||typeof e.stepId=="string"&&e.stepId.length<=100)&&Object.keys(e).length<=2;default:return!1}},L=e=>{if(!B(e)||e.source!==S)return!1;let t=e;switch(e.kind){case"register":return a(t.meta)&&a(t.snapshot)&&c(t.meta)&&c(t.snapshot);case"unregister":return!0;case"snapshot":return a(t.snapshot)&&c(t.snapshot);case"commandResult":return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&a(t.snapshot)&&c(t.snapshot)&&(!("error"in t)||a(t.error));case"commandError":return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&a(t.error);default:return!1}},U=e=>{if(!B(e)||e.source!==g||e.kind!=="command")return!1;let t=e;return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&k(t.command)},x=e=>L(e)||U(e);var K="Journey Machine",P=e=>typeof e=="object"&&e!==null,F=e=>e==="idle"||e==="evaluating-when"||e==="running-effect"||e==="error",W=e=>P(e)?e.PROD===!0?!1:e.DEV===!0?!0:null:null,$=e=>typeof e!="string"?null:e!=="production",A=(e={})=>{let t="bundlerEnv"in e?e.bundlerEnv:import.meta.env,n="nodeEnv"in e?e.nodeEnv:typeof process<"u"?process.env?.NODE_ENV:void 0;return W(t)??$(n)??!1},Z=()=>typeof window>"u"||window.location.origin==="null"?"*":window.location.origin,Q=e=>{if(e.length===0||typeof window>"u")return!1;let t=window.location.origin;return t==="null"?e==="null":e===t},ee=()=>`journey-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,b=class{constructor(t=100,n=1e4){this.commandTimestamps=[];this.maxCommandsPerWindow=t,this.windowMs=n}isAllowed(){let t=Date.now(),n=t-this.windowMs;return this.commandTimestamps=this.commandTimestamps.filter(o=>o>n),this.commandTimestamps.length>=this.maxCommandsPerWindow?!1:(this.commandTimestamps.push(t),!0)}reset(){this.commandTimestamps=[]}},m=e=>{let t=typeof structuredClone=="function"?(()=>{try{return structuredClone(e)}catch{return e}})():e,n=new WeakSet;try{let o=JSON.stringify(t,(v,s)=>{if(typeof s=="bigint")return s.toString();if(typeof s=="function")return`[Function ${s.name||"anonymous"}]`;if(typeof s=="symbol")return s.toString();if(typeof s=="object"&&s!==null){if(n.has(s))return"[Circular]";n.add(s)}return s});return o===void 0?void 0:JSON.parse(o)}catch{return String(e)}},D=e=>{if(e instanceof Error){let t="cause"in e&&e.cause!==void 0?e.cause:null;return{name:e.name,message:e.message,stack:typeof e.stack=="string"?e.stack:null,cause:m(t)}}return{name:null,message:typeof e=="string"?e:"Unknown error",stack:null,cause:m(e)}},R=e=>{let t={};for(let[n,o]of Object.entries(e.async.byStep))P(o)&&(t[n]={phase:F(o.phase)?o.phase:"idle",eventType:typeof o.eventType=="string"?o.eventType:null,transitionId:typeof o.transitionId=="string"?o.transitionId:null,error:o.error===null?null:m(o.error)});return{currentStepId:String(e.currentStepId),context:m(e.context),history:{timeline:e.history.timeline.map(n=>String(n)),index:e.history.index},visited:Object.fromEntries(Object.entries(e.visited).map(([n,o])=>[String(n),o===!0])),stepMeta:m(e.stepMeta),status:e.status,async:{isLoading:e.async.isLoading,byStep:t}}},te=(e,t)=>t in e.stepMeta,_=(e,t,n)=>{if(!te(e.getSnapshot(),t))throw new Error(`Unknown stepId "${t}" for "${n}" command.`);return t},E=e=>({snapshot:e.snapshot,transitioned:e.transitioned,...e.transitionId?{transitionId:e.transitionId}:{},..."error"in e?{error:D(e.error)}:{}}),ne=async(e,t)=>{switch(t.type){case"goToNextStep":case"completeJourney":{let n=await e.send({type:t.type});return E(n)}case"terminateMachine":{let n=await e.send({type:"terminateJourney"});return E(n)}case"goToStepById":{let n=_(e,t.stepId,t.type),o=await e.send({type:"goToStepById",stepId:n});return E(o)}case"goToPreviousStep":{let n=await e.goToPreviousStep(t.steps);return E(n)}case"goToLastVisitedStep":{let n=await e.goToLastVisitedStep();return E(n)}case"send":{let n=t.event.payload===void 0?{type:t.event.type}:{type:t.event.type,payload:t.event.payload},o=await e.send(n);return E(o)}case"updateStepMetadata":{let n=_(e,t.stepId,t.type);return{snapshot:e.updateStepMetadata(n,()=>t.metadata)}}case"resetMachine":return{snapshot:e.resetMachine()};case"clearStepError":{let n=t.stepId===void 0?void 0:_(e,t.stepId,t.type);return{snapshot:e.clearStepError(n)}}}},oe=(e,t={})=>{if(!(t.enabled??A())||typeof window>"u")return()=>{};let o=t.commandsEnabled??A(),v=t.machineId?.trim()||ee(),s={machineId:v,label:t.label?.trim()||K,appName:t.appName?.trim()||(typeof document<"u"?document.title:"")||null,commandsEnabled:o},V=Z(),d=r=>({channel:J,version:3,source:S,kind:r,machineId:v,timestamp:Date.now()}),u=r=>{try{window.postMessage(r,V)}catch{}},Y=r=>{let p={...d("snapshot"),snapshot:R(r)};u(p)},l=!1,C=new b,O=null,y=null,f=null,T=()=>{O=null,y=null,f=null},M=()=>{let r=O;T(),!(!r||l)&&Y(r)},j=r=>{if(O=r,y===null){if(typeof window.requestAnimationFrame=="function"){f="raf",y=window.requestAnimationFrame(()=>{M()});return}f="timeout",y=globalThis.setTimeout(()=>{M()},0)}},q=()=>{if(y===null){T();return}f==="raf"&&typeof window.cancelAnimationFrame=="function"?window.cancelAnimationFrame(y):globalThis.clearTimeout(y),T()},N=r=>{if(r.source!==window||!Q(r.origin)||l||!x(r.data)||r.data.source!==g||r.data.kind!=="command")return;let p=r.data;if(p.machineId!==v)return;if(!C.isAllowed()){let i={...d("commandError"),requestId:p.requestId,error:D("Command rate limit exceeded. Too many commands in a short time window.")};u(i);return}if(!o){let i={...d("commandError"),requestId:p.requestId,error:D("Bridge commands are disabled by configuration.")};u(i);return}(async()=>{try{let i=await ne(e,p.command);if(l)return;let h={...d("commandResult"),requestId:p.requestId,snapshot:R(i.snapshot),...i.transitioned!==void 0?{transitioned:i.transitioned}:{},...i.transitionId?{transitionId:i.transitionId}:{},..."error"in i?{error:i.error}:{}};u(h)}catch(i){if(l)return;let h={...d("commandError"),requestId:p.requestId,error:D(i)};u(h)}})()};window.addEventListener("message",N);let z=e.subscribe(()=>{l||j(e.getSnapshot())}),X={...d("register"),meta:s,snapshot:R(e.getSnapshot())};return u(X),()=>{if(l)return;l=!0,C.reset(),z(),window.removeEventListener("message",N),q();let r={...d("unregister")};u(r)}};export{S as JOURNEY_DEVTOOLS_BRIDGE_SOURCE,J as JOURNEY_DEVTOOLS_CHANNEL,g as JOURNEY_DEVTOOLS_EXTENSION_SOURCE,w as JOURNEY_DEVTOOLS_PROTOCOL_VERSION,oe as attachJourneyDevtools,L as isJourneyDevtoolsBridgeEnvelope,k as isJourneyDevtoolsCommand,x as isJourneyDevtoolsEnvelope,U as isJourneyDevtoolsExtensionEnvelope};
1
+ var R=4,ee=3,h="__RXOVA_JOURNEY_DEVTOOLS__",J="rxova-journey-bridge",S="rxova-journey-extension",i=e=>typeof e=="object"&&e!==null,te=e=>e===J||e===S,ne=e=>e===3||e===4,oe=["startJourney","goToNextStep","terminateJourney","completeJourney","goToStepById","goToPreviousStep","goToLastVisitedStep","send","resetJourney","clearStepError","getExecutionPaths"],re=e=>typeof e=="string"&&oe.includes(e);var g=e=>{try{let t=JSON.stringify(e);if(t!==void 0&&t.length>5e5)return!1}catch{return!1}return x(e,0)},x=(e,t)=>t>10?!1:e==null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"?!0:typeof e!="object"?!1:Array.isArray(e)?e.every(n=>x(n,t+1)):Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null?!1:Object.values(e).every(n=>x(n,t+1)),B=e=>i(e)?e.channel===h&&ne(e.version)&&te(e.source)&&typeof e.kind=="string"&&typeof e.machineId=="string"&&typeof e.timestamp=="number":!1,b=(e,t=1e4)=>typeof e=="number"&&Number.isInteger(e)&&e>=1&&e<=t,se=e=>i(e)?Object.keys(e).length<=2&&(e.maxDepth===void 0||b(e.maxDepth))&&(e.maxPaths===void 0||b(e.maxPaths)):!1,ie=e=>!i(e)||typeof e.type!="string"||e.type.length===0||e.type.length>100?!1:"payload"in e&&e.payload!==void 0?g(e.payload):!0,M=e=>!i(e)||typeof e.observe!="boolean"||typeof e.executionPaths!="boolean"||!Array.isArray(e.commands)||!e.commands.every(t=>re(t))?!1:e.persistence===void 0?!0:i(e.persistence)?(e.persistence.key===null||typeof e.persistence.key=="string")&&(e.persistence.clearOnReset===null||typeof e.persistence.clearOnReset=="boolean"):!1,ae=(e,t)=>i(e)?typeof e.machineId=="string"&&typeof e.label=="string"&&(e.appName===null||typeof e.appName=="string")&&(e.commandsEnabled===void 0||typeof e.commandsEnabled=="boolean")&&(t===3&&e.capabilities===void 0||M(e.capabilities)):!1,ue=e=>i(e)?typeof e.type=="string"&&e.type.length>0&&e.type.length<=100&&typeof e.timestamp=="number"&&g(e):!1,pe=e=>{if(!i(e)||!Array.isArray(e.paths))return!1;let t=n=>n==="final"||n==="depth"||n==="cycle"||n==="limit";return e.paths.every(n=>i(n)&&Array.isArray(n.steps)&&n.steps.every(o=>typeof o=="string")&&Array.isArray(n.events)&&n.events.every(o=>typeof o=="string")&&t(n.terminated))&&typeof e.truncated=="boolean"&&typeof e.cyclesDetected=="boolean"},L=e=>{if(!i(e)||typeof e.type!="string"||e.type.length===0||e.type.length>50)return!1;switch(e.type){case"startJourney":case"goToNextStep":case"terminateJourney":case"completeJourney":case"resetJourney":case"goToLastVisitedStep":return Object.keys(e).length===1;case"goToStepById":return typeof e.stepId=="string"&&e.stepId.length>0&&e.stepId.length<=100&&Object.keys(e).length===2;case"goToPreviousStep":return(e.steps===void 0||b(e.steps))&&Object.keys(e).length<=2;case"send":return ie(e.event)&&Object.keys(e).length===2;case"clearStepError":return(e.stepId===void 0||typeof e.stepId=="string"&&e.stepId.length<=100)&&Object.keys(e).length<=2;case"getExecutionPaths":return(e.options===void 0||se(e.options))&&Object.keys(e).length<=2;default:return!1}},U=e=>{if(!B(e)||e.source!==J)return!1;let t=e;switch(e.kind){case"register":return ae(t.meta,e.version)&&i(t.snapshot)&&g(t.snapshot);case"unregister":return!0;case"snapshot":return i(t.snapshot)&&g(t.snapshot);case"observation":return ue(t.event);case"commandResult":return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&i(t.snapshot)&&g(t.snapshot)&&(!("error"in t)||i(t.error));case"executionPathsResult":return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&pe(t.result);case"commandError":return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&i(t.error);default:return!1}},V=e=>{if(!B(e)||e.source!==S||e.kind!=="command")return!1;let t=e;return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&L(t.command)},I=e=>U(e)||V(e);var le="Journey Machine",de=["startJourney","goToNextStep","terminateJourney","completeJourney","goToStepById","goToPreviousStep","goToLastVisitedStep","send","resetJourney","clearStepError"],j=e=>typeof e=="object"&&e!==null,ye=e=>e==="idle"||e==="evaluating-when"||e==="error",ce=e=>j(e)?e.PROD===!0?!1:e.DEV===!0?!0:null:null,Ee=e=>typeof e!="string"?null:e!=="production",A=(e={})=>{let t="bundlerEnv"in e?e.bundlerEnv:import.meta.env,n="nodeEnv"in e?e.nodeEnv:typeof process<"u"?process.env?.NODE_ENV:void 0;return ce(t)??Ee(n)??!1},ve=()=>typeof window>"u"||window.location.origin==="null"?"*":window.location.origin,ge=e=>{if(e.length===0||typeof window>"u")return!1;let t=window.location.origin;return t==="null"?e==="null":e===t},Je=()=>`journey-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,C=class{constructor(t=100,n=1e4){this.commandTimestamps=[];this.maxCommandsPerWindow=t,this.windowMs=n}isAllowed(){let t=Date.now(),n=t-this.windowMs;return this.commandTimestamps=this.commandTimestamps.filter(o=>o>n),this.commandTimestamps.length>=this.maxCommandsPerWindow?!1:(this.commandTimestamps.push(t),!0)}reset(){this.commandTimestamps=[]}},E=e=>{let t=typeof structuredClone=="function"?(()=>{try{return structuredClone(e)}catch{return e}})():e,n=new WeakSet;try{let o=JSON.stringify(t,(d,u)=>{if(typeof u=="bigint")return u.toString();if(typeof u=="function")return`[Function ${u.name||"anonymous"}]`;if(typeof u=="symbol")return u.toString();if(typeof u=="object"&&u!==null){if(n.has(u))return"[Circular]";n.add(u)}return u});return o===void 0?void 0:JSON.parse(o)}catch{return String(e)}},m=e=>{if(e instanceof Error){let t="cause"in e&&e.cause!==void 0?e.cause:null;return{name:e.name,message:e.message,stack:typeof e.stack=="string"?e.stack:null,cause:E(t)}}return{name:null,message:typeof e=="string"?e:"Unknown error",stack:null,cause:E(e)}},w=e=>{let t={};for(let[n,o]of Object.entries(e.async.byStep))j(o)&&(t[n]={phase:ye(o.phase)?o.phase:"idle",eventType:typeof o.eventType=="string"?o.eventType:null,transitionId:typeof o.transitionId=="string"?o.transitionId:null,error:o.error===null?null:E(o.error)});return{currentStepId:String(e.currentStepId),context:E(e.context),history:{timeline:e.history.timeline.map(n=>String(n)),index:e.history.index},visited:Object.fromEntries(Object.entries(e.visited).map(([n,o])=>[String(n),o===!0])),status:e.status,async:{isLoading:e.async.isLoading,byStep:t}}},Se=e=>e.type==="transition.error"?E({...e,error:m(e.error)}):E(e),me=e=>E(e),Oe=(e,t)=>t in e.async.byStep,Y=(e,t,n)=>{if(!Oe(e.getSnapshot(),t))throw new Error(`Unknown stepId "${t}" for "${n}" command.`);return t},v=e=>({kind:"snapshot",snapshot:e.snapshot,transitioned:e.transitioned,...e.transitionId?{transitionId:e.transitionId}:{},..."error"in e?{error:m(e.error)}:{}}),z=e=>typeof e.getExecutionPaths=="function",he=e=>e.type==="getExecutionPaths",Te=(e,t,n)=>{let o=z(e),d=[];return n&&d.push(...de),o&&d.push("getExecutionPaths"),{commands:d,observe:!0,executionPaths:o,...t.pluginMetadata?.persistence?{persistence:{key:t.pluginMetadata.persistence.key?.trim()||null,clearOnReset:typeof t.pluginMetadata.persistence.clearOnReset=="boolean"?t.pluginMetadata.persistence.clearOnReset:null}}:{}}},fe=async(e,t)=>{switch(t.type){case"startJourney":return{kind:"snapshot",snapshot:await e.startJourney()};case"goToNextStep":case"completeJourney":{let n=await e.send({type:t.type});return v(n)}case"terminateJourney":{let n=await e.send({type:"terminateJourney"});return v(n)}case"goToStepById":{let n=Y(e,t.stepId,t.type),o=await e.send({type:"goToStepById",stepId:n});return v(o)}case"goToPreviousStep":{let n=await e.goToPreviousStep(t.steps);return v(n)}case"goToLastVisitedStep":{let n=await e.goToLastVisitedStep();return v(n)}case"send":{let n=t.event.payload===void 0?{type:t.event.type}:{type:t.event.type,payload:t.event.payload},o=await e.send(n);return v(o)}case"resetJourney":return{kind:"snapshot",snapshot:await e.resetJourney()};case"clearStepError":{let n=t.stepId===void 0?void 0:Y(e,t.stepId,t.type);return{kind:"snapshot",snapshot:await e.clearStepError(n)}}case"getExecutionPaths":{if(!z(e))throw new Error('Machine does not support "getExecutionPaths".');return{kind:"executionPaths",result:e.getExecutionPaths(t.options)}}}},De=(e,t={})=>{if(!(t.enabled??A())||typeof window>"u")return()=>{};let o=t.commandsEnabled??A(),d=t.machineId?.trim()||Je(),u=ve(),q=Te(e,t,o),H={machineId:d,label:t.label?.trim()||le,appName:t.appName?.trim()||(typeof document<"u"?document.title:"")||null,commandsEnabled:o,capabilities:q},p=r=>({channel:h,version:4,source:J,kind:r,machineId:d,timestamp:Date.now()}),l=r=>{try{window.postMessage(r,u)}catch{}},G=r=>{let a={...p("snapshot"),snapshot:w(r)};l(a)},X=r=>{let a={...p("observation"),event:Se(r)};l(a)},K=(r,a)=>{let N={...p("executionPathsResult"),requestId:r,result:me(a)};l(N)},y=!1,_=new C,T=null,c=null,O=null,f=()=>{T=null,c=null,O=null},P=()=>{let r=T;f(),!(!r||y)&&G(r)},F=r=>{if(T=r,c===null){if(typeof window.requestAnimationFrame=="function"){O="raf",c=window.requestAnimationFrame(()=>{P()});return}O="timeout",c=globalThis.setTimeout(()=>{P()},0)}},W=()=>{if(c===null){f();return}O==="raf"&&typeof window.cancelAnimationFrame=="function"?window.cancelAnimationFrame(c):globalThis.clearTimeout(c),f()},k=r=>{if(r.source!==window||!ge(r.origin)||y||!I(r.data)||r.data.source!==S||r.data.kind!=="command")return;let a=r.data;if(a.machineId!==d)return;if(!_.isAllowed()){let s={...p("commandError"),requestId:a.requestId,error:m("Command rate limit exceeded. Too many commands in a short time window.")};l(s);return}if(!o&&!he(a.command)){let s={...p("commandError"),requestId:a.requestId,error:m("Bridge commands are disabled by configuration.")};l(s);return}(async()=>{try{let s=await fe(e,a.command);if(y)return;if(s.kind==="executionPaths"){K(a.requestId,s.result);return}let D={...p("commandResult"),requestId:a.requestId,snapshot:w(s.snapshot),...s.transitioned!==void 0?{transitioned:s.transitioned}:{},...s.transitionId?{transitionId:s.transitionId}:{},..."error"in s?{error:s.error}:{}};l(D)}catch(s){if(y)return;let D={...p("commandError"),requestId:a.requestId,error:m(s)};l(D)}})()};window.addEventListener("message",k);let $=e.subscribe(()=>{y||F(e.getSnapshot())}),Z={...p("register"),meta:H,snapshot:w(e.getSnapshot())};l(Z);let Q=e.subscribeEvent(r=>{y||X(r)});return()=>{if(y)return;y=!0,_.reset(),Q(),$(),window.removeEventListener("message",k),W();let r={...p("unregister")};l(r)}};export{J as JOURNEY_DEVTOOLS_BRIDGE_SOURCE,h as JOURNEY_DEVTOOLS_CHANNEL,S as JOURNEY_DEVTOOLS_EXTENSION_SOURCE,ee as JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION,R as JOURNEY_DEVTOOLS_PROTOCOL_VERSION,De as attachJourneyDevtools,U as isJourneyDevtoolsBridgeEnvelope,L as isJourneyDevtoolsCommand,I as isJourneyDevtoolsEnvelope,V as isJourneyDevtoolsExtensionEnvelope};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/protocol.ts", "../src/bridge.ts"],
4
- "sourcesContent": ["import type { JourneySnapshot, JourneyStepAsyncState } from \"@rxova/journey-core\";\n\nexport const JOURNEY_DEVTOOLS_PROTOCOL_VERSION = 3 as const;\nexport const JOURNEY_DEVTOOLS_CHANNEL = \"__RXOVA_JOURNEY_DEVTOOLS__\" as const;\n\nexport const JOURNEY_DEVTOOLS_BRIDGE_SOURCE = \"rxova-journey-bridge\" as const;\nexport const JOURNEY_DEVTOOLS_EXTENSION_SOURCE = \"rxova-journey-extension\" as const;\n\nexport type JourneyDevtoolsSource =\n | typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE\n | typeof JOURNEY_DEVTOOLS_EXTENSION_SOURCE;\n\nexport type JourneyDevtoolsStepAsyncState = JourneyStepAsyncState;\n\nexport type JourneyDevtoolsSerializableSnapshot = JourneySnapshot<unknown, string>;\n\nexport type JourneyDevtoolsMachineMeta = {\n machineId: string;\n label: string;\n appName: string | null;\n commandsEnabled?: boolean;\n};\n\nexport type JourneyDevtoolsSerializedError = {\n name: string | null;\n message: string;\n stack: string | null;\n cause: unknown;\n};\n\nexport type JourneyDevtoolsCommand =\n | { type: \"goToNextStep\" }\n | { type: \"terminateMachine\" }\n | { type: \"completeJourney\" }\n | { type: \"goToStepById\"; stepId: string }\n | { type: \"goToPreviousStep\"; steps?: number }\n | { type: \"goToLastVisitedStep\" }\n | { type: \"send\"; event: { type: string; payload?: unknown } }\n | { type: \"updateStepMetadata\"; stepId: string; metadata: unknown }\n | { type: \"resetMachine\" }\n | { type: \"clearStepError\"; stepId?: string };\n\nexport type JourneyDevtoolsEnvelopeBase = {\n channel: typeof JOURNEY_DEVTOOLS_CHANNEL;\n version: typeof JOURNEY_DEVTOOLS_PROTOCOL_VERSION;\n source: JourneyDevtoolsSource;\n kind: string;\n machineId: string;\n timestamp: number;\n};\n\nexport type JourneyDevtoolsBridgeRegisterEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"register\";\n meta: JourneyDevtoolsMachineMeta;\n snapshot: JourneyDevtoolsSerializableSnapshot;\n};\n\nexport type JourneyDevtoolsBridgeUnregisterEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"unregister\";\n};\n\nexport type JourneyDevtoolsBridgeSnapshotEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"snapshot\";\n snapshot: JourneyDevtoolsSerializableSnapshot;\n};\n\nexport type JourneyDevtoolsBridgeCommandResultEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"commandResult\";\n requestId: string;\n snapshot: JourneyDevtoolsSerializableSnapshot;\n transitioned?: boolean;\n transitionId?: string;\n error?: JourneyDevtoolsSerializedError;\n};\n\nexport type JourneyDevtoolsBridgeCommandErrorEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"commandError\";\n requestId: string;\n error: JourneyDevtoolsSerializedError;\n};\n\nexport type JourneyDevtoolsExtensionCommandEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_EXTENSION_SOURCE;\n kind: \"command\";\n requestId: string;\n command: JourneyDevtoolsCommand;\n};\n\nexport type JourneyDevtoolsBridgeEnvelope =\n | JourneyDevtoolsBridgeRegisterEnvelope\n | JourneyDevtoolsBridgeUnregisterEnvelope\n | JourneyDevtoolsBridgeSnapshotEnvelope\n | JourneyDevtoolsBridgeCommandResultEnvelope\n | JourneyDevtoolsBridgeCommandErrorEnvelope;\n\nexport type JourneyDevtoolsExtensionEnvelope = JourneyDevtoolsExtensionCommandEnvelope;\n\nexport type JourneyDevtoolsEnvelope =\n | JourneyDevtoolsBridgeEnvelope\n | JourneyDevtoolsExtensionEnvelope;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nconst isKnownSource = (value: unknown): value is JourneyDevtoolsSource =>\n value === JOURNEY_DEVTOOLS_BRIDGE_SOURCE || value === JOURNEY_DEVTOOLS_EXTENSION_SOURCE;\n\n/**\n * Maximum depth for nested object validation.\n * Prevents stack overflow and excessive processing from deeply nested malicious payloads.\n */\nconst MAX_PAYLOAD_DEPTH = 10;\n\n/**\n * Maximum size (in JSON string length) for serialized payloads.\n * Prevents memory exhaustion from extremely large payloads.\n */\nconst MAX_PAYLOAD_SIZE = 500_000; // 500KB\n\n/**\n * Validates that a value is safe for transport.\n * Checks size via a single serialization pass, then validates\n * depth, types, and prototype safety via a structure walk.\n */\nconst isSafePayload = (value: unknown): boolean => {\n try {\n const serialized = JSON.stringify(value);\n if (serialized !== undefined && serialized.length > MAX_PAYLOAD_SIZE) {\n return false;\n }\n } catch {\n return false;\n }\n\n return isStructureSafe(value, 0);\n};\n\nconst isStructureSafe = (value: unknown, depth: number): boolean => {\n if (depth > MAX_PAYLOAD_DEPTH) {\n return false;\n }\n\n if (value === null || value === undefined) {\n return true;\n }\n\n if (typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\") {\n return true;\n }\n\n if (typeof value !== \"object\") {\n return false;\n }\n\n if (Array.isArray(value)) {\n return value.every((item) => isStructureSafe(item, depth + 1));\n }\n\n if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {\n return false;\n }\n\n return Object.values(value).every((prop) => isStructureSafe(prop, depth + 1));\n};\n\nconst hasBaseEnvelopeShape = (value: unknown): value is JourneyDevtoolsEnvelopeBase => {\n if (!isRecord(value)) {\n return false;\n }\n\n return (\n value.channel === JOURNEY_DEVTOOLS_CHANNEL &&\n value.version === JOURNEY_DEVTOOLS_PROTOCOL_VERSION &&\n isKnownSource(value.source) &&\n typeof value.kind === \"string\" &&\n typeof value.machineId === \"string\" &&\n typeof value.timestamp === \"number\"\n );\n};\n\nconst isSendEvent = (value: unknown): value is { type: string; payload?: unknown } => {\n if (!isRecord(value)) {\n return false;\n }\n\n if (typeof value.type !== \"string\" || value.type.length === 0 || value.type.length > 100) {\n return false;\n }\n\n // Validate payload if present\n if (\"payload\" in value && value.payload !== undefined) {\n return isSafePayload(value.payload);\n }\n\n return true;\n};\n\n/**\n * Validates whether an unknown value is a supported devtools command payload.\n */\nexport const isJourneyDevtoolsCommand = (value: unknown): value is JourneyDevtoolsCommand => {\n if (!isRecord(value) || typeof value.type !== \"string\") {\n return false;\n }\n\n // Validate command type is within reasonable length\n if (value.type.length === 0 || value.type.length > 50) {\n return false;\n }\n\n switch (value.type) {\n case \"goToNextStep\":\n case \"terminateMachine\":\n case \"completeJourney\":\n case \"resetMachine\":\n case \"goToLastVisitedStep\":\n // These commands should have no extra properties beyond type\n return Object.keys(value).length === 1;\n case \"goToStepById\":\n return (\n typeof value.stepId === \"string\" &&\n value.stepId.length > 0 &&\n value.stepId.length <= 100 &&\n Object.keys(value).length === 2\n );\n case \"goToPreviousStep\":\n return (\n (value.steps === undefined ||\n (typeof value.steps === \"number\" &&\n Number.isInteger(value.steps) &&\n value.steps >= 1 &&\n value.steps <= 10000)) &&\n Object.keys(value).length <= 2\n );\n case \"send\":\n return isSendEvent(value.event) && Object.keys(value).length === 2;\n case \"updateStepMetadata\":\n return (\n typeof value.stepId === \"string\" &&\n value.stepId.length > 0 &&\n value.stepId.length <= 100 &&\n isSafePayload(value.metadata) &&\n Object.keys(value).length === 3\n );\n case \"clearStepError\":\n return (\n (value.stepId === undefined ||\n (typeof value.stepId === \"string\" && value.stepId.length <= 100)) &&\n Object.keys(value).length <= 2\n );\n default:\n return false;\n }\n};\n\n/**\n * Validates whether an unknown value is a bridge-origin envelope.\n */\nexport const isJourneyDevtoolsBridgeEnvelope = (\n value: unknown\n): value is JourneyDevtoolsBridgeEnvelope => {\n if (!hasBaseEnvelopeShape(value) || value.source !== JOURNEY_DEVTOOLS_BRIDGE_SOURCE) {\n return false;\n }\n\n const envelope = value as Record<string, unknown>;\n\n switch (value.kind) {\n case \"register\":\n return (\n isRecord(envelope.meta) &&\n isRecord(envelope.snapshot) &&\n isSafePayload(envelope.meta) &&\n isSafePayload(envelope.snapshot)\n );\n case \"unregister\":\n return true;\n case \"snapshot\":\n return isRecord(envelope.snapshot) && isSafePayload(envelope.snapshot);\n case \"commandResult\":\n return (\n typeof envelope.requestId === \"string\" &&\n envelope.requestId.length > 0 &&\n envelope.requestId.length <= 100 &&\n isRecord(envelope.snapshot) &&\n isSafePayload(envelope.snapshot) &&\n (!(\"error\" in envelope) || isRecord(envelope.error))\n );\n case \"commandError\":\n return (\n typeof envelope.requestId === \"string\" &&\n envelope.requestId.length > 0 &&\n envelope.requestId.length <= 100 &&\n isRecord(envelope.error)\n );\n default:\n return false;\n }\n};\n\n/**\n * Validates whether an unknown value is an extension-origin command envelope.\n */\nexport const isJourneyDevtoolsExtensionEnvelope = (\n value: unknown\n): value is JourneyDevtoolsExtensionEnvelope => {\n if (!hasBaseEnvelopeShape(value) || value.source !== JOURNEY_DEVTOOLS_EXTENSION_SOURCE) {\n return false;\n }\n\n if (value.kind !== \"command\") {\n return false;\n }\n\n const envelope = value as Record<string, unknown>;\n return (\n typeof envelope.requestId === \"string\" &&\n envelope.requestId.length > 0 &&\n envelope.requestId.length <= 100 &&\n isJourneyDevtoolsCommand(envelope.command)\n );\n};\n\n/**\n * Validates whether an unknown value matches either supported devtools envelope shape.\n */\nexport const isJourneyDevtoolsEnvelope = (value: unknown): value is JourneyDevtoolsEnvelope =>\n isJourneyDevtoolsBridgeEnvelope(value) || isJourneyDevtoolsExtensionEnvelope(value);\n", "import type {\n JourneyEventPayloadMap,\n JourneyMachine,\n JourneySendResult,\n JourneySnapshot\n} from \"@rxova/journey-core\";\nimport {\n JOURNEY_DEVTOOLS_BRIDGE_SOURCE,\n JOURNEY_DEVTOOLS_CHANNEL,\n JOURNEY_DEVTOOLS_EXTENSION_SOURCE,\n JOURNEY_DEVTOOLS_PROTOCOL_VERSION,\n isJourneyDevtoolsEnvelope,\n type JourneyDevtoolsBridgeCommandErrorEnvelope,\n type JourneyDevtoolsBridgeCommandResultEnvelope,\n type JourneyDevtoolsBridgeEnvelope,\n type JourneyDevtoolsBridgeRegisterEnvelope,\n type JourneyDevtoolsBridgeSnapshotEnvelope,\n type JourneyDevtoolsBridgeUnregisterEnvelope,\n type JourneyDevtoolsCommand,\n type JourneyDevtoolsExtensionCommandEnvelope,\n type JourneyDevtoolsMachineMeta,\n type JourneyDevtoolsSerializableSnapshot,\n type JourneyDevtoolsSerializedError\n} from \"./protocol\";\n\ndeclare const process: { env?: { NODE_ENV?: string } } | undefined;\n\nexport type JourneyDevtoolsBridgeOptions = {\n machineId?: string;\n label?: string;\n enabled?: boolean;\n appName?: string;\n commandsEnabled?: boolean;\n};\n\ntype SendOutcome<TContext, TStepId extends string, TStepMeta> = {\n snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>;\n transitioned?: boolean;\n transitionId?: string;\n error?: JourneyDevtoolsSerializedError;\n};\n\ntype SnapshotScheduleKind = \"raf\" | \"timeout\";\n\nconst DEFAULT_MACHINE_LABEL = \"Journey Machine\";\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nconst isJourneyAsyncPhase = (\n value: unknown\n): value is JourneyDevtoolsSerializableSnapshot[\"async\"][\"byStep\"][string][\"phase\"] =>\n value === \"idle\" ||\n value === \"evaluating-when\" ||\n value === \"running-effect\" ||\n value === \"error\";\n\ntype JourneyImportMetaEnv = {\n DEV?: unknown;\n PROD?: unknown;\n};\n\nconst resolveImportMetaEnvironment = (\n bundlerEnv: JourneyImportMetaEnv | null | undefined\n): boolean | null => {\n if (!isRecord(bundlerEnv)) {\n return null;\n }\n\n if (bundlerEnv.PROD === true) {\n return false;\n }\n\n if (bundlerEnv.DEV === true) {\n return true;\n }\n\n return null;\n};\n\nconst resolveNodeEnvironment = (nodeEnv: string | undefined): boolean | null => {\n if (typeof nodeEnv !== \"string\") {\n return null;\n }\n\n return nodeEnv !== \"production\";\n};\n\nexport const resolveNonProductionEnvironment = (\n options: {\n bundlerEnv?: JourneyImportMetaEnv | null | undefined;\n nodeEnv?: string | undefined;\n } = {}\n): boolean => {\n const resolvedBundlerEnv =\n \"bundlerEnv\" in options\n ? options.bundlerEnv\n : (import.meta as ImportMeta & { env?: JourneyImportMetaEnv }).env;\n const resolvedNodeEnv =\n \"nodeEnv\" in options\n ? options.nodeEnv\n : typeof process !== \"undefined\"\n ? process.env?.NODE_ENV\n : undefined;\n\n return (\n resolveImportMetaEnvironment(resolvedBundlerEnv) ??\n resolveNodeEnvironment(resolvedNodeEnv) ??\n false\n );\n};\n\nconst resolveWindowTargetOrigin = (): string => {\n if (typeof window === \"undefined\") {\n return \"*\";\n }\n\n return window.location.origin === \"null\" ? \"*\" : window.location.origin;\n};\n\n// No session token infrastructure needed\n\n/**\n * Validates that the message origin matches the current window origin.\n * This prevents messages from other origins from being processed.\n *\n * Note: This is part of defense-in-depth but not a hard security boundary.\n * Code running in the same origin can still send messages.\n */\nconst isExpectedWindowOrigin = (origin: string): boolean => {\n if (origin.length === 0) {\n return false;\n }\n\n if (typeof window === \"undefined\") {\n return false;\n }\n\n const expected = window.location.origin;\n if (expected === \"null\") {\n // For file:// or sandboxed contexts where origin is \"null\"\n return origin === \"null\";\n }\n\n // Strict equality check - no wildcard matching\n return origin === expected;\n};\n\nconst createMachineId = (): string =>\n `journey-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;\n\n/**\n * Simple rate limiter to prevent command abuse.\n * Tracks command timestamps and enforces a maximum rate.\n */\nclass CommandRateLimiter {\n private commandTimestamps: number[] = [];\n private readonly maxCommandsPerWindow: number;\n private readonly windowMs: number;\n\n constructor(maxCommandsPerWindow = 100, windowMs = 10000) {\n this.maxCommandsPerWindow = maxCommandsPerWindow;\n this.windowMs = windowMs;\n }\n\n /**\n * Checks if a command is allowed based on rate limits.\n * Returns true if allowed, false if rate limit exceeded.\n */\n isAllowed(): boolean {\n const now = Date.now();\n const windowStart = now - this.windowMs;\n\n // Remove old timestamps outside the window\n this.commandTimestamps = this.commandTimestamps.filter((ts) => ts > windowStart);\n\n if (this.commandTimestamps.length >= this.maxCommandsPerWindow) {\n return false;\n }\n\n this.commandTimestamps.push(now);\n return true;\n }\n\n reset(): void {\n this.commandTimestamps = [];\n }\n}\n\nconst cloneForTransport = (value: unknown): unknown => {\n const transportValue =\n typeof structuredClone === \"function\"\n ? (() => {\n try {\n return structuredClone(value);\n } catch {\n return value;\n }\n })()\n : value;\n const seen = new WeakSet<object>();\n\n try {\n const serialized = JSON.stringify(transportValue, (_key, currentValue) => {\n if (typeof currentValue === \"bigint\") {\n return currentValue.toString();\n }\n if (typeof currentValue === \"function\") {\n return `[Function ${currentValue.name || \"anonymous\"}]`;\n }\n if (typeof currentValue === \"symbol\") {\n return currentValue.toString();\n }\n if (typeof currentValue === \"object\" && currentValue !== null) {\n if (seen.has(currentValue)) {\n return \"[Circular]\";\n }\n seen.add(currentValue);\n }\n return currentValue;\n });\n\n if (serialized === undefined) {\n return undefined;\n }\n\n return JSON.parse(serialized) as unknown;\n } catch {\n return String(value);\n }\n};\n\nconst serializeError = (error: unknown): JourneyDevtoolsSerializedError => {\n if (error instanceof Error) {\n const cause =\n \"cause\" in error && (error as { cause?: unknown }).cause !== undefined\n ? (error as { cause?: unknown }).cause\n : null;\n return {\n name: error.name,\n message: error.message,\n stack: typeof error.stack === \"string\" ? error.stack : null,\n cause: cloneForTransport(cause)\n };\n }\n\n return {\n name: null,\n message: typeof error === \"string\" ? error : \"Unknown error\",\n stack: null,\n cause: cloneForTransport(error)\n };\n};\n\nconst serializeSnapshot = <TContext, TStepId extends string, TStepMeta>(\n snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>\n): JourneyDevtoolsSerializableSnapshot => {\n const byStep: Record<string, JourneyDevtoolsSerializableSnapshot[\"async\"][\"byStep\"][string]> = {};\n\n for (const [stepId, stepState] of Object.entries(\n snapshot.async.byStep as Record<string, unknown>\n )) {\n if (!isRecord(stepState)) {\n continue;\n }\n\n byStep[stepId] = {\n phase: isJourneyAsyncPhase(stepState.phase) ? stepState.phase : \"idle\",\n eventType: typeof stepState.eventType === \"string\" ? stepState.eventType : null,\n transitionId: typeof stepState.transitionId === \"string\" ? stepState.transitionId : null,\n error: stepState.error === null ? null : cloneForTransport(stepState.error)\n };\n }\n\n return {\n currentStepId: String(snapshot.currentStepId),\n context: cloneForTransport(snapshot.context),\n history: {\n timeline: snapshot.history.timeline.map((stepId) => String(stepId)),\n index: snapshot.history.index\n },\n visited: Object.fromEntries(\n Object.entries(snapshot.visited as Record<string, boolean>).map(([stepId, isVisited]) => [\n String(stepId),\n isVisited === true\n ])\n ),\n stepMeta: cloneForTransport(snapshot.stepMeta) as Record<string, unknown>,\n status: snapshot.status,\n async: {\n isLoading: snapshot.async.isLoading,\n byStep\n }\n };\n};\n\nconst isKnownStepId = <TContext, TStepId extends string, TStepMeta>(\n snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>,\n stepId: string\n): stepId is TStepId => stepId in snapshot.stepMeta;\n\nconst assertKnownStepId = <TContext, TStepId extends string, TStepMeta>(\n machine: JourneyMachine<TContext, TStepId, string, Record<never, never>, TStepMeta>,\n stepId: string,\n commandType: JourneyDevtoolsCommand[\"type\"]\n): TStepId => {\n if (!isKnownStepId(machine.getSnapshot(), stepId)) {\n throw new Error(`Unknown stepId \"${stepId}\" for \"${commandType}\" command.`);\n }\n return stepId;\n};\n\nconst toSendOutcome = <TContext, TStepId extends string, TStepMeta>(\n result: JourneySendResult<TContext, TStepId, TStepMeta>\n): SendOutcome<TContext, TStepId, TStepMeta> => ({\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {}),\n ...(\"error\" in result ? { error: serializeError(result.error) } : {})\n});\n\nconst runCommand = async <TContext, TStepId extends string, TStepMeta>(\n machine: JourneyMachine<TContext, TStepId, string, Record<never, never>, TStepMeta>,\n command: JourneyDevtoolsCommand\n): Promise<SendOutcome<TContext, TStepId, TStepMeta>> => {\n switch (command.type) {\n case \"goToNextStep\":\n case \"completeJourney\": {\n const result = await machine.send({ type: command.type });\n return toSendOutcome(result);\n }\n case \"terminateMachine\": {\n const result = await machine.send({ type: \"terminateJourney\" });\n return toSendOutcome(result);\n }\n case \"goToStepById\": {\n const stepId = assertKnownStepId(machine, command.stepId, command.type);\n const result = await machine.send({\n type: \"goToStepById\",\n stepId\n });\n return toSendOutcome(result);\n }\n case \"goToPreviousStep\": {\n const result = await machine.goToPreviousStep(command.steps);\n return toSendOutcome(result);\n }\n case \"goToLastVisitedStep\": {\n const result = await machine.goToLastVisitedStep();\n return toSendOutcome(result);\n }\n case \"send\": {\n const sendEvent =\n command.event.payload === undefined\n ? { type: command.event.type }\n : { type: command.event.type, payload: command.event.payload };\n const result: JourneySendResult<TContext, TStepId, TStepMeta> = await machine.send(sendEvent);\n return toSendOutcome(result);\n }\n case \"updateStepMetadata\": {\n const stepId = assertKnownStepId(machine, command.stepId, command.type);\n return {\n snapshot: machine.updateStepMetadata(stepId, () => command.metadata as TStepMeta)\n };\n }\n case \"resetMachine\":\n return {\n snapshot: machine.resetMachine()\n };\n case \"clearStepError\": {\n const stepId =\n command.stepId === undefined\n ? undefined\n : assertKnownStepId(machine, command.stepId, command.type);\n return {\n snapshot: machine.clearStepError(stepId)\n };\n }\n }\n};\n\n/**\n * Attaches a journey machine to the browser devtools transport and returns\n * a detach function that unsubscribes listeners and unregisters the machine.\n */\nexport const attachJourneyDevtools = <\n TContext,\n TStepId extends string,\n TEventType extends string,\n TPayloadMap extends JourneyEventPayloadMap<TEventType>,\n TStepMeta\n>(\n machine: JourneyMachine<TContext, TStepId, TEventType, TPayloadMap, TStepMeta>,\n options: JourneyDevtoolsBridgeOptions = {}\n): (() => void) => {\n const enabled = options.enabled ?? resolveNonProductionEnvironment();\n if (!enabled || typeof window === \"undefined\") {\n return () => {};\n }\n const commandsEnabled = options.commandsEnabled ?? resolveNonProductionEnvironment();\n\n const machineId = options.machineId?.trim() || createMachineId();\n const meta: JourneyDevtoolsMachineMeta = {\n machineId,\n label: options.label?.trim() || DEFAULT_MACHINE_LABEL,\n appName:\n options.appName?.trim() || (typeof document !== \"undefined\" ? document.title : \"\") || null,\n commandsEnabled\n };\n const targetOrigin = resolveWindowTargetOrigin();\n\n const createBaseEnvelope = <TKind extends JourneyDevtoolsBridgeEnvelope[\"kind\"]>(\n kind: TKind\n ) => ({\n channel: JOURNEY_DEVTOOLS_CHANNEL,\n version: JOURNEY_DEVTOOLS_PROTOCOL_VERSION,\n source: JOURNEY_DEVTOOLS_BRIDGE_SOURCE,\n kind,\n machineId,\n timestamp: Date.now()\n });\n\n const post = (envelope: JourneyDevtoolsBridgeEnvelope) => {\n try {\n window.postMessage(envelope, targetOrigin);\n } catch {\n // Swallow transport failures so bridge lifecycle and commands remain non-throwing.\n }\n };\n\n const postSnapshot = (snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>) => {\n const envelope: JourneyDevtoolsBridgeSnapshotEnvelope = {\n ...createBaseEnvelope(\"snapshot\"),\n snapshot: serializeSnapshot(snapshot)\n };\n post(envelope);\n };\n\n let isDetached = false;\n const rateLimiter = new CommandRateLimiter();\n let pendingSnapshot: JourneySnapshot<TContext, TStepId, TStepMeta> | null = null;\n let scheduledSnapshotHandle: number | ReturnType<typeof globalThis.setTimeout> | null = null;\n let scheduledSnapshotKind: SnapshotScheduleKind | null = null;\n\n const clearScheduledSnapshotState = () => {\n pendingSnapshot = null;\n scheduledSnapshotHandle = null;\n scheduledSnapshotKind = null;\n };\n\n const flushScheduledSnapshot = () => {\n const snapshot = pendingSnapshot;\n clearScheduledSnapshotState();\n\n if (!snapshot || isDetached) {\n return;\n }\n\n postSnapshot(snapshot);\n };\n\n const scheduleSnapshotPost = (snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>) => {\n pendingSnapshot = snapshot;\n if (scheduledSnapshotHandle !== null) {\n return;\n }\n\n if (typeof window.requestAnimationFrame === \"function\") {\n scheduledSnapshotKind = \"raf\";\n scheduledSnapshotHandle = window.requestAnimationFrame(() => {\n flushScheduledSnapshot();\n });\n return;\n }\n\n scheduledSnapshotKind = \"timeout\";\n scheduledSnapshotHandle = globalThis.setTimeout(() => {\n flushScheduledSnapshot();\n }, 0);\n };\n\n const cancelScheduledSnapshot = () => {\n if (scheduledSnapshotHandle === null) {\n clearScheduledSnapshotState();\n return;\n }\n\n if (scheduledSnapshotKind === \"raf\" && typeof window.cancelAnimationFrame === \"function\") {\n window.cancelAnimationFrame(scheduledSnapshotHandle as number);\n } else {\n globalThis.clearTimeout(scheduledSnapshotHandle);\n }\n\n clearScheduledSnapshotState();\n };\n\n const onMessage = (event: MessageEvent<unknown>) => {\n if (\n event.source !== window ||\n !isExpectedWindowOrigin(event.origin) ||\n isDetached ||\n !isJourneyDevtoolsEnvelope(event.data)\n ) {\n return;\n }\n\n if (event.data.source !== JOURNEY_DEVTOOLS_EXTENSION_SOURCE || event.data.kind !== \"command\") {\n return;\n }\n\n const commandEnvelope: JourneyDevtoolsExtensionCommandEnvelope = event.data;\n if (commandEnvelope.machineId !== machineId) {\n return;\n }\n\n // Rate limiting to prevent command abuse\n if (!rateLimiter.isAllowed()) {\n const errorEnvelope: JourneyDevtoolsBridgeCommandErrorEnvelope = {\n ...createBaseEnvelope(\"commandError\"),\n requestId: commandEnvelope.requestId,\n error: serializeError(\n \"Command rate limit exceeded. Too many commands in a short time window.\"\n )\n };\n post(errorEnvelope);\n return;\n }\n\n if (!commandsEnabled) {\n const errorEnvelope: JourneyDevtoolsBridgeCommandErrorEnvelope = {\n ...createBaseEnvelope(\"commandError\"),\n requestId: commandEnvelope.requestId,\n error: serializeError(\"Bridge commands are disabled by configuration.\")\n };\n post(errorEnvelope);\n return;\n }\n\n const run = async () => {\n try {\n const outcome = await runCommand(\n machine as JourneyMachine<TContext, TStepId, string, Record<never, never>, TStepMeta>,\n commandEnvelope.command\n );\n if (isDetached) {\n return;\n }\n\n const resultEnvelope: JourneyDevtoolsBridgeCommandResultEnvelope = {\n ...createBaseEnvelope(\"commandResult\"),\n requestId: commandEnvelope.requestId,\n snapshot: serializeSnapshot(outcome.snapshot),\n ...(outcome.transitioned !== undefined ? { transitioned: outcome.transitioned } : {}),\n ...(outcome.transitionId ? { transitionId: outcome.transitionId } : {}),\n ...(\"error\" in outcome ? { error: outcome.error } : {})\n };\n post(resultEnvelope);\n } catch (error) {\n if (isDetached) {\n return;\n }\n\n const errorEnvelope: JourneyDevtoolsBridgeCommandErrorEnvelope = {\n ...createBaseEnvelope(\"commandError\"),\n requestId: commandEnvelope.requestId,\n error: serializeError(error)\n };\n post(errorEnvelope);\n }\n };\n\n void run();\n };\n\n window.addEventListener(\"message\", onMessage);\n\n const unsubscribe = machine.subscribe(() => {\n if (isDetached) {\n return;\n }\n scheduleSnapshotPost(machine.getSnapshot());\n });\n\n const registerEnvelope: JourneyDevtoolsBridgeRegisterEnvelope = {\n ...createBaseEnvelope(\"register\"),\n meta,\n snapshot: serializeSnapshot(machine.getSnapshot())\n };\n post(registerEnvelope);\n\n return () => {\n if (isDetached) {\n return;\n }\n\n isDetached = true;\n rateLimiter.reset();\n unsubscribe();\n window.removeEventListener(\"message\", onMessage);\n cancelScheduledSnapshot();\n\n const unregisterEnvelope: JourneyDevtoolsBridge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lB,EACF,OAGFA,EAAa,GACbC,EAAY,MAAM,EAClBgB,EAAY,EACZ,OAAO,oBAAoB,UAAWR,CAAS,EAC/CD,EAAwB,EAExB,IAAMW,EAA8D,CAClE,GAAG1B,EAAmB,YAAY,CACpC,EACAI,EAAKsB,CAAkB,CACzB,CACF",
6
- "names": ["JOURNEY_DEVTOOLS_PROTOCOL_VERSION", "JOURNEY_DEVTOOLS_CHANNEL", "JOURNEY_DEVTOOLS_BRIDGE_SOURCE", "JOURNEY_DEVTOOLS_EXTENSION_SOURCE", "isRecord", "value", "isKnownSource", "isSafePayload", "value", "serialized", "isStructureSafe", "depth", "item", "prop", "hasBaseEnvelopeShape", "isRecord", "JOURNEY_DEVTOOLS_CHANNEL", "isKnownSource", "isSendEvent", "isJourneyDevtoolsCommand", "isJourneyDevtoolsBridgeEnvelope", "JOURNEY_DEVTOOLS_BRIDGE_SOURCE", "envelope", "isJourneyDevtoolsExtensionEnvelope", "JOURNEY_DEVTOOLS_EXTENSION_SOURCE", "isJourneyDevtoolsEnvelope", "DEFAULT_MACHINE_LABEL", "isRecord", "value", "isJourneyAsyncPhase", "resolveImportMetaEnvironment", "bundlerEnv", "resolveNodeEnvironment", "nodeEnv", "resolveNonProductionEnvironment", "options", "resolvedBundlerEnv", "resolvedNodeEnv", "resolveWindowTargetOrigin", "isExpectedWindowOrigin", "origin", "expected", "createMachineId", "CommandRateLimiter", "maxCommandsPerWindow", "windowMs", "now", "windowStart", "ts", "cloneForTransport", "transportValue", "seen", "serialized", "_key", "currentValue", "serializeError", "error", "cause", "serializeSnapshot", "snapshot", "byStep", "stepId", "stepState", "isVisited", "isKnownStepId", "assertKnownStepId", "machine", "commandType", "toSendOutcome", "result", "runCommand", "command", "sendEvent", "attachJourneyDevtools", "commandsEnabled", "machineId", "meta", "targetOrigin", "createBaseEnvelope", "kind", "JOURNEY_DEVTOOLS_CHANNEL", "JOURNEY_DEVTOOLS_BRIDGE_SOURCE", "post", "envelope", "postSnapshot", "isDetached", "rateLimiter", "pendingSnapshot", "scheduledSnapshotHandle", "scheduledSnapshotKind", "clearScheduledSnapshotState", "flushScheduledSnapshot", "scheduleSnapshotPost", "cancelScheduledSnapshot", "onMessage", "event", "isJourneyDevtoolsEnvelope", "JOURNEY_DEVTOOLS_EXTENSION_SOURCE", "commandEnvelope", "errorEnvelope", "outcome", "resultEnvelope", "unsubscribe", "registerEnvelope", "unregisterEnvelope"]
4
+ "sourcesContent": ["import type {\n JourneyExecutionPathOptions,\n JourneyExecutionPathsResult,\n JourneyJsonObject,\n JourneyObservationEvent,\n JourneySnapshot,\n JourneyStepAsyncState\n} from \"@rxova/journey-core\";\n\nexport const JOURNEY_DEVTOOLS_PROTOCOL_VERSION = 4 as const;\nexport const JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION = 3 as const;\nexport const JOURNEY_DEVTOOLS_CHANNEL = \"__RXOVA_JOURNEY_DEVTOOLS__\" as const;\n\nexport const JOURNEY_DEVTOOLS_BRIDGE_SOURCE = \"rxova-journey-bridge\" as const;\nexport const JOURNEY_DEVTOOLS_EXTENSION_SOURCE = \"rxova-journey-extension\" as const;\n\nexport type JourneyDevtoolsProtocolVersion =\n | typeof JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION\n | typeof JOURNEY_DEVTOOLS_PROTOCOL_VERSION;\n\nexport type JourneyDevtoolsSource =\n | typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE\n | typeof JOURNEY_DEVTOOLS_EXTENSION_SOURCE;\n\nexport type JourneyDevtoolsStepAsyncState = JourneyStepAsyncState;\n\nexport type JourneyDevtoolsSerializableSnapshot = JourneySnapshot<JourneyJsonObject, string>;\nexport type JourneyDevtoolsSerializableObservationEvent = JourneyObservationEvent<\n string,\n Record<never, never>\n>;\nexport type JourneyDevtoolsSerializableExecutionPathsResult = JourneyExecutionPathsResult<\n string,\n string\n>;\n\nexport type JourneyDevtoolsMachineCapabilities = {\n commands: JourneyDevtoolsCommand[\"type\"][];\n observe: boolean;\n executionPaths: boolean;\n persistence?: {\n key: string | null;\n clearOnReset: boolean | null;\n };\n};\n\nexport type JourneyDevtoolsMachineMeta = {\n machineId: string;\n label: string;\n appName: string | null;\n commandsEnabled?: boolean;\n capabilities?: JourneyDevtoolsMachineCapabilities;\n};\n\nexport type JourneyDevtoolsSerializedError = {\n name: string | null;\n message: string;\n stack: string | null;\n cause: unknown;\n};\n\nexport type JourneyDevtoolsCommand =\n | { type: \"startJourney\" }\n | { type: \"goToNextStep\" }\n | { type: \"terminateJourney\" }\n | { type: \"completeJourney\" }\n | { type: \"goToStepById\"; stepId: string }\n | { type: \"goToPreviousStep\"; steps?: number }\n | { type: \"goToLastVisitedStep\" }\n | { type: \"send\"; event: { type: string; payload?: unknown } }\n | { type: \"resetJourney\" }\n | { type: \"clearStepError\"; stepId?: string }\n | { type: \"getExecutionPaths\"; options?: JourneyExecutionPathOptions };\n\nexport type JourneyDevtoolsEnvelopeBase = {\n channel: typeof JOURNEY_DEVTOOLS_CHANNEL;\n version: JourneyDevtoolsProtocolVersion;\n source: JourneyDevtoolsSource;\n kind: string;\n machineId: string;\n timestamp: number;\n};\n\nexport type JourneyDevtoolsBridgeRegisterEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"register\";\n meta: JourneyDevtoolsMachineMeta;\n snapshot: JourneyDevtoolsSerializableSnapshot;\n};\n\nexport type JourneyDevtoolsBridgeUnregisterEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"unregister\";\n};\n\nexport type JourneyDevtoolsBridgeSnapshotEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"snapshot\";\n snapshot: JourneyDevtoolsSerializableSnapshot;\n};\n\nexport type JourneyDevtoolsBridgeObservationEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"observation\";\n event: JourneyDevtoolsSerializableObservationEvent;\n};\n\nexport type JourneyDevtoolsBridgeCommandResultEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"commandResult\";\n requestId: string;\n snapshot: JourneyDevtoolsSerializableSnapshot;\n transitioned?: boolean;\n transitionId?: string;\n error?: JourneyDevtoolsSerializedError;\n};\n\nexport type JourneyDevtoolsBridgeExecutionPathsResultEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"executionPathsResult\";\n requestId: string;\n result: JourneyDevtoolsSerializableExecutionPathsResult;\n};\n\nexport type JourneyDevtoolsBridgeCommandErrorEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;\n kind: \"commandError\";\n requestId: string;\n error: JourneyDevtoolsSerializedError;\n};\n\nexport type JourneyDevtoolsExtensionCommandEnvelope = JourneyDevtoolsEnvelopeBase & {\n source: typeof JOURNEY_DEVTOOLS_EXTENSION_SOURCE;\n kind: \"command\";\n requestId: string;\n command: JourneyDevtoolsCommand;\n};\n\nexport type JourneyDevtoolsBridgeEnvelope =\n | JourneyDevtoolsBridgeRegisterEnvelope\n | JourneyDevtoolsBridgeUnregisterEnvelope\n | JourneyDevtoolsBridgeSnapshotEnvelope\n | JourneyDevtoolsBridgeObservationEnvelope\n | JourneyDevtoolsBridgeCommandResultEnvelope\n | JourneyDevtoolsBridgeExecutionPathsResultEnvelope\n | JourneyDevtoolsBridgeCommandErrorEnvelope;\n\nexport type JourneyDevtoolsExtensionEnvelope = JourneyDevtoolsExtensionCommandEnvelope;\n\nexport type JourneyDevtoolsEnvelope =\n | JourneyDevtoolsBridgeEnvelope\n | JourneyDevtoolsExtensionEnvelope;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nconst isKnownSource = (value: unknown): value is JourneyDevtoolsSource =>\n value === JOURNEY_DEVTOOLS_BRIDGE_SOURCE || value === JOURNEY_DEVTOOLS_EXTENSION_SOURCE;\n\nconst isSupportedProtocolVersion = (value: unknown): value is JourneyDevtoolsProtocolVersion =>\n value === JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION || value === JOURNEY_DEVTOOLS_PROTOCOL_VERSION;\n\nconst JOURNEY_COMMAND_TYPES = [\n \"startJourney\",\n \"goToNextStep\",\n \"terminateJourney\",\n \"completeJourney\",\n \"goToStepById\",\n \"goToPreviousStep\",\n \"goToLastVisitedStep\",\n \"send\",\n \"resetJourney\",\n \"clearStepError\",\n \"getExecutionPaths\"\n] as const;\n\nconst isKnownCommandType = (value: unknown): value is JourneyDevtoolsCommand[\"type\"] =>\n typeof value === \"string\" && (JOURNEY_COMMAND_TYPES as readonly string[]).includes(value);\n\n/**\n * Maximum depth for nested object validation.\n * Prevents stack overflow and excessive processing from deeply nested malicious payloads.\n */\nconst MAX_PAYLOAD_DEPTH = 10;\n\n/**\n * Maximum size (in JSON string length) for serialized payloads.\n * Prevents memory exhaustion from extremely large payloads.\n */\nconst MAX_PAYLOAD_SIZE = 500_000; // 500KB\n\n/**\n * Validates that a value is safe for transport.\n * Checks size via a single serialization pass, then validates\n * depth, types, and prototype safety via a structure walk.\n */\nconst isSafePayload = (value: unknown): boolean => {\n try {\n const serialized = JSON.stringify(value);\n if (serialized !== undefined && serialized.length > MAX_PAYLOAD_SIZE) {\n return false;\n }\n } catch {\n return false;\n }\n\n return isStructureSafe(value, 0);\n};\n\nconst isStructureSafe = (value: unknown, depth: number): boolean => {\n if (depth > MAX_PAYLOAD_DEPTH) {\n return false;\n }\n\n if (value === null || value === undefined) {\n return true;\n }\n\n if (typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\") {\n return true;\n }\n\n if (typeof value !== \"object\") {\n return false;\n }\n\n if (Array.isArray(value)) {\n return value.every((item) => isStructureSafe(item, depth + 1));\n }\n\n if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {\n return false;\n }\n\n return Object.values(value).every((prop) => isStructureSafe(prop, depth + 1));\n};\n\nconst hasBaseEnvelopeShape = (value: unknown): value is JourneyDevtoolsEnvelopeBase => {\n if (!isRecord(value)) {\n return false;\n }\n\n return (\n value.channel === JOURNEY_DEVTOOLS_CHANNEL &&\n isSupportedProtocolVersion(value.version) &&\n isKnownSource(value.source) &&\n typeof value.kind === \"string\" &&\n typeof value.machineId === \"string\" &&\n typeof value.timestamp === \"number\"\n );\n};\n\nconst isPositiveInteger = (value: unknown, max = 10000): value is number =>\n typeof value === \"number\" && Number.isInteger(value) && value >= 1 && value <= max;\n\nconst isExecutionPathOptionsShape = (value: unknown): value is JourneyExecutionPathOptions => {\n if (!isRecord(value)) {\n return false;\n }\n\n return (\n Object.keys(value).length <= 2 &&\n (value.maxDepth === undefined || isPositiveInteger(value.maxDepth)) &&\n (value.maxPaths === undefined || isPositiveInteger(value.maxPaths))\n );\n};\n\nconst isSendEvent = (value: unknown): value is { type: string; payload?: unknown } => {\n if (!isRecord(value)) {\n return false;\n }\n\n if (typeof value.type !== \"string\" || value.type.length === 0 || value.type.length > 100) {\n return false;\n }\n\n if (\"payload\" in value && value.payload !== undefined) {\n return isSafePayload(value.payload);\n }\n\n return true;\n};\n\nconst isMachineCapabilities = (value: unknown): value is JourneyDevtoolsMachineCapabilities => {\n if (\n !isRecord(value) ||\n typeof value.observe !== \"boolean\" ||\n typeof value.executionPaths !== \"boolean\"\n ) {\n return false;\n }\n\n if (\n !Array.isArray(value.commands) ||\n !value.commands.every((command) => isKnownCommandType(command))\n ) {\n return false;\n }\n\n if (value.persistence === undefined) {\n return true;\n }\n\n if (!isRecord(value.persistence)) {\n return false;\n }\n\n return (\n (value.persistence.key === null || typeof value.persistence.key === \"string\") &&\n (value.persistence.clearOnReset === null || typeof value.persistence.clearOnReset === \"boolean\")\n );\n};\n\nconst isMachineMeta = (\n value: unknown,\n version: JourneyDevtoolsProtocolVersion\n): value is JourneyDevtoolsMachineMeta => {\n if (!isRecord(value)) {\n return false;\n }\n\n return (\n typeof value.machineId === \"string\" &&\n typeof value.label === \"string\" &&\n (value.appName === null || typeof value.appName === \"string\") &&\n (value.commandsEnabled === undefined || typeof value.commandsEnabled === \"boolean\") &&\n (version === JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION\n ? value.capabilities === undefined || isMachineCapabilities(value.capabilities)\n : isMachineCapabilities(value.capabilities))\n );\n};\n\nconst isSerializableObservationEvent = (\n value: unknown\n): value is JourneyDevtoolsSerializableObservationEvent => {\n if (!isRecord(value)) {\n return false;\n }\n\n return (\n typeof value.type === \"string\" &&\n value.type.length > 0 &&\n value.type.length <= 100 &&\n typeof value.timestamp === \"number\" &&\n isSafePayload(value)\n );\n};\n\nconst isExecutionPathResult = (\n value: unknown\n): value is JourneyDevtoolsSerializableExecutionPathsResult => {\n if (!isRecord(value) || !Array.isArray(value.paths)) {\n return false;\n }\n\n const isPathTerminated = (terminated: unknown): terminated is string =>\n terminated === \"final\" ||\n terminated === \"depth\" ||\n terminated === \"cycle\" ||\n terminated === \"limit\";\n\n return (\n value.paths.every(\n (path) =>\n isRecord(path) &&\n Array.isArray(path.steps) &&\n path.steps.every((step) => typeof step === \"string\") &&\n Array.isArray(path.events) &&\n path.events.every((event) => typeof event === \"string\") &&\n isPathTerminated(path.terminated)\n ) &&\n typeof value.truncated === \"boolean\" &&\n typeof value.cyclesDetected === \"boolean\"\n );\n};\n\n/**\n * Validates whether an unknown value is a supported devtools command payload.\n */\nexport const isJourneyDevtoolsCommand = (value: unknown): value is JourneyDevtoolsCommand => {\n if (!isRecord(value) || typeof value.type !== \"string\") {\n return false;\n }\n\n if (value.type.length === 0 || value.type.length > 50) {\n return false;\n }\n\n switch (value.type) {\n case \"startJourney\":\n case \"goToNextStep\":\n case \"terminateJourney\":\n case \"completeJourney\":\n case \"resetJourney\":\n case \"goToLastVisitedStep\":\n return Object.keys(value).length === 1;\n case \"goToStepById\":\n return (\n typeof value.stepId === \"string\" &&\n value.stepId.length > 0 &&\n value.stepId.length <= 100 &&\n Object.keys(value).length === 2\n );\n case \"goToPreviousStep\":\n return (\n (value.steps === undefined || isPositiveInteger(value.steps)) &&\n Object.keys(value).length <= 2\n );\n case \"send\":\n return isSendEvent(value.event) && Object.keys(value).length === 2;\n case \"clearStepError\":\n return (\n (value.stepId === undefined ||\n (typeof value.stepId === \"string\" && value.stepId.length <= 100)) &&\n Object.keys(value).length <= 2\n );\n case \"getExecutionPaths\":\n return (\n (value.options === undefined || isExecutionPathOptionsShape(value.options)) &&\n Object.keys(value).length <= 2\n );\n default:\n return false;\n }\n};\n\n/**\n * Validates whether an unknown value is a bridge-origin envelope.\n */\nexport const isJourneyDevtoolsBridgeEnvelope = (\n value: unknown\n): value is JourneyDevtoolsBridgeEnvelope => {\n if (!hasBaseEnvelopeShape(value) || value.source !== JOURNEY_DEVTOOLS_BRIDGE_SOURCE) {\n return false;\n }\n\n const envelope = value as Record<string, unknown>;\n\n switch (value.kind) {\n case \"register\":\n return (\n isMachineMeta(envelope.meta, value.version) &&\n isRecord(envelope.snapshot) &&\n isSafePayload(envelope.snapshot)\n );\n case \"unregister\":\n return true;\n case \"snapshot\":\n return isRecord(envelope.snapshot) && isSafePayload(envelope.snapshot);\n case \"observation\":\n return isSerializableObservationEvent(envelope.event);\n case \"commandResult\":\n return (\n typeof envelope.requestId === \"string\" &&\n envelope.requestId.length > 0 &&\n envelope.requestId.length <= 100 &&\n isRecord(envelope.snapshot) &&\n isSafePayload(envelope.snapshot) &&\n (!(\"error\" in envelope) || isRecord(envelope.error))\n );\n case \"executionPathsResult\":\n return (\n typeof envelope.requestId === \"string\" &&\n envelope.requestId.length > 0 &&\n envelope.requestId.length <= 100 &&\n isExecutionPathResult(envelope.result)\n );\n case \"commandError\":\n return (\n typeof envelope.requestId === \"string\" &&\n envelope.requestId.length > 0 &&\n envelope.requestId.length <= 100 &&\n isRecord(envelope.error)\n );\n default:\n return false;\n }\n};\n\n/**\n * Validates whether an unknown value is an extension-origin command envelope.\n */\nexport const isJourneyDevtoolsExtensionEnvelope = (\n value: unknown\n): value is JourneyDevtoolsExtensionEnvelope => {\n if (!hasBaseEnvelopeShape(value) || value.source !== JOURNEY_DEVTOOLS_EXTENSION_SOURCE) {\n return false;\n }\n\n if (value.kind !== \"command\") {\n return false;\n }\n\n const envelope = value as Record<string, unknown>;\n return (\n typeof envelope.requestId === \"string\" &&\n envelope.requestId.length > 0 &&\n envelope.requestId.length <= 100 &&\n isJourneyDevtoolsCommand(envelope.command)\n );\n};\n\n/**\n * Validates whether an unknown value matches either supported devtools envelope shape.\n */\nexport const isJourneyDevtoolsEnvelope = (value: unknown): value is JourneyDevtoolsEnvelope =>\n isJourneyDevtoolsBridgeEnvelope(value) || isJourneyDevtoolsExtensionEnvelope(value);\n", "import type {\n JourneyExecutionPathOptions,\n JourneyExecutionPathsResult,\n JourneyJsonObject,\n JourneyMachine,\n JourneyObservationEvent,\n JourneySendResult,\n JourneySnapshot\n} from \"@rxova/journey-core\";\nimport {\n JOURNEY_DEVTOOLS_BRIDGE_SOURCE,\n JOURNEY_DEVTOOLS_CHANNEL,\n JOURNEY_DEVTOOLS_EXTENSION_SOURCE,\n JOURNEY_DEVTOOLS_PROTOCOL_VERSION,\n isJourneyDevtoolsEnvelope,\n type JourneyDevtoolsBridgeCommandErrorEnvelope,\n type JourneyDevtoolsBridgeCommandResultEnvelope,\n type JourneyDevtoolsBridgeEnvelope,\n type JourneyDevtoolsBridgeExecutionPathsResultEnvelope,\n type JourneyDevtoolsBridgeObservationEnvelope,\n type JourneyDevtoolsBridgeRegisterEnvelope,\n type JourneyDevtoolsBridgeSnapshotEnvelope,\n type JourneyDevtoolsBridgeUnregisterEnvelope,\n type JourneyDevtoolsCommand,\n type JourneyDevtoolsExtensionCommandEnvelope,\n type JourneyDevtoolsMachineMeta,\n type JourneyDevtoolsSerializableExecutionPathsResult,\n type JourneyDevtoolsSerializableObservationEvent,\n type JourneyDevtoolsSerializableSnapshot,\n type JourneyDevtoolsSerializedError\n} from \"./protocol\";\n\ndeclare const process: { env?: { NODE_ENV?: string } } | undefined;\n\ntype JourneyDevtoolsPersistencePluginMetadata = {\n key?: string;\n clearOnReset?: boolean;\n};\n\nexport type JourneyDevtoolsBridgeOptions = {\n machineId?: string;\n label?: string;\n enabled?: boolean;\n appName?: string;\n commandsEnabled?: boolean;\n pluginMetadata?: {\n persistence?: JourneyDevtoolsPersistencePluginMetadata;\n };\n};\n\ntype SnapshotCommandOutcome<TContext extends JourneyJsonObject, TStepId extends string> = {\n kind: \"snapshot\";\n snapshot: JourneySnapshot<TContext, TStepId>;\n transitioned?: boolean;\n transitionId?: string;\n error?: JourneyDevtoolsSerializedError;\n};\n\ntype ExecutionPathsCommandOutcome<TStepId extends string, TEventType extends string> = {\n kind: \"executionPaths\";\n result: JourneyExecutionPathsResult<TStepId, TEventType>;\n};\n\ntype CommandOutcome<\n TContext extends JourneyJsonObject,\n TStepId extends string,\n TEventType extends string\n> = SnapshotCommandOutcome<TContext, TStepId> | ExecutionPathsCommandOutcome<TStepId, TEventType>;\n\ntype SnapshotScheduleKind = \"raf\" | \"timeout\";\n\ntype JourneyImportMetaEnv = {\n DEV?: unknown;\n PROD?: unknown;\n};\n\ntype ExecutionPathsJourneyMachine<\n TContext extends JourneyJsonObject,\n TStepId extends string,\n TEventMap extends Record<string, unknown>,\n TStepMeta,\n THandlers extends Record<string, unknown>\n> = JourneyMachine<TContext, TStepId, TEventMap, TStepMeta, THandlers> & {\n getExecutionPaths: (\n options?: JourneyExecutionPathOptions\n ) => JourneyExecutionPathsResult<TStepId, string>;\n};\n\nconst DEFAULT_MACHINE_LABEL = \"Journey Machine\";\nconst MUTATING_COMMAND_TYPES = [\n \"startJourney\",\n \"goToNextStep\",\n \"terminateJourney\",\n \"completeJourney\",\n \"goToStepById\",\n \"goToPreviousStep\",\n \"goToLastVisitedStep\",\n \"send\",\n \"resetJourney\",\n \"clearStepError\"\n] as const satisfies readonly Exclude<JourneyDevtoolsCommand[\"type\"], \"getExecutionPaths\">[];\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nconst isJourneyAsyncPhase = (\n value: unknown\n): value is JourneyDevtoolsSerializableSnapshot[\"async\"][\"byStep\"][string][\"phase\"] =>\n value === \"idle\" || value === \"evaluating-when\" || value === \"error\";\n\nconst resolveImportMetaEnvironment = (\n bundlerEnv: JourneyImportMetaEnv | null | undefined\n): boolean | null => {\n if (!isRecord(bundlerEnv)) {\n return null;\n }\n\n if (bundlerEnv.PROD === true) {\n return false;\n }\n\n if (bundlerEnv.DEV === true) {\n return true;\n }\n\n return null;\n};\n\nconst resolveNodeEnvironment = (nodeEnv: string | undefined): boolean | null => {\n if (typeof nodeEnv !== \"string\") {\n return null;\n }\n\n return nodeEnv !== \"production\";\n};\n\nexport const resolveNonProductionEnvironment = (\n options: {\n bundlerEnv?: JourneyImportMetaEnv | null | undefined;\n nodeEnv?: string | undefined;\n } = {}\n): boolean => {\n const resolvedBundlerEnv =\n \"bundlerEnv\" in options\n ? options.bundlerEnv\n : (import.meta as ImportMeta & { env?: JourneyImportMetaEnv }).env;\n const resolvedNodeEnv =\n \"nodeEnv\" in options\n ? options.nodeEnv\n : typeof process !== \"undefined\"\n ? process.env?.NODE_ENV\n : undefined;\n\n return (\n resolveImportMetaEnvironment(resolvedBundlerEnv) ??\n resolveNodeEnvironment(resolvedNodeEnv) ??\n false\n );\n};\n\nconst resolveWindowTargetOrigin = (): string => {\n if (typeof window === \"undefined\") {\n return \"*\";\n }\n\n return window.location.origin === \"null\" ? \"*\" : window.location.origin;\n};\n\nconst isExpectedWindowOrigin = (origin: string): boolean => {\n if (origin.length === 0) {\n return false;\n }\n\n if (typeof window === \"undefined\") {\n return false;\n }\n\n const expected = window.location.origin;\n if (expected === \"null\") {\n return origin === \"null\";\n }\n\n return origin === expected;\n};\n\nconst createJourneyMachineId = (): string =>\n `journey-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;\n\nclass CommandRateLimiter {\n private commandTimestamps: number[] = [];\n private readonly maxCommandsPerWindow: number;\n private readonly windowMs: number;\n\n constructor(maxCommandsPerWindow = 100, windowMs = 10000) {\n this.maxCommandsPerWindow = maxCommandsPerWindow;\n this.windowMs = windowMs;\n }\n\n isAllowed(): boolean {\n const now = Date.now();\n const windowStart = now - this.windowMs;\n\n this.commandTimestamps = this.commandTimestamps.filter((timestamp) => timestamp > windowStart);\n\n if (this.commandTimestamps.length >= this.maxCommandsPerWindow) {\n return false;\n }\n\n this.commandTimestamps.push(now);\n return true;\n }\n\n reset(): void {\n this.commandTimestamps = [];\n }\n}\n\nconst cloneForTransport = (value: unknown): unknown => {\n const transportValue =\n typeof structuredClone === \"function\"\n ? (() => {\n try {\n return structuredClone(value);\n } catch {\n return value;\n }\n })()\n : value;\n const seen = new WeakSet<object>();\n\n try {\n const serialized = JSON.stringify(transportValue, (_key, currentValue) => {\n if (typeof currentValue === \"bigint\") {\n return currentValue.toString();\n }\n if (typeof currentValue === \"function\") {\n return `[Function ${currentValue.name || \"anonymous\"}]`;\n }\n if (typeof currentValue === \"symbol\") {\n return currentValue.toString();\n }\n if (typeof currentValue === \"object\" && currentValue !== null) {\n if (seen.has(currentValue)) {\n return \"[Circular]\";\n }\n seen.add(currentValue);\n }\n return currentValue;\n });\n\n if (serialized === undefined) {\n return undefined;\n }\n\n return JSON.parse(serialized) as unknown;\n } catch {\n return String(value);\n }\n};\n\nconst serializeError = (error: unknown): JourneyDevtoolsSerializedError => {\n if (error instanceof Error) {\n const cause =\n \"cause\" in error && (error as { cause?: unknown }).cause !== undefined\n ? (error as { cause?: unknown }).cause\n : null;\n return {\n name: error.name,\n message: error.message,\n stack: typeof error.stack === \"string\" ? error.stack : null,\n cause: cloneForTransport(cause)\n };\n }\n\n return {\n name: null,\n message: typeof error === \"string\" ? error : \"Unknown error\",\n stack: null,\n cause: cloneForTransport(error)\n };\n};\n\nconst serializeSnapshot = <TContext extends JourneyJsonObject, TStepId extends string>(\n snapshot: JourneySnapshot<TContext, TStepId>\n): JourneyDevtoolsSerializableSnapshot => {\n const byStep: Record<string, JourneyDevtoolsSerializableSnapshot[\"async\"][\"byStep\"][string]> = {};\n\n for (const [stepId, stepState] of Object.entries(\n snapshot.async.byStep as Record<string, unknown>\n )) {\n if (!isRecord(stepState)) {\n continue;\n }\n\n byStep[stepId] = {\n phase: isJourneyAsyncPhase(stepState.phase) ? stepState.phase : \"idle\",\n eventType: typeof stepState.eventType === \"string\" ? stepState.eventType : null,\n transitionId: typeof stepState.transitionId === \"string\" ? stepState.transitionId : null,\n error: stepState.error === null ? null : cloneForTransport(stepState.error)\n };\n }\n\n return {\n currentStepId: String(snapshot.currentStepId),\n context: cloneForTransport(snapshot.context) as JourneyJsonObject,\n history: {\n timeline: snapshot.history.timeline.map((stepId) => String(stepId)),\n index: snapshot.history.index\n },\n visited: Object.fromEntries(\n Object.entries(snapshot.visited as Record<string, boolean>).map(([stepId, isVisited]) => [\n String(stepId),\n isVisited === true\n ])\n ),\n status: snapshot.status,\n async: {\n isLoading: snapshot.async.isLoading,\n byStep\n }\n };\n};\n\nconst serializeObservationEvent = <\n TStepId extends string,\n TEventMap extends Record<string, unknown>\n>(\n event: JourneyObservationEvent<TStepId, TEventMap>\n): JourneyDevtoolsSerializableObservationEvent => {\n if (event.type === \"transition.error\") {\n return cloneForTransport({\n ...event,\n error: serializeError(event.error)\n }) as JourneyDevtoolsSerializableObservationEvent;\n }\n return cloneForTransport(event) as JourneyDevtoolsSerializableObservationEvent;\n};\n\nconst serializeExecutionPathsResult = <TStepId extends string, TEventType extends string>(\n result: JourneyExecutionPathsResult<TStepId, TEventType>\n): JourneyDevtoolsSerializableExecutionPathsResult =>\n cloneForTransport(result) as JourneyDevtoolsSerializableExecutionPathsResult;\n\nconst isKnownStepId = <TContext extends JourneyJsonObject, TStepId extends string>(\n snapshot: JourneySnapshot<TContext, TStepId>,\n stepId: string\n): stepId is TStepId => stepId in (snapshot.async.byStep as Record<string, unknown>);\n\nconst assertKnownStepId = <TContext extends JourneyJsonObject, TStepId extends string>(\n machine: { getSnapshot: () => JourneySnapshot<TContext, TStepId> },\n stepId: string,\n commandType: JourneyDevtoolsCommand[\"type\"]\n): TStepId => {\n if (!isKnownStepId(machine.getSnapshot(), stepId)) {\n throw new Error(`Unknown stepId \"${stepId}\" for \"${commandType}\" command.`);\n }\n return stepId;\n};\n\nconst toSnapshotCommandOutcome = <TContext extends JourneyJsonObject, TStepId extends string>(\n result: JourneySendResult<TContext, TStepId>\n): SnapshotCommandOutcome<TContext, TStepId> => ({\n kind: \"snapshot\",\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {}),\n ...(\"error\" in result ? { error: serializeError(result.error) } : {})\n});\n\nconst hasExecutionPathsSupport = <\n TContext extends JourneyJsonObject,\n TStepId extends string,\n TEventMap extends Record<string, unknown>,\n TStepMeta,\n THandlers extends Record<string, unknown>\n>(\n machine: JourneyMachine<TContext, TStepId, TEventMap, TStepMeta, THandlers>\n): machine is ExecutionPathsJourneyMachine<TContext, TStepId, TEventMap, TStepMeta, THandlers> =>\n typeof (machine as Record<string, unknown>).getExecutionPaths === \"function\";\n\nconst isReadOnlyCommand = (command: JourneyDevtoolsCommand): boolean =>\n command.type === \"getExecutionPaths\";\n\nconst createCapabilities = <\n TContext extends JourneyJsonObject,\n TStepId extends string,\n TEventMap extends Record<string, unknown>,\n TStepMeta,\n THandlers extends Record<string, unknown>\n>(\n machine: JourneyMachine<TContext, TStepId, TEventMap, TStepMeta, THandlers>,\n options: JourneyDevtoolsBridgeOptions,\n commandsEnabled: boolean\n) => {\n const executionPaths = hasExecutionPathsSupport(machine);\n const commands: JourneyDevtoolsCommand[\"type\"][] = [];\n\n if (commandsEnabled) {\n commands.push(...MUTATING_COMMAND_TYPES);\n }\n\n if (executionPaths) {\n commands.push(\"getExecutionPaths\");\n }\n\n return {\n commands,\n observe: true as const,\n executionPaths,\n ...(options.pluginMetadata?.persistence\n ? {\n persistence: {\n key: options.pluginMetadata.persistence.key?.trim() || null,\n clearOnReset:\n typeof options.pluginMetadata.persistence.clearOnReset === \"boolean\"\n ? options.pluginMetadata.persistence.clearOnReset\n : null\n }\n }\n : {})\n };\n};\n\nconst runCommand = async <\n TContext extends JourneyJsonObject,\n TStepId extends string,\n TStepMeta,\n THandlers extends Record<string, unknown>\n>(\n machine: JourneyMachine<TContext, TStepId, Record<never, never>, TStepMeta, THandlers>,\n command: JourneyDevtoolsCommand\n): Promise<CommandOutcome<TContext, TStepId, string>> => {\n switch (command.type) {\n case \"startJourney\":\n return {\n kind: \"snapshot\",\n snapshot: await machine.startJourney()\n };\n case \"goToNextStep\":\n case \"completeJourney\": {\n const result = await machine.send({ type: command.type });\n return toSnapshotCommandOutcome(result);\n }\n case \"terminateJourney\": {\n const result = await machine.send({ type: \"terminateJourney\" });\n return toSnapshotCommandOutcome(result);\n }\n case \"goToStepById\": {\n const stepId = assertKnownStepId(machine, command.stepId, command.type);\n const result = await machine.send({\n type: \"goToStepById\",\n stepId\n });\n return toSnapshotCommandOutcome(result);\n }\n case \"goToPreviousStep\": {\n const result = await machine.goToPreviousStep(command.steps);\n return toSnapshotCommandOutcome(result);\n }\n case \"goToLastVisitedStep\": {\n const result = await machine.goToLastVisitedStep();\n return toSnapshotCommandOutcome(result);\n }\n case \"send\": {\n const sendEvent =\n command.event.payload === undefined\n ? { type: command.event.type }\n : { type: command.event.type, payload: command.event.payload };\n const result: JourneySendResult<TContext, TStepId> = await machine.send(\n sendEvent as Parameters<typeof machine.send>[0]\n );\n return toSnapshotCommandOutcome(result);\n }\n case \"resetJourney\":\n return {\n kind: \"snapshot\",\n snapshot: await machine.resetJourney()\n };\n case \"clearStepError\": {\n const stepId =\n command.stepId === undefined\n ? undefined\n : assertKnownStepId(machine, command.stepId, command.type);\n return {\n kind: \"snapshot\",\n snapshot: await machine.clearStepError(stepId)\n };\n }\n case \"getExecutionPaths\": {\n if (!hasExecutionPathsSupport(machine)) {\n throw new Error('Machine does not support \"getExecutionPaths\".');\n }\n\n return {\n kind: \"executionPaths\",\n result: machine.getExecutionPaths(command.options)\n };\n }\n }\n};\n\n/**\n * Attaches a journey machine to the browser devtools transport and returns\n * a detach function that unsubscribes listeners and unregisters the machine.\n */\nexport const attachJourneyDevtools = <\n TContext extends JourneyJsonObject,\n TStepId extends string,\n TEventMap extends Record<string, unknown> = Record<never, never>,\n TStepMeta = unknown,\n THandlers extends Record<string, unknown> = Record<never, never>\n>(\n machine: JourneyMachine<TContext, TStepId, TEventMap, TStepMeta, THandlers>,\n options: JourneyDevtoolsBridgeOptions = {}\n): (() => void) => {\n const enabled = options.enabled ?? resolveNonProductionEnvironment();\n if (!enabled || typeof window === \"undefined\") {\n return () => {};\n }\n\n const commandsEnabled = options.commandsEnabled ?? resolveNonProductionEnvironment();\n const machineId = options.machineId?.trim() || createJourneyMachineId();\n const targetOrigin = resolveWindowTargetOrigin();\n const capabilities = createCapabilities(machine, options, commandsEnabled);\n\n const meta: JourneyDevtoolsMachineMeta = {\n machineId,\n label: options.label?.trim() || DEFAULT_MACHINE_LABEL,\n appName:\n options.appName?.trim() || (typeof document !== \"undefined\" ? document.title : \"\") || null,\n commandsEnabled,\n capabilities\n };\n\n const createBaseEnvelope = <TKind extends JourneyDevtoolsBridgeEnvelope[\"kind\"]>(\n kind: TKind\n ) => ({\n channel: JOURNEY_DEVTOOLS_CHANNEL,\n version: JOURNEY_DEVTOOLS_PROTOCOL_VERSION,\n source: JOURNEY_DEVTOOLS_BRIDGE_SOURCE,\n kind,\n machineId,\n timestamp: Date.now()\n });\n\n const post = (envelope: JourneyDevtoolsBridgeEnvelope) => {\n try {\n window.postMessage(envelope, targetOrigin);\n } catch {\n // Swallow transport failures so bridge lifecycle and commands remain non-throwing.\n }\n };\n\n const postSnapshot = (snapshot: JourneySnapshot<TContext, TStepId>) => {\n const envelope: JourneyDevtoolsBridgeSnapshotEnvelope = {\n ...createBaseEnvelope(\"snapshot\"),\n snapshot: serializeSnapshot(snapshot)\n };\n post(envelope);\n };\n\n const postObservation = (event: JourneyObservationEvent<TStepId, TEventMap>) => {\n const envelope: JourneyDevtoolsBridgeObservationEnvelope = {\n ...createBaseEnvelope(\"observation\"),\n event: serializeObservationEvent(event)\n };\n post(envelope);\n };\n\n const postExecutionPathsResult = (\n requestId: string,\n result: JourneyExecutionPathsResult<TStepId, string>\n ) => {\n const envelope: JourneyDevtoolsBridgeExecutionPathsResultEnvelope = {\n ...createBaseEnvelope(\"executionPathsResult\"),\n requestId,\n result: serializeExecutionPathsResult(result)\n };\n post(envelope);\n };\n\n let isDetached = false;\n const rateLimiter = new CommandRateLimiter();\n let pendingSnapshot: JourneySnapshot<TContext, TStepId> | null = null;\n let scheduledSnapshotHandle: number | ReturnType<typeof globalThis.setTimeout> | null = null;\n let scheduledSnapshotKind: SnapshotScheduleKind | null = null;\n\n const clearScheduledSnapshotState = () => {\n pendingSnapshot = null;\n scheduledSnapshotHandle = null;\n scheduledSnapshotKind = null;\n };\n\n const flushScheduledSnapshot = () => {\n const snapshot = pendingSnapshot;\n clearScheduledSnapshotState();\n\n if (!snapshot || isDetached) {\n return;\n }\n\n postSnapshot(snapshot);\n };\n\n const scheduleSnapshotPost = (snapshot: JourneySnapshot<TContext, TStepId>) => {\n pendingSnapshot = snapshot;\n if (scheduledSnapshotHandle !== null) {\n return;\n }\n\n if (typeof window.requestAnimationFrame === \"function\") {\n scheduledSnapshotKind = \"raf\";\n scheduledSnapshotHandle = window.requestAnimationFrame(() => {\n flushScheduledSnapshot();\n });\n return;\n }\n\n scheduledSnapshotKind = \"timeout\";\n scheduledSnapshotHandle = globalThis.setTimeout(() => {\n flushScheduledSnapshot();\n }, 0);\n };\n\n const cancelScheduledSnapshot = () => {\n if (scheduledSnapshotHandle === null) {\n clearScheduledSnapshotState();\n return;\n }\n\n if (scheduledSnapshotKind === \"raf\" && typeof window.cancelAnimationFrame === \"function\") {\n window.cancelAnimationFrame(scheduledSnapshotHandle as number);\n } else {\n globalThis.clearTimeout(scheduledSnapshotHandle);\n }\n\n clearScheduledSnapshotState();\n };\n\n const onMessage = (event: MessageEvent<unknown>) => {\n if (\n event.source !== window ||\n !isExpectedWindowOrigin(event.origin) ||\n isDetached ||\n !isJourneyDevtoolsEnvelope(event.data)\n ) {\n return;\n }\n\n if (event.data.source !== JOURNEY_DEVTOOLS_EXTENSION_SOURCE || event.data.kind !== \"command\") {\n return;\n }\n\n const commandEnvelope: JourneyDevtoolsExtensionCommandEnvelope = event.data;\n if (commandEnvelope.machineId !== machineId) {\n return;\n }\n\n if (!rateLimiter.isAllowed()) {\n const errorEnvelope: JourneyDevtoolsBridgeCommandErrorEnvelope = {\n ...createBaseEnvelope(\"commandError\"),\n requestId: commandEnvelope.requestId,\n error: serializeError(\n \"Command rate limit exceeded. Too many commands in a short time window.\"\n )\n };\n post(errorEnvelope);\n return;\n }\n\n if (!commandsEnabled && !isReadOnlyCommand(commandEnvelope.command)) {\n const errorEnvelope: JourneyDevtoolsBridgeCommandErrorEnvelope = {\n ...createBaseEnvelope(\"commandError\"),\n requestId: commandEnvelope.requestId,\n error: serializeError(\"Bridge commands are disabled by configuration.\")\n };\n post(errorEnvelope);\n return;\n }\n\n const run = async () => {\n try {\n const outcome = await runCommand(\n machine as unknown as JourneyMachine<\n TContext,\n TStepId,\n Record<never, never>,\n TStepMeta,\n THandlers\n >,\n commandEnvelope.command\n );\n\n if (isDetached) {\n return;\n }\n\n if (outcome.kind === \"executionPaths\") {\n postExecutionPathsResult(commandEnvelope.requestId, outcome.result);\n return;\n }\n\n const resultEnvelope: JourneyDevtoolsBridgeCommandResultEnvelope = {\n ...createBaseEnvelope(\"commandResult\"),\n requestId: commandEnvelope.requestId,\n snapshot: serializeSnapshot(outcome.snapshot),\n ...(outcome.transitioned !== undefined ? { transitioned: outcome.transitioned } : {}),\n ...(outcome.transitionId ? { transitionId: outcome.transitionId } : {}),\n ...(\"error\" in outcome ? { error: outcome.error } : {})\n };\n post(resultEnvelope);\n } catch (error) {\n if (isDetached) {\n return;\n }\n\n const errorEnvelope: JourneyDevtoolsBridgeCommandErrorEnvelope = {\n ...createBaseEnvelope(\"commandError\"),\n requestId: commandEnvelope.requestId,\n error: serializeError(error)\n };\n post(errorEnvelope);\n }\n };\n\n void run();\n };\n\n window.addEventListener(\"message\", onMessage);\n\n const unsubscribeSnapshot = machine.subscribe(() => {\n if (isDetached) {\n return;\n }\n\n scheduleSnapshotPost(machine.getSnapshot());\n });\n\n const registerEnvelope: JourneyDevtoolsBridgeRegisterEnvelope = {\n ...createBaseEnvelope(\"register\"),\n meta,\n snapshot: serializeSnapshot(machine.getSnapshot())\n };\n post(registerEnvelope);\n\n const unsubscribeObservation = machine.subscribeEvent((event) => {\n if (isDetached) {\n return;\n }\n\n postObservation(event);\n });\n\n return () => {\n if (isDetached) {\n return;\n }\n\n isDetached = true;\n rateLimiter.reset();\n unsubscribeObservation();\n unsubscribeSnapshot();\n window.removeEventListener(\"message\", onMessage);\n cancelScheduledSnapshot();\n\n const unregisterEnvelope: JourneyDevtoolsBridgeUnregisterEnvelope = {\n ...createBaseEnvelope(\"unregister\")\n };\n post(unregisterEnvelope);\n };\n};\n"],
5
+ "mappings": "AASO,IAAMA,EAAoC,EACpCC,GAA2C,EAC3CC,EAA2B,6BAE3BC,EAAiC,uBACjCC,EAAoC,0BA2I3CC,EAAYC,GAChB,OAAOA,GAAU,UAAYA,IAAU,KAEnCC,GAAiBD,GACrBA,IAAUH,GAAkCG,IAAUF,EAElDI,GAA8BF,GAClCA,IAAU,GAA4CA,IAAU,EAE5DG,GAAwB,CAC5B,eACA,eACA,mBACA,kBACA,eACA,mBACA,sBACA,OACA,eACA,iBACA,mBACF,EAEMC,GAAsBJ,GAC1B,OAAOA,GAAU,UAAaG,GAA4C,SAASH,CAAK,EAmB1F,IAAMK,EAAiBC,GAA4B,C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,CAAS,EAE5C,IAAMO,EAAsB3C,EAAQ,UAAU,IAAM,CAC9C2B,GAIJO,EAAqBlC,EAAQ,YAAY,CAAC,CAC5C,CAAC,EAEK4C,EAA0D,CAC9D,GAAG3B,EAAmB,UAAU,EAChC,KAAAD,EACA,SAAU5B,EAAkBY,EAAQ,YAAY,CAAC,CACnD,EACAqB,EAAKuB,CAAgB,EAErB,IAAMC,EAAyB7C,EAAQ,eAAgBL,GAAU,CAC3DgC,GAIJH,EAAgB7B,CAAK,CACvB,CAAC,EAED,MAAO,IAAM,CACX,GAAIgC,EACF,OAGFA,EAAa,GACbC,EAAY,MAAM,EAClBiB,EAAuB,EACvBF,EAAoB,EACpB,OAAO,oBAAoB,UAAWP,CAAS,EAC/CD,EAAwB,EAExB,IAAMW,EAA8D,CAClE,GAAG7B,EAAmB,YAAY,CACpC,EACAI,EAAKyB,CAAkB,CACzB,CACF",
6
+ "names": ["JOURNEY_DEVTOOLS_PROTOCOL_VERSION", "JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION", "JOURNEY_DEVTOOLS_CHANNEL", "JOURNEY_DEVTOOLS_BRIDGE_SOURCE", "JOURNEY_DEVTOOLS_EXTENSION_SOURCE", "isRecord", "value", "isKnownSource", "isSupportedProtocolVersion", "JOURNEY_COMMAND_TYPES", "isKnownCommandType", "isSafePayload", "value", "serialized", "isStructureSafe", "depth", "item", "prop", "hasBaseEnvelopeShape", "isRecord", "JOURNEY_DEVTOOLS_CHANNEL", "isSupportedProtocolVersion", "isKnownSource", "isPositiveInteger", "max", "isExecutionPathOptionsShape", "isSendEvent", "isMachineCapabilities", "command", "isKnownCommandType", "isMachineMeta", "version", "isSerializableObservationEvent", "isExecutionPathResult", "isPathTerminated", "terminated", "path", "step", "event", "isJourneyDevtoolsCommand", "isJourneyDevtoolsBridgeEnvelope", "JOURNEY_DEVTOOLS_BRIDGE_SOURCE", "envelope", "isJourneyDevtoolsExtensionEnvelope", "JOURNEY_DEVTOOLS_EXTENSION_SOURCE", "isJourneyDevtoolsEnvelope", "DEFAULT_MACHINE_LABEL", "MUTATING_COMMAND_TYPES", "isRecord", "value", "isJourneyAsyncPhase", "resolveImportMetaEnvironment", "bundlerEnv", "resolveNodeEnvironment", "nodeEnv", "resolveNonProductionEnvironment", "options", "resolvedBundlerEnv", "resolvedNodeEnv", "resolveWindowTargetOrigin", "isExpectedWindowOrigin", "origin", "expected", "createJourneyMachineId", "CommandRateLimiter", "maxCommandsPerWindow", "windowMs", "now", "windowStart", "timestamp", "cloneForTransport", "transportValue", "seen", "serialized", "_key", "currentValue", "serializeError", "error", "cause", "serializeSnapshot", "snapshot", "byStep", "stepId", "stepState", "isVisited", "serializeObservationEvent", "event", "serializeExecutionPathsResult", "result", "isKnownStepId", "assertKnownStepId", "machine", "commandType", "toSnapshotCommandOutcome", "hasExecutionPathsSupport", "isReadOnlyCommand", "command", "createCapabilities", "commandsEnabled", "executionPaths", "commands", "runCommand", "sendEvent", "attachJourneyDevtools", "machineId", "targetOrigin", "capabilities", "meta", "createBaseEnvelope", "kind", "JOURNEY_DEVTOOLS_CHANNEL", "JOURNEY_DEVTOOLS_BRIDGE_SOURCE", "post", "envelope", "postSnapshot", "postObservation", "postExecutionPathsResult", "requestId", "isDetached", "rateLimiter", "pendingSnapshot", "scheduledSnapshotHandle", "scheduledSnapshotKind", "clearScheduledSnapshotState", "flushScheduledSnapshot", "scheduleSnapshotPost", "cancelScheduledSnapshot", "onMessage", "isJourneyDevtoolsEnvelope", "JOURNEY_DEVTOOLS_EXTENSION_SOURCE", "commandEnvelope", "errorEnvelope", "outcome", "resultEnvelope", "unsubscribeSnapshot", "registerEnvelope", "unsubscribeObservation", "unregisterEnvelope"]
7
7
  }
@@ -0,0 +1,139 @@
1
+ import type { JourneyExecutionPathOptions, JourneyExecutionPathsResult, JourneyJsonObject, JourneyObservationEvent, JourneySnapshot, JourneyStepAsyncState } from "@rxova/journey-core";
2
+ export declare const JOURNEY_DEVTOOLS_PROTOCOL_VERSION: 4;
3
+ export declare const JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION: 3;
4
+ export declare const JOURNEY_DEVTOOLS_CHANNEL: "__RXOVA_JOURNEY_DEVTOOLS__";
5
+ export declare const JOURNEY_DEVTOOLS_BRIDGE_SOURCE: "rxova-journey-bridge";
6
+ export declare const JOURNEY_DEVTOOLS_EXTENSION_SOURCE: "rxova-journey-extension";
7
+ export type JourneyDevtoolsProtocolVersion = typeof JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION | typeof JOURNEY_DEVTOOLS_PROTOCOL_VERSION;
8
+ export type JourneyDevtoolsSource = typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE | typeof JOURNEY_DEVTOOLS_EXTENSION_SOURCE;
9
+ export type JourneyDevtoolsStepAsyncState = JourneyStepAsyncState;
10
+ export type JourneyDevtoolsSerializableSnapshot = JourneySnapshot<JourneyJsonObject, string>;
11
+ export type JourneyDevtoolsSerializableObservationEvent = JourneyObservationEvent<string, Record<never, never>>;
12
+ export type JourneyDevtoolsSerializableExecutionPathsResult = JourneyExecutionPathsResult<string, string>;
13
+ export type JourneyDevtoolsMachineCapabilities = {
14
+ commands: JourneyDevtoolsCommand["type"][];
15
+ observe: boolean;
16
+ executionPaths: boolean;
17
+ persistence?: {
18
+ key: string | null;
19
+ clearOnReset: boolean | null;
20
+ };
21
+ };
22
+ export type JourneyDevtoolsMachineMeta = {
23
+ machineId: string;
24
+ label: string;
25
+ appName: string | null;
26
+ commandsEnabled?: boolean;
27
+ capabilities?: JourneyDevtoolsMachineCapabilities;
28
+ };
29
+ export type JourneyDevtoolsSerializedError = {
30
+ name: string | null;
31
+ message: string;
32
+ stack: string | null;
33
+ cause: unknown;
34
+ };
35
+ export type JourneyDevtoolsCommand = {
36
+ type: "startJourney";
37
+ } | {
38
+ type: "goToNextStep";
39
+ } | {
40
+ type: "terminateJourney";
41
+ } | {
42
+ type: "completeJourney";
43
+ } | {
44
+ type: "goToStepById";
45
+ stepId: string;
46
+ } | {
47
+ type: "goToPreviousStep";
48
+ steps?: number;
49
+ } | {
50
+ type: "goToLastVisitedStep";
51
+ } | {
52
+ type: "send";
53
+ event: {
54
+ type: string;
55
+ payload?: unknown;
56
+ };
57
+ } | {
58
+ type: "resetJourney";
59
+ } | {
60
+ type: "clearStepError";
61
+ stepId?: string;
62
+ } | {
63
+ type: "getExecutionPaths";
64
+ options?: JourneyExecutionPathOptions;
65
+ };
66
+ export type JourneyDevtoolsEnvelopeBase = {
67
+ channel: typeof JOURNEY_DEVTOOLS_CHANNEL;
68
+ version: JourneyDevtoolsProtocolVersion;
69
+ source: JourneyDevtoolsSource;
70
+ kind: string;
71
+ machineId: string;
72
+ timestamp: number;
73
+ };
74
+ export type JourneyDevtoolsBridgeRegisterEnvelope = JourneyDevtoolsEnvelopeBase & {
75
+ source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;
76
+ kind: "register";
77
+ meta: JourneyDevtoolsMachineMeta;
78
+ snapshot: JourneyDevtoolsSerializableSnapshot;
79
+ };
80
+ export type JourneyDevtoolsBridgeUnregisterEnvelope = JourneyDevtoolsEnvelopeBase & {
81
+ source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;
82
+ kind: "unregister";
83
+ };
84
+ export type JourneyDevtoolsBridgeSnapshotEnvelope = JourneyDevtoolsEnvelopeBase & {
85
+ source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;
86
+ kind: "snapshot";
87
+ snapshot: JourneyDevtoolsSerializableSnapshot;
88
+ };
89
+ export type JourneyDevtoolsBridgeObservationEnvelope = JourneyDevtoolsEnvelopeBase & {
90
+ source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;
91
+ kind: "observation";
92
+ event: JourneyDevtoolsSerializableObservationEvent;
93
+ };
94
+ export type JourneyDevtoolsBridgeCommandResultEnvelope = JourneyDevtoolsEnvelopeBase & {
95
+ source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;
96
+ kind: "commandResult";
97
+ requestId: string;
98
+ snapshot: JourneyDevtoolsSerializableSnapshot;
99
+ transitioned?: boolean;
100
+ transitionId?: string;
101
+ error?: JourneyDevtoolsSerializedError;
102
+ };
103
+ export type JourneyDevtoolsBridgeExecutionPathsResultEnvelope = JourneyDevtoolsEnvelopeBase & {
104
+ source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;
105
+ kind: "executionPathsResult";
106
+ requestId: string;
107
+ result: JourneyDevtoolsSerializableExecutionPathsResult;
108
+ };
109
+ export type JourneyDevtoolsBridgeCommandErrorEnvelope = JourneyDevtoolsEnvelopeBase & {
110
+ source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;
111
+ kind: "commandError";
112
+ requestId: string;
113
+ error: JourneyDevtoolsSerializedError;
114
+ };
115
+ export type JourneyDevtoolsExtensionCommandEnvelope = JourneyDevtoolsEnvelopeBase & {
116
+ source: typeof JOURNEY_DEVTOOLS_EXTENSION_SOURCE;
117
+ kind: "command";
118
+ requestId: string;
119
+ command: JourneyDevtoolsCommand;
120
+ };
121
+ export type JourneyDevtoolsBridgeEnvelope = JourneyDevtoolsBridgeRegisterEnvelope | JourneyDevtoolsBridgeUnregisterEnvelope | JourneyDevtoolsBridgeSnapshotEnvelope | JourneyDevtoolsBridgeObservationEnvelope | JourneyDevtoolsBridgeCommandResultEnvelope | JourneyDevtoolsBridgeExecutionPathsResultEnvelope | JourneyDevtoolsBridgeCommandErrorEnvelope;
122
+ export type JourneyDevtoolsExtensionEnvelope = JourneyDevtoolsExtensionCommandEnvelope;
123
+ export type JourneyDevtoolsEnvelope = JourneyDevtoolsBridgeEnvelope | JourneyDevtoolsExtensionEnvelope;
124
+ /**
125
+ * Validates whether an unknown value is a supported devtools command payload.
126
+ */
127
+ export declare const isJourneyDevtoolsCommand: (value: unknown) => value is JourneyDevtoolsCommand;
128
+ /**
129
+ * Validates whether an unknown value is a bridge-origin envelope.
130
+ */
131
+ export declare const isJourneyDevtoolsBridgeEnvelope: (value: unknown) => value is JourneyDevtoolsBridgeEnvelope;
132
+ /**
133
+ * Validates whether an unknown value is an extension-origin command envelope.
134
+ */
135
+ export declare const isJourneyDevtoolsExtensionEnvelope: (value: unknown) => value is JourneyDevtoolsExtensionEnvelope;
136
+ /**
137
+ * Validates whether an unknown value matches either supported devtools envelope shape.
138
+ */
139
+ export declare const isJourneyDevtoolsEnvelope: (value: unknown) => value is JourneyDevtoolsEnvelope;
@@ -1,16 +1,30 @@
1
- import type { JourneySnapshot, JourneyStepAsyncState } from "@rxova/journey-core";
2
- export declare const JOURNEY_DEVTOOLS_PROTOCOL_VERSION: 3;
1
+ import type { JourneyExecutionPathOptions, JourneyExecutionPathsResult, JourneyJsonObject, JourneyObservationEvent, JourneySnapshot, JourneyStepAsyncState } from "@rxova/journey-core";
2
+ export declare const JOURNEY_DEVTOOLS_PROTOCOL_VERSION: 4;
3
+ export declare const JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION: 3;
3
4
  export declare const JOURNEY_DEVTOOLS_CHANNEL: "__RXOVA_JOURNEY_DEVTOOLS__";
4
5
  export declare const JOURNEY_DEVTOOLS_BRIDGE_SOURCE: "rxova-journey-bridge";
5
6
  export declare const JOURNEY_DEVTOOLS_EXTENSION_SOURCE: "rxova-journey-extension";
7
+ export type JourneyDevtoolsProtocolVersion = typeof JOURNEY_DEVTOOLS_LEGACY_PROTOCOL_VERSION | typeof JOURNEY_DEVTOOLS_PROTOCOL_VERSION;
6
8
  export type JourneyDevtoolsSource = typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE | typeof JOURNEY_DEVTOOLS_EXTENSION_SOURCE;
7
9
  export type JourneyDevtoolsStepAsyncState = JourneyStepAsyncState;
8
- export type JourneyDevtoolsSerializableSnapshot = JourneySnapshot<unknown, string>;
10
+ export type JourneyDevtoolsSerializableSnapshot = JourneySnapshot<JourneyJsonObject, string>;
11
+ export type JourneyDevtoolsSerializableObservationEvent = JourneyObservationEvent<string, Record<never, never>>;
12
+ export type JourneyDevtoolsSerializableExecutionPathsResult = JourneyExecutionPathsResult<string, string>;
13
+ export type JourneyDevtoolsMachineCapabilities = {
14
+ commands: JourneyDevtoolsCommand["type"][];
15
+ observe: boolean;
16
+ executionPaths: boolean;
17
+ persistence?: {
18
+ key: string | null;
19
+ clearOnReset: boolean | null;
20
+ };
21
+ };
9
22
  export type JourneyDevtoolsMachineMeta = {
10
23
  machineId: string;
11
24
  label: string;
12
25
  appName: string | null;
13
26
  commandsEnabled?: boolean;
27
+ capabilities?: JourneyDevtoolsMachineCapabilities;
14
28
  };
15
29
  export type JourneyDevtoolsSerializedError = {
16
30
  name: string | null;
@@ -19,9 +33,11 @@ export type JourneyDevtoolsSerializedError = {
19
33
  cause: unknown;
20
34
  };
21
35
  export type JourneyDevtoolsCommand = {
36
+ type: "startJourney";
37
+ } | {
22
38
  type: "goToNextStep";
23
39
  } | {
24
- type: "terminateMachine";
40
+ type: "terminateJourney";
25
41
  } | {
26
42
  type: "completeJourney";
27
43
  } | {
@@ -39,18 +55,17 @@ export type JourneyDevtoolsCommand = {
39
55
  payload?: unknown;
40
56
  };
41
57
  } | {
42
- type: "updateStepMetadata";
43
- stepId: string;
44
- metadata: unknown;
45
- } | {
46
- type: "resetMachine";
58
+ type: "resetJourney";
47
59
  } | {
48
60
  type: "clearStepError";
49
61
  stepId?: string;
62
+ } | {
63
+ type: "getExecutionPaths";
64
+ options?: JourneyExecutionPathOptions;
50
65
  };
51
66
  export type JourneyDevtoolsEnvelopeBase = {
52
67
  channel: typeof JOURNEY_DEVTOOLS_CHANNEL;
53
- version: typeof JOURNEY_DEVTOOLS_PROTOCOL_VERSION;
68
+ version: JourneyDevtoolsProtocolVersion;
54
69
  source: JourneyDevtoolsSource;
55
70
  kind: string;
56
71
  machineId: string;
@@ -71,6 +86,11 @@ export type JourneyDevtoolsBridgeSnapshotEnvelope = JourneyDevtoolsEnvelopeBase
71
86
  kind: "snapshot";
72
87
  snapshot: JourneyDevtoolsSerializableSnapshot;
73
88
  };
89
+ export type JourneyDevtoolsBridgeObservationEnvelope = JourneyDevtoolsEnvelopeBase & {
90
+ source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;
91
+ kind: "observation";
92
+ event: JourneyDevtoolsSerializableObservationEvent;
93
+ };
74
94
  export type JourneyDevtoolsBridgeCommandResultEnvelope = JourneyDevtoolsEnvelopeBase & {
75
95
  source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;
76
96
  kind: "commandResult";
@@ -80,6 +100,12 @@ export type JourneyDevtoolsBridgeCommandResultEnvelope = JourneyDevtoolsEnvelope
80
100
  transitionId?: string;
81
101
  error?: JourneyDevtoolsSerializedError;
82
102
  };
103
+ export type JourneyDevtoolsBridgeExecutionPathsResultEnvelope = JourneyDevtoolsEnvelopeBase & {
104
+ source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;
105
+ kind: "executionPathsResult";
106
+ requestId: string;
107
+ result: JourneyDevtoolsSerializableExecutionPathsResult;
108
+ };
83
109
  export type JourneyDevtoolsBridgeCommandErrorEnvelope = JourneyDevtoolsEnvelopeBase & {
84
110
  source: typeof JOURNEY_DEVTOOLS_BRIDGE_SOURCE;
85
111
  kind: "commandError";
@@ -92,7 +118,7 @@ export type JourneyDevtoolsExtensionCommandEnvelope = JourneyDevtoolsEnvelopeBas
92
118
  requestId: string;
93
119
  command: JourneyDevtoolsCommand;
94
120
  };
95
- export type JourneyDevtoolsBridgeEnvelope = JourneyDevtoolsBridgeRegisterEnvelope | JourneyDevtoolsBridgeUnregisterEnvelope | JourneyDevtoolsBridgeSnapshotEnvelope | JourneyDevtoolsBridgeCommandResultEnvelope | JourneyDevtoolsBridgeCommandErrorEnvelope;
121
+ export type JourneyDevtoolsBridgeEnvelope = JourneyDevtoolsBridgeRegisterEnvelope | JourneyDevtoolsBridgeUnregisterEnvelope | JourneyDevtoolsBridgeSnapshotEnvelope | JourneyDevtoolsBridgeObservationEnvelope | JourneyDevtoolsBridgeCommandResultEnvelope | JourneyDevtoolsBridgeExecutionPathsResultEnvelope | JourneyDevtoolsBridgeCommandErrorEnvelope;
96
122
  export type JourneyDevtoolsExtensionEnvelope = JourneyDevtoolsExtensionCommandEnvelope;
97
123
  export type JourneyDevtoolsEnvelope = JourneyDevtoolsBridgeEnvelope | JourneyDevtoolsExtensionEnvelope;
98
124
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxova/journey-devtools-bridge",
3
- "version": "0.7.0",
3
+ "version": "1.0.0-rc.2",
4
4
  "description": "Bridge API to connect Journey machines to browser devtools.",
5
5
  "keywords": [
6
6
  "journey",
@@ -44,15 +44,20 @@
44
44
  "LICENSE"
45
45
  ],
46
46
  "sideEffects": false,
47
- "dependencies": {
48
- "@rxova/journey-core": "^0.7.0"
47
+ "peerDependencies": {
48
+ "@rxova/journey-core": "^1.0.0-rc.2"
49
+ },
50
+ "peerDependenciesMeta": {
51
+ "@rxova/journey-core": {
52
+ "optional": false
53
+ }
49
54
  },
50
55
  "size-limit": [
51
56
  {
52
57
  "name": "devtools-bridge/attachJourneyDevtools",
53
58
  "path": "dist/index.js",
54
59
  "import": "{ attachJourneyDevtools }",
55
- "limit": "3 kB"
60
+ "limit": "3.5 kB"
56
61
  }
57
62
  ],
58
63
  "scripts": {