A TypeScript library for parsing, manipulating, and serializing Salesforce Flow XML files in Deno.
- Parse Salesforce Flow XML files into TypeScript objects
- Manipulate Flow objects with a clean, type-safe API
- Serialize Flow objects back to XML
- Find and modify Flow nodes and their connections
- Sort Flow arrays by name for consistent output
- Comprehensive type definitions for Flow objects
# Add to your dependencies
deno add @damecek/sf-flow-parser
# Or import directly in your code
import { parse, stringify } from "jsr:@damecek/sf-flow-parser";
import {parse, stringify} from "https://raw.githubusercontent.com/damecek/sf-flow-parser/main/src/main.ts";
# Clone the repository
git clone https://github.com/damecek/sf-flow-parser.git
cd sf-flow-parser
# Import in your code
import { parse, stringify } from "./src/main.ts";
import {parseFromFile, stringifyToFile} from "@damecek/sf-flow-parser";
// Parse a Flow XML file
const flow = parseFromFile("path/to/flow.xml");
// Modify the Flow object
flow.label = "Modified Flow";
// Write the modified Flow back to a file
stringifyToFile(flow, "path/to/modified-flow.xml");
import {
parseFromFile,
stringifyToFile,
findFlowNodeByName,
findParentFlowNodes,
getConnectors
} from "@damecek/sf-flow-parser";
// Parse a Flow XML file
const flow = parseFromFile("path/to/flow.xml");
// Find a specific node
const node = findFlowNodeByName(flow, "MyDecision");
if (node) {
// Modify the node
node.label = "Updated Decision";
}
// Find all parent nodes that connect to a specific node
const parents = findParentFlowNodes(flow, "TargetNode");
parents.forEach(parent => {
console.log(`Parent node: ${parent.name}`);
// Get all connectors from the parent node
const connectors = getConnectors(parent);
connectors.forEach(connector => {
console.log(`Connector target: ${connector.targetReference}`);
});
});
// Write the modified Flow back to a file
stringifyToFile(flow, "path/to/modified-flow.xml");
parse(xml: string): Flow
- Parse XML string into a Flow objectparseFromFile(path: string): Flow
- Parse Flow from XML filestringify(flow: Flow): string
- Convert Flow object to XML stringstringifyToFile(flow: Flow, path: string): void
- Write Flow object to XML file
findFlowNodeByName(flow: Flow, name: string): FlowNode | undefined
- Find a Flow node by namefindParentFlowNodes(flow: Flow, childName: string): FlowNode[]
- Find all parent nodes that connect to a child nodegetConnectors(node: BaseFlowNodeWithConnector): FlowConnector[]
- Get all connectors from a Flow nodegetFlowNodes(flow: Flow): FlowNode[]
- Get all nodes from a Flow objectreparentNode(flow: Flow, sourceNodeName: string, targetNodeName: string): void
- Change all parent node connections from one node to another
ensureArray(obj: Record<string, any>, propertyName: string): void
- Ensure a property is always an arrayensureArrayProperties(flow: Flow): void
- Ensure all Flow array properties are arraysprocessNestedArrays(obj: Record<string, any>): void
- Process nested arrays in Flow objectssortByName<T>(arr: T[]): T[]
- Sort an array of objects by namesortFlowArrays(flow: Flow): Flow
- Sort all array properties in a Flow object by name
- Deno v1.37.0 or higher
- Clone the repository:
git clone https://github.com/damecek/sf-flow-parser.git cd sf-flow-parser
# Run all tests
deno task test
# Run tests with coverage
deno task test:coverage
# Run specific test file
deno task test src/test/flow.test.ts
This is a Deno module, so no build step is required. The code can be imported directly.
Contributions are welcome! Please feel free to submit a Pull Request.
- Make sure all tests pass before submitting a PR
- Add tests for new features
- Update documentation for any changes
- Follow the existing code style
- Run
deno fmt
before committing to ensure consistent formatting
- Fork the repository
- Create a new branch for your feature
- Make your changes
- Add or update tests
- Run tests to ensure they pass
- Run
deno fmt
to format your code - Submit a pull request
Check out the examples directory for more usage examples:
- Basic Usage - Simple example of parsing and modifying a Flow
- Add Decision Node - Advanced example showing how to add a new decision node to a Flow
Run examples with:
deno run --allow-read --allow-write examples/basic-usage.ts path/to/flow.xml