Extending FlowDelta for New Salesforce Node Types
Extending FlowDelta for New Salesforce Node Types
Use this guide when Salesforce ships a new Flow element type, or an existing type gains new properties.
Overview
Supporting a new node type takes up to four steps:
- Declare the type in
src/model/graph-model.ts, if it isn’t there yet. - Verify parsing. Confirm the vendored parser handles it.
- Add a section schema (optional) for better rendering.
- Add test coverage.
Step 1: Declare the NodeType
All supported element types are listed in src/model/graph-model.ts:
export type NodeType = | "start" | "end" | "assignment" // ... existing types | "myNewType" // Add here | "unknown";Rules:
- Use lowercase camelCase.
- Use the exact element name from the Salesforce XML.
- Add a test fixture (see Step 4).
Also add the type to the element card maps. These maps are typed Record<NodeType, …>, so npm run typecheck fails until each one has an entry:
NODE_TYPE_LABELSinsrc/model/node-summary.ts: the type name shown in the card’s tooltip, and the caption fallback.CARD_GLYPHSinsrc/render/render-html.ts: the inline SVG glyph for the card tile.CARD_TYPE_TOKENSinsrc/render/render-html.ts: the--type-*color token for the tile and border. Reuse an existing token, such asrecordorneutral. A new token also needs--type-<token>and--type-<token>-fillin the light and dark palettes inrender-html.ts.
Optionally, add a SUMMARIES entry in src/model/node-summary.ts to give the card a key-fact caption. Without one, the caption falls back to the display name.
Step 2: Verify parser support
The parser is vendored from Google Flow Lens. It lives in src/parser/flow_types.ts, which is read-only. Check whether it already defines the new element type:
grep "myNewType" src/parser/flow_types.tsIf it’s there, the parser handles the element. Go to Step 3.
If it’s not, the parser may not recognize the element. You have two options:
- Open an upstream issue with Google Flow Lens and ask them to add the type.
- Add a fallback in
src/model/build-model.tsthat catches unknown elements as"unknown".
The parser already falls back for unrecognized types, so parsing won’t fail. Unknown elements are parsed, but classified as type: "unknown" in the GraphModel.
Step 3: Add a section schema (optional)
If the new type has domain-specific properties that should show as semantic sections (for example “Filters” or “Outcomes”), add a section schema in src/render/section-schemas.ts:
const myNewTypeSchemas: SectionSchema[] = [ { name: "Configuration", paths: ["myProperty", "anotherProperty"], render: "lines", // or "table" / "grouped-table" },];
function getNodeTypeSchemas(nodeType: NodeType): SectionSchema[] { switch (nodeType) { case "myNewType": return myNewTypeSchemas; // ... other cases }}See section-schemas.md for details.
If you skip this step, the diff still works. Changed properties appear in the generic "Configuration" fallback section. The rendering is less polished, but correct.
Step 4: Add test coverage
Create a fixture with the new element in both the before and after versions:
mkdir -p fixtures/diff/my_new_type/# Add before.flow-meta.xml and after.flow-meta.xml with the new elementAdd a test row in test/semantic-diff.test.ts:
{ name: "my_new_type", expectedSummary: { addedNodes: 0, removedNodes: 0, modifiedNodes: 1, // The new element was modified unchangedNodes: 3, addedEdges: 0, removedEdges: 0 }, assertion: (diff) => { const modified = diff.nodes.find(n => n.type === "myNewType"); assert(modified, "myNewType node should be modified"); }}Run the tests:
npm testnpm run render:fixturesOpen flow-delta-out/fixtures/my_new_type.html in a browser and check the rendering.
Common scenarios
Scenario 1: a new node type with simple properties
Example: a new "notification" element that sends notifications.
- Add
"notification"toNodeTypeingraph-model.ts. - Check whether the parser supports it (run the test suite).
- Create a fixture with a modified notification node.
- Optionally, add a simple section schema if the properties deserve grouping.
- Commit and test.
export type NodeType = | // ... existing | "notification" | "unknown";
// src/render/section-schemas.ts (optional)const notificationSchemas: SectionSchema[] = [ { name: "Notification Settings", paths: ["recipientList", "subject", "body"], render: "lines" }];
function getNodeTypeSchemas(nodeType: NodeType): SectionSchema[] { switch (nodeType) { case "notification": return notificationSchemas; // ... }}Scenario 2: an existing type gains new properties
Example: recordCreate gains a requiredFields property.
- No type change is needed. The element is still
"recordCreate". - The new property is diffed automatically.
- Optionally, if
requiredFieldsis a collection, add a section for it. - Create a fixture with a modified create element.
- Test.
const recordCreateSchemas: SectionSchema[] = [ { name: "Field Mappings", paths: ["inputAssignments"], render: "table", columns: [ { key: "field", label: "Field" }, { key: "value", label: "Value", unwrap: true }, ], }, { name: "Required Fields", // New section paths: ["requiredFields"], render: "table", columns: [{ key: "name", label: "Field Name" }], },];Scenario 3: Salesforce changes an element’s structure
Example: a decision’s rules array now includes a metadata object.
- No type change.
- The new
metadatais captured in property diffs automatically. - Inspect the parser output to understand the new structure.
- If the structure is complex, add a grouped-table schema.
- Create a fixture with the modified decision.
- Test.
const decisionSchemas: SectionSchema[] = [ { name: "Outcomes", paths: ["rules"], render: "grouped-table", columns: [ { key: "leftValueReference", label: "Resource", unwrap: true }, { key: "operator", label: "Operator" }, { key: "rightValue", label: "Value", unwrap: true }, ], }, // If "rules[].metadata" needs special rendering, add another section];Scenario 4: the parser doesn’t understand the element
If the parser can’t parse the new element, it falls back to "unknown".
"unknown"is already inNodeType.- Unknown elements still produce diffs, classified as
type: "unknown". - No special handling is needed. The fallback is generic.
- Create a fixture with the unknown element.
- Run the tests to confirm it parses without error.
No code changes are needed. The element appears as type: "unknown" in diffs.
To improve support, either:
- file an issue with Google Flow Lens to request parser support; or
- add a custom parser pass in
build-model.tsto handle the element.
Example custom pass:
// In buildGraphModel(), after parsing:if (element.elementSubtype === "MyNewCustomElement") { element.type = "myCustomElement"; // Override unknown → custom type}Debugging new types
If a new element type doesn’t parse or diff correctly:
-
Check the diff output.
Terminal window npx tsx src/cli.ts --old before.xml --new after.xml --json --out out/cat out/*.diff.json | jq '.nodes[] | select(.type == "myNewType")' -
Inspect the parsed structure. Add
console.log()inbuildGraphModel()to see the parsed element. Compare it withsrc/parser/flow_types.tsto see which fields are extracted. -
Check canonicalization. Are the element’s properties being stripped (coordinates, connectors)? See
TOP_LEVEL_KEYSandEDGE_KEYSinbuild-model.ts. -
Check the schema. Are the property paths and column keys right?
-
Use a minimal fixture. Make one with only the new element type, and run the test to isolate the issue.
Checklist
- Added the type name to the
NodeTypeunion insrc/model/graph-model.ts - Added the type to
NODE_TYPE_LABELS,CARD_GLYPHS, andCARD_TYPE_TOKENS(required by typecheck) - Verified the parser supports it (or filed an upstream issue)
- Created a fixture in
fixtures/diff/<case>/with before/after flows - Added a test row in
test/semantic-diff.test.ts - (Optional) Added a section schema in
src/render/section-schemas.ts - (Optional) Updated salesforce-flow-primer.md with element docs
- Ran
npm testand it passes - Ran
npm run render:fixturesand checked the HTML by eye - Committed the fixture and code changes together
Contributing upstream
If you extend the parser or add parser support:
- Test thoroughly. Parser changes affect every flow.
- Keep parser edits minimal. The parser is vendored, so build on top of it where you can.
- Coordinate with Google Flow Lens. If the parser lacks a type, file an issue upstream.
- Update NOTICE. If you vendor a new parser version, update the commit hash.
See vendoring.md for the vendoring policy.
References
- Salesforce Flow metadata API
- Google Flow Lens (upstream parser)
- Parser types:
src/parser/flow_types.ts(do not edit) - Section schema authoring: section-schemas.md
- Data model: data-model.md