@rxova/journey-devtools-bridge 0.6.2 → 0.6.4
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/dist/bridge.d.ts +4 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +2 -2
- package/dist/protocol.d.ts +12 -0
- package/package.json +2 -2
package/dist/bridge.d.ts
CHANGED
|
@@ -6,4 +6,8 @@ export type JourneyDevtoolsBridgeOptions = {
|
|
|
6
6
|
appName?: string;
|
|
7
7
|
commandsEnabled?: boolean;
|
|
8
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Attaches a journey machine to the browser devtools transport and returns
|
|
11
|
+
* a detach function that unsubscribes listeners and unregisters the machine.
|
|
12
|
+
*/
|
|
9
13
|
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);
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var J=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var P=(e,t)=>{for(var n in t)J(e,n,{get:t[n],enumerable:!0})},V=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of A(t))!Y.call(e,r)&&r!==n&&J(e,r,{get:()=>t[r],enumerable:!(o=U(t,r))||o.enumerable});return e};var j=e=>V(J({},"__esModule",{value:!0}),e);var te={};P(te,{JOURNEY_DEVTOOLS_BRIDGE_SOURCE:()=>c,JOURNEY_DEVTOOLS_CHANNEL:()=>g,JOURNEY_DEVTOOLS_EXTENSION_SOURCE:()=>E,JOURNEY_DEVTOOLS_PROTOCOL_VERSION:()=>m,attachJourneyDevtools:()=>C,isJourneyDevtoolsBridgeEnvelope:()=>O,isJourneyDevtoolsCommand:()=>D,isJourneyDevtoolsEnvelope:()=>v,isJourneyDevtoolsExtensionEnvelope:()=>T});module.exports=j(te);var m=3,g="__RXOVA_JOURNEY_DEVTOOLS__",c="rxova-journey-bridge",E="rxova-journey-extension",p=e=>typeof e=="object"&&e!==null,q=e=>e===c||e===E;var d=(e,t=0)=>{if(t>10)return!1;if(e==null||["string","number","boolean"].includes(typeof e))return!0;if(typeof e=="object"){try{if(JSON.stringify(e).length>5e5)return!1}catch{return!1}return Array.isArray(e)?e.every(o=>d(o,t+1)):Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null?!1:Object.values(e).every(o=>d(o,t+1))}return!1},b=e=>p(e)?e.channel===g&&e.version===3&&q(e.source)&&typeof e.kind=="string"&&typeof e.machineId=="string"&&typeof e.timestamp=="number":!1,z=e=>!p(e)||typeof e.type!="string"||e.type.length===0||e.type.length>100?!1:"payload"in e&&e.payload!==void 0?d(e.payload):!0,D=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 z(e.event)&&Object.keys(e).length===2;case"updateStepMetadata":return typeof e.stepId=="string"&&e.stepId.length>0&&e.stepId.length<=100&&d(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}},O=e=>{if(!b(e)||e.source!==c)return!1;let t=e;switch(e.kind){case"register":return p(t.meta)&&p(t.snapshot)&&d(t.meta)&&d(t.snapshot);case"unregister":return!0;case"snapshot":return p(t.snapshot)&&d(t.snapshot);case"commandResult":return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&p(t.snapshot)&&d(t.snapshot);case"commandError":return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&p(t.error);default:return!1}},T=e=>{if(!b(e)||e.source!==E||e.kind!=="command")return!1;let t=e;return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&D(t.command)},v=e=>O(e)||T(e);var X="Journey Machine",G=e=>typeof e=="object"&&e!==null,H=e=>e==="idle"||e==="evaluating-when"||e==="running-effect"||e==="error",W=()=>{let e=typeof process<"u"?process.env?.NODE_ENV:void 0;return typeof e!="string"?!1:e!=="production"},K=()=>{let e=typeof process<"u"?process.env?.NODE_ENV:void 0;return typeof e!="string"?!1:e!=="production"},$=()=>typeof window>"u"||window.location.origin==="null"?"*":window.location.origin,F=e=>{if(e.length===0||typeof window>"u")return!1;let t=window.location.origin;return t==="null"?e==="null":e===t},Z=()=>`journey-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,_=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=[]}},S=e=>{if(typeof structuredClone=="function")try{return structuredClone(e)}catch{}let t=new WeakSet;try{let n=JSON.stringify(e,(o,r)=>{if(typeof r=="bigint")return r.toString();if(typeof r=="function")return`[Function ${r.name||"anonymous"}]`;if(typeof r=="symbol")return r.toString();if(typeof r=="object"&&r!==null){if(t.has(r))return"[Circular]";t.add(r)}return r});return n===void 0?void 0:JSON.parse(n)}catch{return String(e)}},
|
|
1
|
+
"use strict";var J=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var P=(e,t)=>{for(var n in t)J(e,n,{get:t[n],enumerable:!0})},V=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of A(t))!Y.call(e,r)&&r!==n&&J(e,r,{get:()=>t[r],enumerable:!(o=U(t,r))||o.enumerable});return e};var j=e=>V(J({},"__esModule",{value:!0}),e);var te={};P(te,{JOURNEY_DEVTOOLS_BRIDGE_SOURCE:()=>c,JOURNEY_DEVTOOLS_CHANNEL:()=>g,JOURNEY_DEVTOOLS_EXTENSION_SOURCE:()=>E,JOURNEY_DEVTOOLS_PROTOCOL_VERSION:()=>m,attachJourneyDevtools:()=>C,isJourneyDevtoolsBridgeEnvelope:()=>O,isJourneyDevtoolsCommand:()=>D,isJourneyDevtoolsEnvelope:()=>v,isJourneyDevtoolsExtensionEnvelope:()=>T});module.exports=j(te);var m=3,g="__RXOVA_JOURNEY_DEVTOOLS__",c="rxova-journey-bridge",E="rxova-journey-extension",p=e=>typeof e=="object"&&e!==null,q=e=>e===c||e===E;var d=(e,t=0)=>{if(t>10)return!1;if(e==null||["string","number","boolean"].includes(typeof e))return!0;if(typeof e=="object"){try{if(JSON.stringify(e).length>5e5)return!1}catch{return!1}return Array.isArray(e)?e.every(o=>d(o,t+1)):Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null?!1:Object.values(e).every(o=>d(o,t+1))}return!1},b=e=>p(e)?e.channel===g&&e.version===3&&q(e.source)&&typeof e.kind=="string"&&typeof e.machineId=="string"&&typeof e.timestamp=="number":!1,z=e=>!p(e)||typeof e.type!="string"||e.type.length===0||e.type.length>100?!1:"payload"in e&&e.payload!==void 0?d(e.payload):!0,D=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 z(e.event)&&Object.keys(e).length===2;case"updateStepMetadata":return typeof e.stepId=="string"&&e.stepId.length>0&&e.stepId.length<=100&&d(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}},O=e=>{if(!b(e)||e.source!==c)return!1;let t=e;switch(e.kind){case"register":return p(t.meta)&&p(t.snapshot)&&d(t.meta)&&d(t.snapshot);case"unregister":return!0;case"snapshot":return p(t.snapshot)&&d(t.snapshot);case"commandResult":return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&p(t.snapshot)&&d(t.snapshot);case"commandError":return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&p(t.error);default:return!1}},T=e=>{if(!b(e)||e.source!==E||e.kind!=="command")return!1;let t=e;return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&D(t.command)},v=e=>O(e)||T(e);var X="Journey Machine",G=e=>typeof e=="object"&&e!==null,H=e=>e==="idle"||e==="evaluating-when"||e==="running-effect"||e==="error",W=()=>{let e=typeof process<"u"?process.env?.NODE_ENV:void 0;return typeof e!="string"?!1:e!=="production"},K=()=>{let e=typeof process<"u"?process.env?.NODE_ENV:void 0;return typeof e!="string"?!1:e!=="production"},$=()=>typeof window>"u"||window.location.origin==="null"?"*":window.location.origin,F=e=>{if(e.length===0||typeof window>"u")return!1;let t=window.location.origin;return t==="null"?e==="null":e===t},Z=()=>`journey-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,_=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=[]}},S=e=>{if(typeof structuredClone=="function")try{return structuredClone(e)}catch{}let t=new WeakSet;try{let n=JSON.stringify(e,(o,r)=>{if(typeof r=="bigint")return r.toString();if(typeof r=="function")return`[Function ${r.name||"anonymous"}]`;if(typeof r=="symbol")return r.toString();if(typeof r=="object"&&r!==null){if(t.has(r))return"[Circular]";t.add(r)}return r});return n===void 0?void 0:JSON.parse(n)}catch{return String(e)}},h=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:S(t)}}return{name:null,message:typeof e=="string"?e:"Unknown error",stack:null,cause:S(e)}},I=e=>{let t={};for(let[n,o]of Object.entries(e.async.byStep))G(o)&&(t[n]={phase:H(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:S(o.error)});return{currentStepId:String(e.currentStepId),context:S(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:S(e.stepMeta),status:e.status,async:{isLoading:e.async.isLoading,byStep:t}}},Q=(e,t)=>t in e.stepMeta,w=(e,t,n)=>{if(!Q(e.getSnapshot(),t))throw new Error(`Unknown stepId "${t}" for "${n}" command.`);return t},ee=async(e,t)=>{switch(t.type){case"goToNextStep":case"completeJourney":{let n=await e.send({type:t.type});return{snapshot:n.snapshot,transitioned:n.transitioned,...n.transitionId?{transitionId:n.transitionId}:{}}}case"terminateMachine":{let n=await e.send({type:"terminateJourney"});return{snapshot:n.snapshot,transitioned:n.transitioned,...n.transitionId?{transitionId:n.transitionId}:{}}}case"goToStepById":{let n=w(e,t.stepId,t.type),o=await e.send({type:"goToStepById",stepId:n});return{snapshot:o.snapshot,transitioned:o.transitioned,...o.transitionId?{transitionId:o.transitionId}:{}}}case"goToPreviousStep":{let n=await e.goToPreviousStep(t.steps);return{snapshot:n.snapshot,transitioned:n.transitioned,...n.transitionId?{transitionId:n.transitionId}:{}}}case"goToLastVisitedStep":{let n=await e.goToLastVisitedStep();return{snapshot:n.snapshot,transitioned:n.transitioned,...n.transitionId?{transitionId:n.transitionId}:{}}}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{snapshot:o.snapshot,transitioned:o.transitioned,...o.transitionId?{transitionId:o.transitionId}:{}}}case"updateStepMetadata":{let n=w(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:w(e,t.stepId,t.type);return{snapshot:e.clearStepError(n)}}}},C=(e,t={})=>{if(!(t.enabled??W())||typeof window>"u")return()=>{};let o=t.commandsEnabled??K(),r=t.machineId?.trim()||Z(),N={machineId:r,label:t.label?.trim()||X,appName:t.appName?.trim()||(typeof document<"u"?document.title:"")||null,commandsEnabled:o},B=$(),u=s=>({channel:g,version:3,source:c,kind:s,machineId:r,timestamp:Date.now()}),l=s=>{try{window.postMessage(s,B)}catch{}},M=s=>{let a={...u("snapshot"),snapshot:I(s)};l(a)},y=!1,R=new _,x=s=>{if(s.source!==window||!F(s.origin)||y||!v(s.data)||s.data.source!==E||s.data.kind!=="command")return;let a=s.data;if(a.machineId!==r)return;if(!R.isAllowed()){let i={...u("commandError"),requestId:a.requestId,error:h("Command rate limit exceeded. Too many commands in a short time window.")};l(i);return}if(!o){let i={...u("commandError"),requestId:a.requestId,error:h("Bridge commands are disabled by configuration.")};l(i);return}(async()=>{try{let i=await ee(e,a.command);if(y)return;let f={...u("commandResult"),requestId:a.requestId,snapshot:I(i.snapshot),...i.transitioned!==void 0?{transitioned:i.transitioned}:{},...i.transitionId?{transitionId:i.transitionId}:{}};l(f)}catch(i){if(y)return;let f={...u("commandError"),requestId:a.requestId,error:h(i)};l(f)}})()};window.addEventListener("message",x);let k=e.subscribe(()=>{y||M(e.getSnapshot())}),L={...u("register"),meta:N,snapshot:I(e.getSnapshot())};return l(L),()=>{if(y)return;y=!0,R.reset(),k(),window.removeEventListener("message",x);let s={...u("unregister")};l(s)}};0&&(module.exports={JOURNEY_DEVTOOLS_BRIDGE_SOURCE,JOURNEY_DEVTOOLS_CHANNEL,JOURNEY_DEVTOOLS_EXTENSION_SOURCE,JOURNEY_DEVTOOLS_PROTOCOL_VERSION,attachJourneyDevtools,isJourneyDevtoolsBridgeEnvelope,isJourneyDevtoolsCommand,isJourneyDevtoolsEnvelope,isJourneyDevtoolsExtensionEnvelope});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -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};\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 depth and size constraints to prevent malicious payloads.\n */\nconst isSafePayload = (value: unknown, depth = 0): boolean => {\n if (depth > MAX_PAYLOAD_DEPTH) {\n return false;\n }\n\n if (value === null || value === undefined) {\n return true;\n }\n\n const primitiveTypes = [\"string\", \"number\", \"boolean\"];\n if (primitiveTypes.includes(typeof value)) {\n return true;\n }\n\n if (typeof value === \"object\") {\n // Check JSON serialization size\n try {\n const serialized = JSON.stringify(value);\n if (serialized.length > MAX_PAYLOAD_SIZE) {\n return false;\n }\n } catch {\n // Circular references or non-serializable objects are not safe\n return false;\n }\n\n // Recursively validate nested objects and arrays\n if (Array.isArray(value)) {\n return value.every((item) => isSafePayload(item, depth + 1));\n }\n\n // Validate plain objects (guard against prototype pollution)\n if (\n Object.getPrototypeOf(value) !== Object.prototype &&\n Object.getPrototypeOf(value) !== null\n ) {\n return false;\n }\n\n return Object.values(value).every((prop) => isSafePayload(prop, depth + 1));\n }\n\n // Reject functions, symbols, and other non-serializable types\n return false;\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\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\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 );\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\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\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};\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\nconst resolveDefaultEnabled = (): boolean => {\n const nodeEnv = typeof process !== \"undefined\" ? process.env?.NODE_ENV : undefined;\n if (typeof nodeEnv !== \"string\") {\n return false;\n }\n\n return nodeEnv !== \"production\";\n};\n\nconst resolveDefaultCommandsEnabled = (): boolean => {\n const nodeEnv = typeof process !== \"undefined\" ? process.env?.NODE_ENV : undefined;\n if (typeof nodeEnv !== \"string\") {\n return false;\n }\n\n return nodeEnv !== \"production\";\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 if (typeof structuredClone === \"function\") {\n try {\n return structuredClone(value);\n } catch {\n // Fall through to the JSON serializer below.\n }\n }\n\n const seen = new WeakSet<object>();\n\n try {\n const serialized = JSON.stringify(value, (_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 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 {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\n }\n case \"terminateMachine\": {\n const result = await machine.send({ type: \"terminateJourney\" });\n return {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\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 {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\n }\n case \"goToPreviousStep\": {\n const result = await machine.goToPreviousStep(command.steps);\n return {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\n }\n case \"goToLastVisitedStep\": {\n const result = await machine.goToLastVisitedStep();\n return {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\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 {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\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\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 ?? resolveDefaultEnabled();\n if (!enabled || typeof window === \"undefined\") {\n return () => {};\n }\n const commandsEnabled = options.commandsEnabled ?? resolveDefaultCommandsEnabled();\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 window.postMessage(envelope, targetOrigin);\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\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 };\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 postSnapshot(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\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,EAAA,8BAAAC,EAAA,uCAAAC,IAAA,eAAAC,EAAAX,ICEO,IAAMY,EAAoC,EACpCC,EAA2B,6BAE3BC,EAAiC,uBACjCC,EAAoC,0BAmG3CC,EAAYC,GAChB,OAAOA,GAAU,UAAYA,IAAU,KAEnCC,EAAiBD,GACrBA,IAAUH,GAAkCG,IAAUF,EAkBxD,IAAMI,EAAgB,CAACC,EAAgBC,EAAQ,IAAe,CAC5D,GAAIA,EAAQ,GACV,MAAO,GAQT,GALID,GAAU,MAIS,CAAC,SAAU,SAAU,SAAS,EAClC,SAAS,OAAOA,CAAK,EACtC,MAAO,GAGT,GAAI,OAAOA,GAAU,SAAU,CAE7B,GAAI,CAEF,GADmB,KAAK,UAAUA,CAAK,EACxB,OAAS,IACtB,MAAO,EAEX,MAAQ,CAEN,MAAO,EACT,CAGA,OAAI,MAAM,QAAQA,CAAK,EACdA,EAAM,MAAOE,GAASH,EAAcG,EAAMD,EAAQ,CAAC,CAAC,EAK3D,OAAO,eAAeD,CAAK,IAAM,OAAO,WACxC,OAAO,eAAeA,CAAK,IAAM,KAE1B,GAGF,OAAO,OAAOA,CAAK,EAAE,MAAOG,GAASJ,EAAcI,EAAMF,EAAQ,CAAC,CAAC,CAC5E,CAGA,MAAO,EACT,EAEMG,EAAwBJ,GACvBK,EAASL,CAAK,EAKjBA,EAAM,UAAYM,GAClBN,EAAM,UAAY,GAClBO,EAAcP,EAAM,MAAM,GAC1B,OAAOA,EAAM,MAAS,UACtB,OAAOA,EAAM,WAAc,UAC3B,OAAOA,EAAM,WAAc,SATpB,GAaLQ,EAAeR,GACf,CAACK,EAASL,CAAK,GAIf,OAAOA,EAAM,MAAS,UAAYA,EAAM,KAAK,SAAW,GAAKA,EAAM,KAAK,OAAS,IAC5E,GAIL,YAAaA,GAASA,EAAM,UAAY,OACnCD,EAAcC,EAAM,OAAO,EAG7B,
|
|
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};\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 depth and size constraints to prevent malicious payloads.\n */\nconst isSafePayload = (value: unknown, depth = 0): boolean => {\n if (depth > MAX_PAYLOAD_DEPTH) {\n return false;\n }\n\n if (value === null || value === undefined) {\n return true;\n }\n\n const primitiveTypes = [\"string\", \"number\", \"boolean\"];\n if (primitiveTypes.includes(typeof value)) {\n return true;\n }\n\n if (typeof value === \"object\") {\n // Check JSON serialization size\n try {\n const serialized = JSON.stringify(value);\n if (serialized.length > MAX_PAYLOAD_SIZE) {\n return false;\n }\n } catch {\n // Circular references or non-serializable objects are not safe\n return false;\n }\n\n // Recursively validate nested objects and arrays\n if (Array.isArray(value)) {\n return value.every((item) => isSafePayload(item, depth + 1));\n }\n\n // Validate plain objects (guard against prototype pollution)\n if (\n Object.getPrototypeOf(value) !== Object.prototype &&\n Object.getPrototypeOf(value) !== null\n ) {\n return false;\n }\n\n return Object.values(value).every((prop) => isSafePayload(prop, depth + 1));\n }\n\n // Reject functions, symbols, and other non-serializable types\n return false;\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 );\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};\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\nconst resolveDefaultEnabled = (): boolean => {\n const nodeEnv = typeof process !== \"undefined\" ? process.env?.NODE_ENV : undefined;\n if (typeof nodeEnv !== \"string\") {\n return false;\n }\n\n return nodeEnv !== \"production\";\n};\n\nconst resolveDefaultCommandsEnabled = (): boolean => {\n const nodeEnv = typeof process !== \"undefined\" ? process.env?.NODE_ENV : undefined;\n if (typeof nodeEnv !== \"string\") {\n return false;\n }\n\n return nodeEnv !== \"production\";\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 if (typeof structuredClone === \"function\") {\n try {\n return structuredClone(value);\n } catch {\n // Fall through to the JSON serializer below.\n }\n }\n\n const seen = new WeakSet<object>();\n\n try {\n const serialized = JSON.stringify(value, (_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 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 {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\n }\n case \"terminateMachine\": {\n const result = await machine.send({ type: \"terminateJourney\" });\n return {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\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 {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\n }\n case \"goToPreviousStep\": {\n const result = await machine.goToPreviousStep(command.steps);\n return {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\n }\n case \"goToLastVisitedStep\": {\n const result = await machine.goToLastVisitedStep();\n return {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\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 {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\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 ?? resolveDefaultEnabled();\n if (!enabled || typeof window === \"undefined\") {\n return () => {};\n }\n const commandsEnabled = options.commandsEnabled ?? resolveDefaultCommandsEnabled();\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\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 };\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 postSnapshot(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\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,EAAA,8BAAAC,EAAA,uCAAAC,IAAA,eAAAC,EAAAX,ICEO,IAAMY,EAAoC,EACpCC,EAA2B,6BAE3BC,EAAiC,uBACj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EAA2D,CAC/D,GAAGd,EAAmB,cAAc,EACpC,UAAWa,EAAgB,UAC3B,MAAOpC,EAAeC,CAAK,CAC7B,EACA0B,EAAKU,CAAa,CACpB,CACF,GAES,CACX,EAEA,OAAO,iBAAiB,UAAWL,CAAS,EAE5C,IAAMQ,EAAc7B,EAAQ,UAAU,IAAM,CACtCmB,GAGJD,EAAalB,EAAQ,YAAY,CAAC,CACpC,CAAC,EAEK8B,EAA0D,CAC9D,GAAGlB,EAAmB,UAAU,EAChC,KAAAF,EACA,SAAUlB,EAAkBQ,EAAQ,YAAY,CAAC,CACnD,EACA,OAAAgB,EAAKc,CAAgB,EAEd,IAAM,CACX,GAAIX,EACF,OAGFA,EAAa,GACbC,EAAY,MAAM,EAClBS,EAAY,EACZ,OAAO,oBAAoB,UAAWR,CAAS,EAE/C,IAAMU,EAA8D,CAClE,GAAGnB,EAAmB,YAAY,CACpC,EACAI,EAAKe,CAAkB,CACzB,CACF",
|
|
6
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", "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", "resolveDefaultEnabled", "nodeEnv", "resolveDefaultCommandsEnabled", "resolveWindowTargetOrigin", "isExpectedWindowOrigin", "origin", "expected", "createMachineId", "CommandRateLimiter", "maxCommandsPerWindow", "windowMs", "now", "windowStart", "ts", "cloneForTransport", "seen", "serialized", "_key", "currentValue", "serializeError", "error", "cause", "serializeSnapshot", "snapshot", "byStep", "stepId", "stepState", "isVisited", "isKnownStepId", "assertKnownStepId", "machine", "commandType", "runCommand", "command", "result", "sendEvent", "attachJourneyDevtools", "options", "commandsEnabled", "machineId", "meta", "targetOrigin", "createBaseEnvelope", "kind", "JOURNEY_DEVTOOLS_CHANNEL", "JOURNEY_DEVTOOLS_BRIDGE_SOURCE", "post", "envelope", "postSnapshot", "isDetached", "rateLimiter", "onMessage", "event", "isJourneyDevtoolsEnvelope", "JOURNEY_DEVTOOLS_EXTENSION_SOURCE", "commandEnvelope", "errorEnvelope", "outcome", "resultEnvelope", "unsubscribe", "registerEnvelope", "unregisterEnvelope"]
|
|
7
7
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var v=3,S="__RXOVA_JOURNEY_DEVTOOLS__",c="rxova-journey-bridge",E="rxova-journey-extension",p=e=>typeof e=="object"&&e!==null,k=e=>e===c||e===E;var d=(e,t=0)=>{if(t>10)return!1;if(e==null||["string","number","boolean"].includes(typeof e))return!0;if(typeof e=="object"){try{if(JSON.stringify(e).length>5e5)return!1}catch{return!1}return Array.isArray(e)?e.every(o=>d(o,t+1)):Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null?!1:Object.values(e).every(o=>d(o,t+1))}return!1},w=e=>p(e)?e.channel===S&&e.version===3&&k(e.source)&&typeof e.kind=="string"&&typeof e.machineId=="string"&&typeof e.timestamp=="number":!1,L=e=>!p(e)||typeof e.type!="string"||e.type.length===0||e.type.length>100?!1:"payload"in e&&e.payload!==void 0?d(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 L(e.event)&&Object.keys(e).length===2;case"updateStepMetadata":return typeof e.stepId=="string"&&e.stepId.length>0&&e.stepId.length<=100&&d(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}},R=e=>{if(!w(e)||e.source!==c)return!1;let t=e;switch(e.kind){case"register":return p(t.meta)&&p(t.snapshot)&&d(t.meta)&&d(t.snapshot);case"unregister":return!0;case"snapshot":return p(t.snapshot)&&d(t.snapshot);case"commandResult":return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&p(t.snapshot)&&d(t.snapshot);case"commandError":return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&p(t.error);default:return!1}},x=e=>{if(!w(e)||e.source!==E||e.kind!=="command")return!1;let t=e;return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&_(t.command)},f=e=>R(e)||x(e);var U="Journey Machine",A=e=>typeof e=="object"&&e!==null,Y=e=>e==="idle"||e==="evaluating-when"||e==="running-effect"||e==="error",P=()=>{let e=typeof process<"u"?process.env?.NODE_ENV:void 0;return typeof e!="string"?!1:e!=="production"},V=()=>{let e=typeof process<"u"?process.env?.NODE_ENV:void 0;return typeof e!="string"?!1:e!=="production"},j=()=>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},z=()=>`journey-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,T=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=[]}},g=e=>{if(typeof structuredClone=="function")try{return structuredClone(e)}catch{}let t=new WeakSet;try{let n=JSON.stringify(e,(o,r)=>{if(typeof r=="bigint")return r.toString();if(typeof r=="function")return`[Function ${r.name||"anonymous"}]`;if(typeof r=="symbol")return r.toString();if(typeof r=="object"&&r!==null){if(t.has(r))return"[Circular]";t.add(r)}return r});return n===void 0?void 0:JSON.parse(n)}catch{return String(e)}},J=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:g(t)}}return{name:null,message:typeof e=="string"?e:"Unknown error",stack:null,cause:g(e)}},D=e=>{let t={};for(let[n,o]of Object.entries(e.async.byStep))A(o)&&(t[n]={phase:Y(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:g(o.error)});return{currentStepId:String(e.currentStepId),context:g(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:g(e.stepMeta),status:e.status,async:{isLoading:e.async.isLoading,byStep:t}}},X=(e,t)=>t in e.stepMeta,O=(e,t,n)=>{if(!X(e.getSnapshot(),t))throw new Error(`Unknown stepId "${t}" for "${n}" command.`);return t},G=async(e,t)=>{switch(t.type){case"goToNextStep":case"completeJourney":{let n=await e.send({type:t.type});return{snapshot:n.snapshot,transitioned:n.transitioned,...n.transitionId?{transitionId:n.transitionId}:{}}}case"terminateMachine":{let n=await e.send({type:"terminateJourney"});return{snapshot:n.snapshot,transitioned:n.transitioned,...n.transitionId?{transitionId:n.transitionId}:{}}}case"goToStepById":{let n=O(e,t.stepId,t.type),o=await e.send({type:"goToStepById",stepId:n});return{snapshot:o.snapshot,transitioned:o.transitioned,...o.transitionId?{transitionId:o.transitionId}:{}}}case"goToPreviousStep":{let n=await e.goToPreviousStep(t.steps);return{snapshot:n.snapshot,transitioned:n.transitioned,...n.transitionId?{transitionId:n.transitionId}:{}}}case"goToLastVisitedStep":{let n=await e.goToLastVisitedStep();return{snapshot:n.snapshot,transitioned:n.transitioned,...n.transitionId?{transitionId:n.transitionId}:{}}}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{snapshot:o.snapshot,transitioned:o.transitioned,...o.transitionId?{transitionId:o.transitionId}:{}}}case"updateStepMetadata":{let n=O(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:O(e,t.stepId,t.type);return{snapshot:e.clearStepError(n)}}}},H=(e,t={})=>{if(!(t.enabled??P())||typeof window>"u")return()=>{};let o=t.commandsEnabled??V(),r=t.machineId?.trim()||z(),b={machineId:r,label:t.label?.trim()||U,appName:t.appName?.trim()||(typeof document<"u"?document.title:"")||null,commandsEnabled:o},C=j(),u=s=>({channel:S,version:3,source:c,kind:s,machineId:r,timestamp:Date.now()}),l=s=>{window.postMessage(s,C)},N=s=>{let a={...u("snapshot"),snapshot:D(s)};l(a)},y=!1,
|
|
1
|
+
var v=3,S="__RXOVA_JOURNEY_DEVTOOLS__",c="rxova-journey-bridge",E="rxova-journey-extension",p=e=>typeof e=="object"&&e!==null,k=e=>e===c||e===E;var d=(e,t=0)=>{if(t>10)return!1;if(e==null||["string","number","boolean"].includes(typeof e))return!0;if(typeof e=="object"){try{if(JSON.stringify(e).length>5e5)return!1}catch{return!1}return Array.isArray(e)?e.every(o=>d(o,t+1)):Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null?!1:Object.values(e).every(o=>d(o,t+1))}return!1},w=e=>p(e)?e.channel===S&&e.version===3&&k(e.source)&&typeof e.kind=="string"&&typeof e.machineId=="string"&&typeof e.timestamp=="number":!1,L=e=>!p(e)||typeof e.type!="string"||e.type.length===0||e.type.length>100?!1:"payload"in e&&e.payload!==void 0?d(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 L(e.event)&&Object.keys(e).length===2;case"updateStepMetadata":return typeof e.stepId=="string"&&e.stepId.length>0&&e.stepId.length<=100&&d(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}},R=e=>{if(!w(e)||e.source!==c)return!1;let t=e;switch(e.kind){case"register":return p(t.meta)&&p(t.snapshot)&&d(t.meta)&&d(t.snapshot);case"unregister":return!0;case"snapshot":return p(t.snapshot)&&d(t.snapshot);case"commandResult":return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&p(t.snapshot)&&d(t.snapshot);case"commandError":return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&p(t.error);default:return!1}},x=e=>{if(!w(e)||e.source!==E||e.kind!=="command")return!1;let t=e;return typeof t.requestId=="string"&&t.requestId.length>0&&t.requestId.length<=100&&_(t.command)},f=e=>R(e)||x(e);var U="Journey Machine",A=e=>typeof e=="object"&&e!==null,Y=e=>e==="idle"||e==="evaluating-when"||e==="running-effect"||e==="error",P=()=>{let e=typeof process<"u"?process.env?.NODE_ENV:void 0;return typeof e!="string"?!1:e!=="production"},V=()=>{let e=typeof process<"u"?process.env?.NODE_ENV:void 0;return typeof e!="string"?!1:e!=="production"},j=()=>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},z=()=>`journey-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,T=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=[]}},g=e=>{if(typeof structuredClone=="function")try{return structuredClone(e)}catch{}let t=new WeakSet;try{let n=JSON.stringify(e,(o,r)=>{if(typeof r=="bigint")return r.toString();if(typeof r=="function")return`[Function ${r.name||"anonymous"}]`;if(typeof r=="symbol")return r.toString();if(typeof r=="object"&&r!==null){if(t.has(r))return"[Circular]";t.add(r)}return r});return n===void 0?void 0:JSON.parse(n)}catch{return String(e)}},J=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:g(t)}}return{name:null,message:typeof e=="string"?e:"Unknown error",stack:null,cause:g(e)}},D=e=>{let t={};for(let[n,o]of Object.entries(e.async.byStep))A(o)&&(t[n]={phase:Y(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:g(o.error)});return{currentStepId:String(e.currentStepId),context:g(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:g(e.stepMeta),status:e.status,async:{isLoading:e.async.isLoading,byStep:t}}},X=(e,t)=>t in e.stepMeta,O=(e,t,n)=>{if(!X(e.getSnapshot(),t))throw new Error(`Unknown stepId "${t}" for "${n}" command.`);return t},G=async(e,t)=>{switch(t.type){case"goToNextStep":case"completeJourney":{let n=await e.send({type:t.type});return{snapshot:n.snapshot,transitioned:n.transitioned,...n.transitionId?{transitionId:n.transitionId}:{}}}case"terminateMachine":{let n=await e.send({type:"terminateJourney"});return{snapshot:n.snapshot,transitioned:n.transitioned,...n.transitionId?{transitionId:n.transitionId}:{}}}case"goToStepById":{let n=O(e,t.stepId,t.type),o=await e.send({type:"goToStepById",stepId:n});return{snapshot:o.snapshot,transitioned:o.transitioned,...o.transitionId?{transitionId:o.transitionId}:{}}}case"goToPreviousStep":{let n=await e.goToPreviousStep(t.steps);return{snapshot:n.snapshot,transitioned:n.transitioned,...n.transitionId?{transitionId:n.transitionId}:{}}}case"goToLastVisitedStep":{let n=await e.goToLastVisitedStep();return{snapshot:n.snapshot,transitioned:n.transitioned,...n.transitionId?{transitionId:n.transitionId}:{}}}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{snapshot:o.snapshot,transitioned:o.transitioned,...o.transitionId?{transitionId:o.transitionId}:{}}}case"updateStepMetadata":{let n=O(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:O(e,t.stepId,t.type);return{snapshot:e.clearStepError(n)}}}},H=(e,t={})=>{if(!(t.enabled??P())||typeof window>"u")return()=>{};let o=t.commandsEnabled??V(),r=t.machineId?.trim()||z(),b={machineId:r,label:t.label?.trim()||U,appName:t.appName?.trim()||(typeof document<"u"?document.title:"")||null,commandsEnabled:o},C=j(),u=s=>({channel:S,version:3,source:c,kind:s,machineId:r,timestamp:Date.now()}),l=s=>{try{window.postMessage(s,C)}catch{}},N=s=>{let a={...u("snapshot"),snapshot:D(s)};l(a)},y=!1,h=new T,I=s=>{if(s.source!==window||!q(s.origin)||y||!f(s.data)||s.data.source!==E||s.data.kind!=="command")return;let a=s.data;if(a.machineId!==r)return;if(!h.isAllowed()){let i={...u("commandError"),requestId:a.requestId,error:J("Command rate limit exceeded. Too many commands in a short time window.")};l(i);return}if(!o){let i={...u("commandError"),requestId:a.requestId,error:J("Bridge commands are disabled by configuration.")};l(i);return}(async()=>{try{let i=await G(e,a.command);if(y)return;let m={...u("commandResult"),requestId:a.requestId,snapshot:D(i.snapshot),...i.transitioned!==void 0?{transitioned:i.transitioned}:{},...i.transitionId?{transitionId:i.transitionId}:{}};l(m)}catch(i){if(y)return;let m={...u("commandError"),requestId:a.requestId,error:J(i)};l(m)}})()};window.addEventListener("message",I);let B=e.subscribe(()=>{y||N(e.getSnapshot())}),M={...u("register"),meta:b,snapshot:D(e.getSnapshot())};return l(M),()=>{if(y)return;y=!0,h.reset(),B(),window.removeEventListener("message",I);let s={...u("unregister")};l(s)}};export{c as JOURNEY_DEVTOOLS_BRIDGE_SOURCE,S as JOURNEY_DEVTOOLS_CHANNEL,E as JOURNEY_DEVTOOLS_EXTENSION_SOURCE,v as JOURNEY_DEVTOOLS_PROTOCOL_VERSION,H as attachJourneyDevtools,R as isJourneyDevtoolsBridgeEnvelope,_ as isJourneyDevtoolsCommand,f as isJourneyDevtoolsEnvelope,x 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};\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 depth and size constraints to prevent malicious payloads.\n */\nconst isSafePayload = (value: unknown, depth = 0): boolean => {\n if (depth > MAX_PAYLOAD_DEPTH) {\n return false;\n }\n\n if (value === null || value === undefined) {\n return true;\n }\n\n const primitiveTypes = [\"string\", \"number\", \"boolean\"];\n if (primitiveTypes.includes(typeof value)) {\n return true;\n }\n\n if (typeof value === \"object\") {\n // Check JSON serialization size\n try {\n const serialized = JSON.stringify(value);\n if (serialized.length > MAX_PAYLOAD_SIZE) {\n return false;\n }\n } catch {\n // Circular references or non-serializable objects are not safe\n return false;\n }\n\n // Recursively validate nested objects and arrays\n if (Array.isArray(value)) {\n return value.every((item) => isSafePayload(item, depth + 1));\n }\n\n // Validate plain objects (guard against prototype pollution)\n if (\n Object.getPrototypeOf(value) !== Object.prototype &&\n Object.getPrototypeOf(value) !== null\n ) {\n return false;\n }\n\n return Object.values(value).every((prop) => isSafePayload(prop, depth + 1));\n }\n\n // Reject functions, symbols, and other non-serializable types\n return false;\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\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\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 );\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\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\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};\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\nconst resolveDefaultEnabled = (): boolean => {\n const nodeEnv = typeof process !== \"undefined\" ? process.env?.NODE_ENV : undefined;\n if (typeof nodeEnv !== \"string\") {\n return false;\n }\n\n return nodeEnv !== \"production\";\n};\n\nconst resolveDefaultCommandsEnabled = (): boolean => {\n const nodeEnv = typeof process !== \"undefined\" ? process.env?.NODE_ENV : undefined;\n if (typeof nodeEnv !== \"string\") {\n return false;\n }\n\n return nodeEnv !== \"production\";\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 if (typeof structuredClone === \"function\") {\n try {\n return structuredClone(value);\n } catch {\n // Fall through to the JSON serializer below.\n }\n }\n\n const seen = new WeakSet<object>();\n\n try {\n const serialized = JSON.stringify(value, (_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 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 {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\n }\n case \"terminateMachine\": {\n const result = await machine.send({ type: \"terminateJourney\" });\n return {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\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 {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\n }\n case \"goToPreviousStep\": {\n const result = await machine.goToPreviousStep(command.steps);\n return {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\n }\n case \"goToLastVisitedStep\": {\n const result = await machine.goToLastVisitedStep();\n return {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\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 {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\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\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 ?? resolveDefaultEnabled();\n if (!enabled || typeof window === \"undefined\") {\n return () => {};\n }\n const commandsEnabled = options.commandsEnabled ?? resolveDefaultCommandsEnabled();\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 window.postMessage(envelope, targetOrigin);\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\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 };\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 postSnapshot(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\n const unregisterEnvelope: JourneyDevtoolsBridgeUnregisterEnvelope = {\n ...createBaseEnvelope(\"unregister\")\n };\n post(unregisterEnvelope);\n };\n};\n"],
|
|
5
|
-
"mappings": "AAEO,IAAMA,EAAoC,EACpCC,EAA2B,6BAE3BC,EAAiC,uBACjCC,EAAoC,0BAmG3CC,EAAYC,GAChB,OAAOA,GAAU,UAAYA,IAAU,KAEnCC,EAAiBD,GACrBA,IAAUH,GAAkCG,IAAUF,EAkBxD,IAAMI,EAAgB,CAACC,EAAgBC,EAAQ,IAAe,CAC5D,GAAIA,EAAQ,GACV,MAAO,GAQT,GALID,GAAU,MAIS,CAAC,SAAU,SAAU,SAAS,EAClC,SAAS,OAAOA,CAAK,EACtC,MAAO,GAGT,GAAI,OAAOA,GAAU,SAAU,CAE7B,GAAI,CAEF,GADmB,KAAK,UAAUA,CAAK,EACxB,OAAS,IACtB,MAAO,EAEX,MAAQ,CAEN,MAAO,EACT,CAGA,OAAI,MAAM,QAAQA,CAAK,EACdA,EAAM,MAAOE,GAASH,EAAcG,EAAMD,EAAQ,CAAC,CAAC,EAK3D,OAAO,eAAeD,CAAK,IAAM,OAAO,WACxC,OAAO,eAAeA,CAAK,IAAM,KAE1B,GAGF,OAAO,OAAOA,CAAK,EAAE,MAAOG,GAASJ,EAAcI,EAAMF,EAAQ,CAAC,CAAC,CAC5E,CAGA,MAAO,EACT,EAEMG,EAAwBJ,GACvBK,EAASL,CAAK,EAKjBA,EAAM,UAAYM,GAClBN,EAAM,UAAY,GAClBO,EAAcP,EAAM,MAAM,GAC1B,OAAOA,EAAM,MAAS,UACtB,OAAOA,EAAM,WAAc,UAC3B,OAAOA,EAAM,WAAc,SATpB,GAaLQ,EAAeR,GACf,CAACK,EAASL,CAAK,GAIf,OAAOA,EAAM,MAAS,UAAYA,EAAM,KAAK,SAAW,GAAKA,EAAM,KAAK,OAAS,IAC5E,GAIL,YAAaA,GAASA,EAAM,UAAY,OACnCD,EAAcC,EAAM,OAAO,EAG7B,
|
|
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};\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 depth and size constraints to prevent malicious payloads.\n */\nconst isSafePayload = (value: unknown, depth = 0): boolean => {\n if (depth > MAX_PAYLOAD_DEPTH) {\n return false;\n }\n\n if (value === null || value === undefined) {\n return true;\n }\n\n const primitiveTypes = [\"string\", \"number\", \"boolean\"];\n if (primitiveTypes.includes(typeof value)) {\n return true;\n }\n\n if (typeof value === \"object\") {\n // Check JSON serialization size\n try {\n const serialized = JSON.stringify(value);\n if (serialized.length > MAX_PAYLOAD_SIZE) {\n return false;\n }\n } catch {\n // Circular references or non-serializable objects are not safe\n return false;\n }\n\n // Recursively validate nested objects and arrays\n if (Array.isArray(value)) {\n return value.every((item) => isSafePayload(item, depth + 1));\n }\n\n // Validate plain objects (guard against prototype pollution)\n if (\n Object.getPrototypeOf(value) !== Object.prototype &&\n Object.getPrototypeOf(value) !== null\n ) {\n return false;\n }\n\n return Object.values(value).every((prop) => isSafePayload(prop, depth + 1));\n }\n\n // Reject functions, symbols, and other non-serializable types\n return false;\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 );\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};\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\nconst resolveDefaultEnabled = (): boolean => {\n const nodeEnv = typeof process !== \"undefined\" ? process.env?.NODE_ENV : undefined;\n if (typeof nodeEnv !== \"string\") {\n return false;\n }\n\n return nodeEnv !== \"production\";\n};\n\nconst resolveDefaultCommandsEnabled = (): boolean => {\n const nodeEnv = typeof process !== \"undefined\" ? process.env?.NODE_ENV : undefined;\n if (typeof nodeEnv !== \"string\") {\n return false;\n }\n\n return nodeEnv !== \"production\";\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 if (typeof structuredClone === \"function\") {\n try {\n return structuredClone(value);\n } catch {\n // Fall through to the JSON serializer below.\n }\n }\n\n const seen = new WeakSet<object>();\n\n try {\n const serialized = JSON.stringify(value, (_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 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 {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\n }\n case \"terminateMachine\": {\n const result = await machine.send({ type: \"terminateJourney\" });\n return {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\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 {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\n }\n case \"goToPreviousStep\": {\n const result = await machine.goToPreviousStep(command.steps);\n return {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\n }\n case \"goToLastVisitedStep\": {\n const result = await machine.goToLastVisitedStep();\n return {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\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 {\n snapshot: result.snapshot,\n transitioned: result.transitioned,\n ...(result.transitionId ? { transitionId: result.transitionId } : {})\n };\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 ?? resolveDefaultEnabled();\n if (!enabled || typeof window === \"undefined\") {\n return () => {};\n }\n const commandsEnabled = options.commandsEnabled ?? resolveDefaultCommandsEnabled();\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\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 };\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 postSnapshot(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\n const unregisterEnvelope: JourneyDevtoolsBridgeUnregisterEnvelope = {\n ...createBaseEnvelope(\"unregister\")\n };\n post(unregisterEnvelope);\n };\n};\n"],
|
|
5
|
+
"mappings": "AAEO,IAAMA,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AAStC,EAAO,CACd,GAAI6B,EACF,OAGF,IAAMO,EAA2D,CAC/D,GAAGd,EAAmB,cAAc,EACpC,UAAWa,EAAgB,UAC3B,MAAOpC,EAAeC,CAAK,CAC7B,EACA0B,EAAKU,CAAa,CACpB,CACF,GAES,CACX,EAEA,OAAO,iBAAiB,UAAWL,CAAS,EAE5C,IAAMQ,EAAc7B,EAAQ,UAAU,IAAM,CACtCmB,GAGJD,EAAalB,EAAQ,YAAY,CAAC,CACpC,CAAC,EAEK8B,EAA0D,CAC9D,GAAGlB,EAAmB,UAAU,EAChC,KAAAF,EACA,SAAUlB,EAAkBQ,EAAQ,YAAY,CAAC,CACnD,EACA,OAAAgB,EAAKc,CAAgB,EAEd,IAAM,CACX,GAAIX,EACF,OAGFA,EAAa,GACbC,EAAY,MAAM,EAClBS,EAAY,EACZ,OAAO,oBAAoB,UAAWR,CAAS,EAE/C,IAAMU,EAA8D,CAClE,GAAGnB,EAAmB,YAAY,CACpC,EACAI,EAAKe,CAAkB,CACzB,CACF",
|
|
6
6
|
"names": ["JOURNEY_DEVTOOLS_PROTOCOL_VERSION", "JOURNEY_DEVTOOLS_CHANNEL", "JOURNEY_DEVTOOLS_BRIDGE_SOURCE", "JOURNEY_DEVTOOLS_EXTENSION_SOURCE", "isRecord", "value", "isKnownSource", "isSafePayload", "value", "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", "resolveDefaultEnabled", "nodeEnv", "resolveDefaultCommandsEnabled", "resolveWindowTargetOrigin", "isExpectedWindowOrigin", "origin", "expected", "createMachineId", "CommandRateLimiter", "maxCommandsPerWindow", "windowMs", "now", "windowStart", "ts", "cloneForTransport", "seen", "serialized", "_key", "currentValue", "serializeError", "error", "cause", "serializeSnapshot", "snapshot", "byStep", "stepId", "stepState", "isVisited", "isKnownStepId", "assertKnownStepId", "machine", "commandType", "runCommand", "command", "result", "sendEvent", "attachJourneyDevtools", "options", "commandsEnabled", "machineId", "meta", "targetOrigin", "createBaseEnvelope", "kind", "JOURNEY_DEVTOOLS_CHANNEL", "JOURNEY_DEVTOOLS_BRIDGE_SOURCE", "post", "envelope", "postSnapshot", "isDetached", "rateLimiter", "onMessage", "event", "isJourneyDevtoolsEnvelope", "JOURNEY_DEVTOOLS_EXTENSION_SOURCE", "commandEnvelope", "errorEnvelope", "outcome", "resultEnvelope", "unsubscribe", "registerEnvelope", "unregisterEnvelope"]
|
|
7
7
|
}
|
package/dist/protocol.d.ts
CHANGED
|
@@ -94,7 +94,19 @@ export type JourneyDevtoolsExtensionCommandEnvelope = JourneyDevtoolsEnvelopeBas
|
|
|
94
94
|
export type JourneyDevtoolsBridgeEnvelope = JourneyDevtoolsBridgeRegisterEnvelope | JourneyDevtoolsBridgeUnregisterEnvelope | JourneyDevtoolsBridgeSnapshotEnvelope | JourneyDevtoolsBridgeCommandResultEnvelope | JourneyDevtoolsBridgeCommandErrorEnvelope;
|
|
95
95
|
export type JourneyDevtoolsExtensionEnvelope = JourneyDevtoolsExtensionCommandEnvelope;
|
|
96
96
|
export type JourneyDevtoolsEnvelope = JourneyDevtoolsBridgeEnvelope | JourneyDevtoolsExtensionEnvelope;
|
|
97
|
+
/**
|
|
98
|
+
* Validates whether an unknown value is a supported devtools command payload.
|
|
99
|
+
*/
|
|
97
100
|
export declare const isJourneyDevtoolsCommand: (value: unknown) => value is JourneyDevtoolsCommand;
|
|
101
|
+
/**
|
|
102
|
+
* Validates whether an unknown value is a bridge-origin envelope.
|
|
103
|
+
*/
|
|
98
104
|
export declare const isJourneyDevtoolsBridgeEnvelope: (value: unknown) => value is JourneyDevtoolsBridgeEnvelope;
|
|
105
|
+
/**
|
|
106
|
+
* Validates whether an unknown value is an extension-origin command envelope.
|
|
107
|
+
*/
|
|
99
108
|
export declare const isJourneyDevtoolsExtensionEnvelope: (value: unknown) => value is JourneyDevtoolsExtensionEnvelope;
|
|
109
|
+
/**
|
|
110
|
+
* Validates whether an unknown value matches either supported devtools envelope shape.
|
|
111
|
+
*/
|
|
100
112
|
export declare const isJourneyDevtoolsEnvelope: (value: unknown) => value is JourneyDevtoolsEnvelope;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxova/journey-devtools-bridge",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"description": "Bridge API to connect Journey machines to browser devtools.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"journey",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
],
|
|
46
46
|
"sideEffects": false,
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@rxova/journey-core": "^0.6.
|
|
48
|
+
"@rxova/journey-core": "^0.6.4"
|
|
49
49
|
},
|
|
50
50
|
"size-limit": [
|
|
51
51
|
{
|