@sfdxy/mule-lint 1.21.0 → 1.22.0

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.
@@ -0,0 +1,191 @@
1
+ # Variable Contracts & Correlation ID Patterns
2
+
3
+ > **Applies to:** All
4
+ > **Related Rules:** `MULE-007` · `MULE-102` · `STD-001`
5
+ > **Last Updated:** April 2026
6
+
7
+ ## When to Read This
8
+
9
+ Read this when designing the variable contract between flows and sub-flows. Standardized variables ensure consistent behavior across routing, logging, error handling, and response building.
10
+
11
+ ---
12
+
13
+ ## Standard Variable Set
14
+
15
+ Every APIKit route flow or event listener flow should set these variables **before** delegating to sub-flows:
16
+
17
+ | Variable | Type | Required | Description |
18
+ | ----------------- | ------- | ------------------ | --------------------------------------------------------------- |
19
+ | `correlationId` | String | ✅ Always | Unique request/event identifier for distributed tracing |
20
+ | `logCategory` | String | ✅ Always | Logger category (e.g., `com.myorg.sf.sapi`) |
21
+ | `flowName` | String | ✅ Always | Human-readable flow identifier for logging |
22
+ | `env` | String | ✅ Always | Current environment from `p('mule.env')` |
23
+ | `action` | String | ✅ For CRUD APIs | Operation type: `CREATE`, `UPDATE`, `UPSERT`, `DELETE`, `QUERY` |
24
+ | `sObjectType` | String | ✅ For entity APIs | Entity/record type from URI parameter |
25
+ | `isArray` | Boolean | ✅ For CRUD APIs | Whether the original request payload was an array |
26
+ | `externalIdField` | String | Optional | External ID field for upsert operations (defaults to `Id`) |
27
+
28
+ ---
29
+
30
+ ## Patterns
31
+
32
+ ### Pattern 1: APIKit Route Variable Setup
33
+
34
+ **Use when:** setting variables in an APIKit-generated route flow.
35
+
36
+ Set all variables in a single `ee:transform` at the top of every route flow:
37
+
38
+ ```xml
39
+ <flow name="post:\salesforce\(sObjectType):application\json:api-config">
40
+ <ee:transform doc:name="Set Variables">
41
+ <ee:variables>
42
+ <ee:set-variable variableName="correlationId"><![CDATA[
43
+ attributes.headers.'x-correlation-id' default correlationId
44
+ ]]></ee:set-variable>
45
+ <ee:set-variable variableName="logCategory"><![CDATA[
46
+ "com.myorg.sf.sapi"
47
+ ]]></ee:set-variable>
48
+ <ee:set-variable variableName="flowName"><![CDATA[
49
+ "Mulesoft: my-sapi - " ++ flow.name
50
+ ]]></ee:set-variable>
51
+ <ee:set-variable variableName="env"><![CDATA[
52
+ p('mule.env')
53
+ ]]></ee:set-variable>
54
+ <ee:set-variable variableName="action"><![CDATA[
55
+ "CREATE"
56
+ ]]></ee:set-variable>
57
+ <ee:set-variable variableName="sObjectType"><![CDATA[
58
+ attributes.uriParams.'sObjectType'
59
+ ]]></ee:set-variable>
60
+ <ee:set-variable variableName="isArray"><![CDATA[
61
+ payload is Array
62
+ ]]></ee:set-variable>
63
+ </ee:variables>
64
+ </ee:transform>
65
+ <logger level="INFO" category="#[vars.logCategory]"
66
+ message='#["[" ++ vars.correlationId ++ "] CREATE for: " ++ vars.sObjectType]'/>
67
+ <flow-ref name="process-subflow"/>
68
+ </flow>
69
+ ```
70
+
71
+ ### Pattern 2: Event Listener Variable Setup
72
+
73
+ **Use when:** setting variables from a Salesforce Platform Event or Anypoint MQ message.
74
+
75
+ ```xml
76
+ <flow name="sf-account-event-listener">
77
+ <salesforce:replay-channel-listener channel="/event/Account_Event__e" .../>
78
+ <ee:transform doc:name="Set Variables">
79
+ <ee:variables>
80
+ <!-- Correlation ID from event metadata, NOT HTTP header -->
81
+ <ee:set-variable variableName="correlationId"><![CDATA[
82
+ payload.EventUuid default correlationId
83
+ ]]></ee:set-variable>
84
+ <ee:set-variable variableName="logCategory"><![CDATA[
85
+ "com.myorg.sf.papi"
86
+ ]]></ee:set-variable>
87
+ <ee:set-variable variableName="salesforceId"><![CDATA[
88
+ payload.Record_Id__c default ""
89
+ ]]></ee:set-variable>
90
+ <ee:set-variable variableName="entity"><![CDATA[
91
+ "account"
92
+ ]]></ee:set-variable>
93
+ </ee:variables>
94
+ </ee:transform>
95
+ <!-- ... -->
96
+ </flow>
97
+ ```
98
+
99
+ ### Pattern 3: Array-In / Array-Out Response Mirroring
100
+
101
+ **Use when:** an API accepts both single objects and arrays, and the response must mirror the input shape.
102
+
103
+ Set `vars.isArray` in the route flow:
104
+
105
+ ```xml
106
+ <ee:set-variable variableName="isArray"><![CDATA[
107
+ payload is Array
108
+ ]]></ee:set-variable>
109
+ ```
110
+
111
+ Use it in DWL response transforms to mirror the shape:
112
+
113
+ ```dataweave
114
+ %dw 2.0
115
+ output application/json
116
+ ---
117
+ if (vars.isArray)
118
+ payload map { id: $.id, success: $.success }
119
+ else
120
+ { id: payload[0].id, success: payload[0].success }
121
+ ```
122
+
123
+ ### Pattern 4: Action-Based Routing
124
+
125
+ **Use when:** a single process sub-flow handles multiple CRUD operations.
126
+
127
+ The `vars.action` variable drives routing inside the process sub-flow:
128
+
129
+ ```xml
130
+ <sub-flow name="salesforce-process-subflow">
131
+ <choice>
132
+ <when expression="#[vars.action == 'CREATE']">
133
+ <flow-ref name="salesforce-create-subflow"/>
134
+ </when>
135
+ <when expression="#[vars.action == 'UPSERT']">
136
+ <flow-ref name="salesforce-upsert-subflow"/>
137
+ </when>
138
+ <when expression="#[vars.action == 'DELETE']">
139
+ <flow-ref name="salesforce-delete-subflow"/>
140
+ </when>
141
+ <when expression="#[vars.action == 'QUERY' or vars.action == 'QUERY_ENTITY']">
142
+ <flow-ref name="salesforce-query-subflow"/>
143
+ </when>
144
+ </choice>
145
+ </sub-flow>
146
+ ```
147
+
148
+ ---
149
+
150
+ ## Correlation ID Patterns
151
+
152
+ | Source | Pattern | Use Case |
153
+ | -------------- | ------------------------------------------------------------- | ---------------------------- |
154
+ | HTTP header | `attributes.headers.'x-correlation-id' default correlationId` | HTTP APIs (SAPI, Experience) |
155
+ | Platform Event | `payload.EventUuid default correlationId` | Event-driven PAPI |
156
+ | Anypoint MQ | `attributes.messageId default correlationId` | MQ consumers |
157
+ | Generated | `correlationId` (Mule built-in) | Fallback / internal flows |
158
+
159
+ **Propagation rules:**
160
+
161
+ - Include in all outbound HTTP requests as `x-correlation-id` header
162
+ - Include in all log messages: `#["[" ++ vars.correlationId ++ "] message"]`
163
+ - Include in all error response payloads
164
+ - Store in `vars.correlationId` (camelCase)
165
+
166
+ ---
167
+
168
+ ## Variable Naming Conventions
169
+
170
+ | Convention | Example | Use For |
171
+ | ------------------- | ----------------------------------------- | -------------------------- |
172
+ | `camelCase` | `correlationId`, `sObjectType`, `isArray` | All `set-variable` names |
173
+ | Static strings | `"com.myorg.sf.sapi"` | Logger categories, actions |
174
+ | Property references | `p('mule.env')` | Environment-derived values |
175
+
176
+ > ❌ **Don't use:** `snake_case` (`correlation_id`), `PascalCase` (`CorrelationId`), or `SCREAMING_CASE` (`CORRELATION_ID`) for variable names.
177
+
178
+ ---
179
+
180
+ ## Checklist
181
+
182
+ - [ ] All route flows set `correlationId`, `logCategory`, `flowName`, `env` before delegation
183
+ - [ ] CRUD route flows additionally set `action`, `sObjectType`, `isArray`
184
+ - [ ] Correlation ID sourced correctly for project type (HTTP vs. event vs. MQ)
185
+ - [ ] `correlationId` propagated in all outbound requests, logs, and error responses
186
+ - [ ] Variables use `camelCase` naming
187
+ - [ ] `isArray` set before calling process sub-flow (for response mirroring)
188
+
189
+ ---
190
+
191
+ **See also:** [Error Handling](error-handling.md) · [Logging](logging.md) · [Event-Driven Patterns](event-driven-patterns.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sfdxy/mule-lint",
3
- "version": "1.21.0",
3
+ "version": "1.22.0",
4
4
  "description": "Static analysis tool for MuleSoft applications - supports humans, AI agents, and CI/CD pipelines",
5
5
  "author": "Avinava",
6
6
  "license": "MIT",