@sfdxy/mule-lint 1.21.0 → 1.23.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.
Files changed (37) hide show
  1. package/dist/package.json +1 -1
  2. package/dist/src/mcp/prompts/index.d.ts +1 -1
  3. package/dist/src/mcp/prompts/index.d.ts.map +1 -1
  4. package/dist/src/mcp/prompts/index.js +62 -1
  5. package/dist/src/mcp/prompts/index.js.map +1 -1
  6. package/dist/src/mcp/resources/index.js +114 -16
  7. package/dist/src/mcp/resources/index.js.map +1 -1
  8. package/dist/src/mcp/tools/getRuleDetails.d.ts.map +1 -1
  9. package/dist/src/mcp/tools/getRuleDetails.js +30 -1
  10. package/dist/src/mcp/tools/getRuleDetails.js.map +1 -1
  11. package/dist/src/rules/index.js +3 -3
  12. package/dist/src/rules/index.js.map +1 -1
  13. package/dist/src/rules/logging/{NewLoggingRules.d.ts → LoggingPatternRules.d.ts} +1 -1
  14. package/dist/src/rules/logging/LoggingPatternRules.d.ts.map +1 -0
  15. package/dist/src/rules/logging/{NewLoggingRules.js → LoggingPatternRules.js} +1 -1
  16. package/dist/src/rules/logging/LoggingPatternRules.js.map +1 -0
  17. package/dist/src/rules/naming/FlowCasingRule.d.ts +6 -3
  18. package/dist/src/rules/naming/FlowCasingRule.d.ts.map +1 -1
  19. package/dist/src/rules/naming/FlowCasingRule.js +26 -8
  20. package/dist/src/rules/naming/FlowCasingRule.js.map +1 -1
  21. package/docs/README.md +87 -27
  22. package/docs/best-practices/ci-cd.md +135 -0
  23. package/docs/best-practices/connector-patterns.md +253 -0
  24. package/docs/best-practices/dataweave-patterns.md +370 -0
  25. package/docs/best-practices/deployment-2026.md +171 -0
  26. package/docs/best-practices/error-handling.md +277 -0
  27. package/docs/best-practices/event-driven-patterns.md +424 -0
  28. package/docs/best-practices/logging.md +163 -0
  29. package/docs/best-practices/mulesoft-best-practices.md +72 -865
  30. package/docs/best-practices/performance.md +273 -0
  31. package/docs/best-practices/security.md +181 -0
  32. package/docs/best-practices/testing.md +190 -0
  33. package/docs/best-practices/variable-contracts.md +191 -0
  34. package/docs/linter/naming-conventions.md +4 -0
  35. package/package.json +1 -1
  36. package/dist/src/rules/logging/NewLoggingRules.d.ts.map +0 -1
  37. package/dist/src/rules/logging/NewLoggingRules.js.map +0 -1
package/docs/README.md CHANGED
@@ -1,17 +1,47 @@
1
1
  # Mule-Lint Documentation
2
2
 
3
- Welcome to the Mule-Lint documentation. This documentation is organized into two sections:
3
+ Welcome to the Mule-Lint documentation. This documentation is organized into two sections: **MuleSoft Best Practices** (for integration developers and AI agents) and **Linter Technical Documentation** (for mule-lint contributors).
4
4
 
5
5
  ---
6
6
 
7
7
  ## 📘 MuleSoft Best Practices
8
8
 
9
- Comprehensive guidelines for building maintainable, secure, and performant Mule applications. These guidelines cover more than just what the linter validates - they represent industry best practices for MuleSoft development.
9
+ Comprehensive guidelines for building maintainable, secure, and performant Mule 4 applications. Each guide is a focused, self-contained reference that can be read independently.
10
10
 
11
- | Document | Description |
12
- | ----------------------------------------------------------------- | -------------------------------------------- |
13
- | [Best Practices Guide](best-practices/mulesoft-best-practices.md) | Complete MuleSoft development best practices |
14
- | [Rules Catalog](best-practices/rules-catalog.md) | All 56 linter rules with examples |
11
+ ### Core Development
12
+
13
+ | Document | Description |
14
+ | ----------------------------------------------------------------- | ---------------------------------------------------------------------------- |
15
+ | [Best Practices Index](best-practices/mulesoft-best-practices.md) | Master index with quick reference card and API-Led overview |
16
+ | [Error Handling](best-practices/error-handling.md) | Global error handlers, HTTP vs. event-driven patterns, connector error types, CRM error log objects |
17
+ | [Variable Contracts](best-practices/variable-contracts.md) | Standard variables, correlation IDs, array mirroring, action routing |
18
+ | [Logging](best-practices/logging.md) | Categories, structured JSON logging, MDC/tracing, PII prevention |
19
+ | [Security](best-practices/security.md) | Secure properties, TLS 1.2+, credentials, zero-trust architecture |
20
+ | [Performance](best-practices/performance.md) | Timeouts, connection pooling, async error handling, streaming, bulk lookup (N+1 prevention) |
21
+
22
+ ### Architecture & Patterns
23
+
24
+ | Document | Description |
25
+ | ---------------------------------------------------------------- | ----------------------------------------------------------------- |
26
+ | [Event-Driven Patterns](best-practices/event-driven-patterns.md) | Platform Events, Anypoint MQ, VM Queue Dispatcher, scheduler watermarking, deferred task polling |
27
+ | [Connector Patterns](best-practices/connector-patterns.md) | Entity config YAML, SF/NS connector gotchas, protocol negotiation, ObjectStore caching |
28
+ | [DataWeave Patterns](best-practices/dataweave-patterns.md) | Modules, type coercion, cross-system value mapping (4 strategies), import path rules |
29
+
30
+ ### Project & Operations
31
+
32
+ | Document | Description |
33
+ | -------------------------------------------------------------------- | ------------------------------------------------------------ |
34
+ | [Folder Structure](best-practices/folder-structure.md) | Standard Maven layout for Mule 4 projects |
35
+ | [Documentation Standards](best-practices/documentation-standards.md) | Flow documentation, README templates, commit messages |
36
+ | [Testing (MUnit)](best-practices/testing.md) | Test structure, error scenario testing, event-driven testing |
37
+ | [CI/CD Integration](best-practices/ci-cd.md) | Pipeline stages, mule-lint integration, quality gates |
38
+ | [Deployment & Modernization](best-practices/deployment-2026.md) | CloudHub 2.0, Java 17, Anypoint Code Builder, API Governance |
39
+
40
+ ### Reference
41
+
42
+ | Document | Description |
43
+ | ------------------------------------------------ | ------------------------------------------------------ |
44
+ | [Rules Catalog](best-practices/rules-catalog.md) | Complete reference for all 82 lint rules with examples |
15
45
 
16
46
  ---
17
47
 
@@ -19,13 +49,14 @@ Comprehensive guidelines for building maintainable, secure, and performant Mule
19
49
 
20
50
  For contributors and those extending mule-lint.
21
51
 
22
- | Document | Description |
23
- | -------------------------------------------------- | -------------------------------------- |
24
- | [Architecture](linter/architecture.md) | System design, patterns, and data flow |
25
- | [Rule Engine](linter/rule-engine.md) | Rule engine internals and interfaces |
26
- | [Extending](linter/extending.md) | How to create custom rules |
27
- | [Folder Structure](linter/folder-structure.md) | Project organization |
28
- | [Naming Conventions](linter/naming-conventions.md) | Code style and naming standards |
52
+ | Document | Description |
53
+ | -------------------------------------------------- | ------------------------------------------------ |
54
+ | [Architecture](linter/architecture.md) | System design, patterns, and data flow |
55
+ | [Rule Engine](linter/rule-engine.md) | Rule engine internals and interfaces |
56
+ | [Extending](linter/extending.md) | How to create custom rules |
57
+ | [Folder Structure](linter/folder-structure.md) | Linter project organization |
58
+ | [Naming Conventions](linter/naming-conventions.md) | Code style and naming standards |
59
+ | [MCP Design](mcp-design.md) | MCP server architecture and tool/resource design |
29
60
 
30
61
  ---
31
62
 
@@ -72,25 +103,54 @@ mule-lint ./src/main/mule --fail-on-warning
72
103
 
73
104
  ## Rule Families
74
105
 
75
- | Family | Prefix | Count | Description |
76
- | --------------- | ------------------------- | ----- | -------------------------------------------------- |
77
- | Core MuleSoft | MULE-XXX | 29 | Core Mule 4 XML validation |
78
- | Security | SEC-XXX | 5 | Security best practices (TLS, rate limiting, etc.) |
79
- | Logging | LOG-XXX | 2 | Structured logging and sensitive data |
80
- | Operations | OPS-XXX, RES-XXX, HYG-XXX | 7 | Reconnection, auto-discovery, hygiene |
81
- | YAML Properties | YAML-XXX | 3 | YAML configuration validation |
82
- | DataWeave | DW-XXX | 4 | DataWeave file validation |
83
- | API-Led | API-XXX | 5 | API-Led connectivity patterns |
84
- | Governance | PROJ-XXX | 2 | POM and Git hygiene |
85
- | Experimental | EXP-XXX | 3 | Beta rules for evaluation |
86
-
87
- **Total: 56 rules**
106
+ | Family | Prefix | Count | Description |
107
+ | --------------- | ------------------------- | ----- | -------------------------------------------- |
108
+ | Core MuleSoft | MULE-XXX | 29 | Core Mule 4 XML validation |
109
+ | Error Handling | ERR-XXX | 4 | Advanced error handler rules |
110
+ | Security | SEC-XXX | 5 | Security best practices (TLS, rate limiting) |
111
+ | Logging | LOG-XXX, HYG-001 | 3 | Structured logging and sensitive data |
112
+ | HTTP | HTTP-XXX | 1 | HTTP connector configuration |
113
+ | Operations | OPS-XXX, RES-XXX, HYG-XXX | 8 | Reconnection, auto-discovery, hygiene |
114
+ | YAML Properties | YAML-XXX | 3 | YAML configuration validation |
115
+ | DataWeave | DW-XXX | 5 | DataWeave file validation |
116
+ | API-Led | API-XXX | 7 | API-Led connectivity patterns |
117
+ | Connectors | SF-XXX | 2 | Salesforce and event connector rules |
118
+ | Standards | CFG-XXX, STD-XXX | 3 | Config and API standards |
119
+ | Governance | PROJ-XXX | 2 | POM and Git hygiene |
120
+ | Experimental | EXP-XXX | 3 | Beta rules for evaluation |
121
+
122
+ **Total: 82 rules**
88
123
 
89
124
  ---
90
125
 
91
126
  ## For AI Agents
92
127
 
93
- Use SARIF output format for structured results:
128
+ ### MCP Resources
129
+
130
+ All best practice guides are available via the MuleSoft Lint MCP server:
131
+
132
+ ```
133
+ mule-lint://rules → JSON catalog of all 82 rules
134
+ mule-lint://docs/best-practices → Master index and quick reference
135
+ mule-lint://docs/error-handling → Error handling patterns
136
+ mule-lint://docs/event-driven → Event-driven architecture
137
+ mule-lint://docs/connectors → Connector configuration
138
+ mule-lint://docs/variables → Variable contracts
139
+ mule-lint://docs/dataweave → DataWeave patterns
140
+ mule-lint://docs/security → Security best practices
141
+ mule-lint://docs/logging → Logging standards
142
+ mule-lint://docs/performance → Performance optimization
143
+ mule-lint://docs/testing → MUnit testing
144
+ mule-lint://docs/deployment → Deployment & modernization
145
+ mule-lint://docs/ci-cd → CI/CD integration
146
+ mule-lint://docs/folder-structure → Project structure
147
+ mule-lint://docs/documentation-standards → Documentation standards
148
+ mule-lint://docs/rules-catalog → Complete rules reference
149
+ ```
150
+
151
+ ### SARIF Output
152
+
153
+ Use SARIF output for structured results:
94
154
 
95
155
  ```bash
96
156
  mule-lint ./src/main/mule -f sarif > report.sarif
@@ -0,0 +1,135 @@
1
+ # CI/CD Integration
2
+
3
+ > **Applies to:** All
4
+ > **Related Rules:** `PROJ-001` · `PROJ-002`
5
+ > **Last Updated:** April 2026
6
+
7
+ ## When to Read This
8
+
9
+ Read this when setting up CI/CD pipelines, integrating mule-lint into builds, or configuring quality gates.
10
+
11
+ ---
12
+
13
+ ## Pipeline Stages
14
+
15
+ ```
16
+ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
17
+ │ Build │ → │ Lint │ → │ Test │ → │ Package │ → │ Deploy │
18
+ │ │ │ │ │ │ │ │ │ │
19
+ │ mvn │ │ mule- │ │ mvn test │ │ mvn │ │ anypoint │
20
+ │ compile │ │ lint │ │ │ │ package │ │ deploy │
21
+ └──────────┘ └──────────┘ └──────────┘ └──────────┘ └──────────┘
22
+ ```
23
+
24
+ ---
25
+
26
+ ## mule-lint Integration
27
+
28
+ ### Quality Gate Configuration
29
+
30
+ ```json
31
+ // .mulelintrc.json
32
+ {
33
+ "include": ["src/main/mule/**/*.xml"],
34
+ "exclude": ["src/test/munit/**/*.xml"],
35
+ "qualityGate": {
36
+ "name": "Project Quality Gate",
37
+ "conditions": [
38
+ { "metric": "errors", "operator": ">", "threshold": 0, "status": "fail" },
39
+ { "metric": "warnings", "operator": ">", "threshold": 10, "status": "warn" }
40
+ ]
41
+ },
42
+ "rules": {
43
+ "MULE-001": {
44
+ "enabled": false,
45
+ "reason": "Global error handler in non-standard location — documented exception"
46
+ }
47
+ }
48
+ }
49
+ ```
50
+
51
+ **Rule suppression:** When disabling a rule, always include a `reason` or `comment` field explaining why. This documents the engineering decision for future reviewers.
52
+
53
+ ### Output Formats
54
+
55
+ | Format | Use Case | Command |
56
+ | -------- | ------------------------------- | ------------------------------------ |
57
+ | `pretty` | Local development | `mule-lint . -f pretty` |
58
+ | `json` | CI/CD parsing | `mule-lint . -f json` |
59
+ | `sarif` | GitHub Code Scanning, AI agents | `mule-lint . -f sarif -o lint.sarif` |
60
+ | `html` | Human review reports | `mule-lint . -f html -o report.html` |
61
+
62
+ ---
63
+
64
+ ## GitHub Actions Example
65
+
66
+ ```yaml
67
+ name: Mule CI/CD
68
+
69
+ on:
70
+ push:
71
+ branches: [main, develop]
72
+ pull_request:
73
+ branches: [main]
74
+
75
+ jobs:
76
+ build-and-test:
77
+ runs-on: ubuntu-latest
78
+ steps:
79
+ - uses: actions/checkout@v4
80
+
81
+ - name: Set up JDK 17
82
+ uses: actions/setup-java@v4
83
+ with:
84
+ java-version: '17'
85
+ distribution: 'temurin'
86
+
87
+ - name: Cache Maven packages
88
+ uses: actions/cache@v4
89
+ with:
90
+ path: ~/.m2
91
+ key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
92
+
93
+ - name: Build
94
+ run: mvn -B clean compile
95
+
96
+ - name: Run mule-lint
97
+ run: npx @sfdxy/mule-lint . -c .mulelintrc.json -f sarif -o lint.sarif
98
+
99
+ - name: Upload SARIF results
100
+ uses: github/codeql-action/upload-sarif@v3
101
+ with:
102
+ sarif_file: lint.sarif
103
+
104
+ - name: Run MUnit tests
105
+ run: mvn -B test -Dmule.env=dev -Dsecure.key=test
106
+ ```
107
+
108
+ ---
109
+
110
+ ## Git Branch Strategy
111
+
112
+ | Branch | Purpose | Deployment Target |
113
+ | ----------- | --------------------- | ----------------- |
114
+ | `main` | Production-ready code | Production |
115
+ | `develop` | Integration branch | QA/Staging |
116
+ | `feature/*` | New features | Development |
117
+ | `hotfix/*` | Production fixes | Production |
118
+
119
+ ---
120
+
121
+ ## Commit Messages
122
+
123
+ Follow [Conventional Commits](https://www.conventionalcommits.org/):
124
+
125
+ ```
126
+ feat: add new order processing logic
127
+ fix: resolve null pointer in mapping
128
+ docs: update README with deployment steps
129
+ chore: upgrade mule maven plugin
130
+ refactor: extract common DWL functions to module
131
+ ```
132
+
133
+ ---
134
+
135
+ **See also:** [Testing](testing.md) · [Deployment & Modernization](deployment-2026.md) · [Folder Structure](folder-structure.md)
@@ -0,0 +1,253 @@
1
+ # Connector Configuration Patterns
2
+
3
+ > **Applies to:** All (System APIs, Process APIs)
4
+ > **Related Rules:** `SEC-007` · `SEC-008` · `PERF-002` · `RES-001` · `RES-002` · `SF-001` · `SF-002`
5
+ > **Last Updated:** April 2026
6
+
7
+ ## When to Read This
8
+
9
+ Read this when configuring Salesforce, NetSuite, HTTP, or Database connectors in Mule 4. Covers connector attribute gotchas, the entity-config pattern, and protocol negotiation.
10
+
11
+ ---
12
+
13
+ ## Patterns
14
+
15
+ ### Pattern 1: Entity Configuration (YAML-Driven)
16
+
17
+ **Use when:** building a System API that supports multiple entity types (Account, Contact, Order, etc.) with consistent CRUD operations.
18
+
19
+ Instead of hardcoding entity-specific details in flow XML, externalize them to per-entity YAML files:
20
+
21
+ ```
22
+ src/main/resources/entity-config/
23
+ ├── account.yaml
24
+ ├── contact.yaml
25
+ ├── opportunity.yaml
26
+ └── order.yaml
27
+ ```
28
+
29
+ **Entity config structure:**
30
+
31
+ ```yaml
32
+ # entity-config/account.yaml
33
+ entity:
34
+ account:
35
+ sObjectType: 'Account'
36
+ enabled: true
37
+ externalIdField: 'NetSuite_ID__c'
38
+ queryFields: 'Id, Name, BillingStreet, BillingCity, Phone, Website'
39
+ queryTemplate: 'SELECT {fields} FROM Account WHERE {filter} LIMIT {limit}'
40
+ writeback:
41
+ netSuiteIdField: 'NetSuite_ID__c'
42
+ errorField: 'NetSuite_Error__c'
43
+ lastSyncField: 'Last_NetSuite_Sync__c'
44
+ ```
45
+
46
+ **Load in global-config.xml:**
47
+
48
+ ```xml
49
+ <configuration-properties doc:name="Account Config"
50
+ file="entity-config/account.yaml"/>
51
+ <configuration-properties doc:name="Contact Config"
52
+ file="entity-config/contact.yaml"/>
53
+ ```
54
+
55
+ **Benefits:**
56
+
57
+ - Add a new entity by creating a YAML file — no flow XML changes
58
+ - Entity behavior is visible, auditable, and environment-independent
59
+ - LLMs can read entity configs to understand available operations
60
+
61
+ ### Pattern 2: Salesforce JWT Connector
62
+
63
+ **Use when:** authenticating to Salesforce via OAuth 2.0 JWT Bearer flow.
64
+
65
+ ```xml
66
+ <salesforce:sfdc-config name="Salesforce_Config">
67
+ <salesforce:jwt-connection
68
+ consumerKey="${secure::salesforce.jwt.consumerKey}"
69
+ keyStore="${salesforce.jwt.keystorePath}"
70
+ storePassword="${secure::salesforce.jwt.storePassword}"
71
+ principal="${salesforce.jwt.principal}"
72
+ tokenEndpoint="${salesforce.jwt.tokenEndpoint}"
73
+ audienceUrl="${salesforce.jwt.audienceUrl}">
74
+ <reconnection>
75
+ <reconnect count="3" frequency="5000"/>
76
+ </reconnection>
77
+ </salesforce:jwt-connection>
78
+ </salesforce:sfdc-config>
79
+ ```
80
+
81
+ > ⚠️ **Gotchas** (common mistakes that cause runtime failures):
82
+ >
83
+ > | Incorrect | Correct | Notes |
84
+ > | ----------------------------------- | ------------------------ | ---------------------------------- |
85
+ > | `salesforce:jwt-connection-config` | `salesforce:sfdc-config` | Outer config element name |
86
+ > | `keyStorePath="..."` | `keyStore="..."` | JWT connection attribute |
87
+ > | `type="Account"` (on upsert) | `objectType="Account"` | Upsert operation attribute |
88
+ > | `type="Account"` (on create/update) | `type="Account"` | Create/Update use `type` (correct) |
89
+
90
+ ### Pattern 3: Protocol Negotiation (Dual-Protocol SAPI)
91
+
92
+ **Use when:** a System API must support both SOAP and REST protocols to the same backend (e.g., NetSuite).
93
+
94
+ The calling PAPI sends an `x-integration-protocol` header. The SAPI routes internally:
95
+
96
+ ```xml
97
+ <!-- common/netsuite-process-subflow.xml -->
98
+ <sub-flow name="netsuite-process-subflow">
99
+ <choice>
100
+ <when expression="#[vars.protocol == 'SOAP']">
101
+ <flow-ref name="netsuite-soap-upsert-subflow"/>
102
+ </when>
103
+ <when expression="#[vars.protocol == 'REST']">
104
+ <flow-ref name="netsuite-rest-upsert-subflow"/>
105
+ </when>
106
+ </choice>
107
+ </sub-flow>
108
+ ```
109
+
110
+ **Protocol support matrix:**
111
+
112
+ | Record Type | SOAP | REST |
113
+ | ----------- | ---- | -------------- |
114
+ | Customer | ✅ | ✅ |
115
+ | Contact | ✅ | ✅ |
116
+ | Sales Order | ✅ | ❌ (SOAP-only) |
117
+ | Credit Memo | ✅ | ❌ (SOAP-only) |
118
+
119
+ ### Pattern 4: HTTP Request Connector (with Pooling)
120
+
121
+ **Use when:** making outbound HTTP calls to downstream APIs.
122
+
123
+ ```xml
124
+ <http:request-config name="SAPI_HTTP_Config"
125
+ responseTimeout="${https.request.responseTimeout}">
126
+ <http:request-connection host="${https.request.host}"
127
+ port="${https.request.port}"
128
+ connectionIdleTimeout="${https.connection.idleTimeout}"
129
+ maxConnections="${https.connection.maxConnections}">
130
+ <reconnection>
131
+ <reconnect frequency="${reconnection.frequency}"
132
+ count="${reconnection.attempts}"/>
133
+ </reconnection>
134
+ </http:request-connection>
135
+ <!-- Set correlation ID once — applied to every request automatically -->
136
+ <http:default-headers>
137
+ <http:default-header key="X-Correlation-Id" value="#[correlationId]"/>
138
+ </http:default-headers>
139
+ </http:request-config>
140
+ ```
141
+
142
+ **Rules:**
143
+
144
+ - Always set `responseTimeout` (avoid hanging connections)
145
+ - Set `connectionIdleTimeout >= responseTimeout` (Grizzly kills connections if idle fires first)
146
+ - Configure connection pooling for production (`maxConnections`)
147
+
148
+ ### Pattern 5: Reconnection Strategies
149
+
150
+ **Use when:** configuring any connector that connects to an external system.
151
+
152
+ | Connector Type | Strategy | Example |
153
+ | -------------------------------------- | --------------------- | ---------------------------------- |
154
+ | **Event listeners** (SF, MQ) | `reconnect-forever` | Must auto-recover from disconnects |
155
+ | **Outbound connectors** (HTTP, SF, DB) | `reconnect count="3"` | Bounded retries with frequency |
156
+ | **HTTP Listener** | `reconnect-forever` | Server must always be up |
157
+
158
+ ```xml
159
+ <!-- Listener — always reconnect -->
160
+ <http:listener-config name="httpListenerConfig">
161
+ <http:listener-connection host="0.0.0.0" port="${http.port}">
162
+ <reconnection>
163
+ <reconnect-forever frequency="5000"/>
164
+ </reconnection>
165
+ </http:listener-connection>
166
+ </http:listener-config>
167
+
168
+ <!-- Outbound — bounded retries -->
169
+ <salesforce:sfdc-config name="Salesforce_Config">
170
+ <salesforce:jwt-connection ...>
171
+ <reconnection>
172
+ <reconnect count="3" frequency="5000"/>
173
+ </reconnection>
174
+ </salesforce:jwt-connection>
175
+ </salesforce:sfdc-config>
176
+ ```
177
+
178
+ ### Pattern 6: ObjectStore for Reference Data Caching
179
+
180
+ **Use when:** frequently-accessed reference data (customer records, config lookups) is fetched repeatedly during batch processing. Cache in ObjectStore with TTL to reduce API calls.
181
+
182
+ ```xml
183
+ <!-- global.xml — configure the cache store -->
184
+ <os:object-store name="customer-cache-store"
185
+ entryTtl="${customer.cache.ttl}"
186
+ expirationInterval="${customer.cache.expirationInterval}"
187
+ maxEntries="200"/>
188
+ ```
189
+
190
+ **Key rules:**
191
+
192
+ - Set `maxEntries` to prevent unbounded memory growth
193
+ - Set `entryTtl` appropriate to data volatility (e.g., 1 hour for customer data, 24 hours for country codes)
194
+ - Use `os:contains` + `os:retrieve` to check-then-get, not just `os:retrieve` with default (avoids computing defaults unnecessarily)
195
+
196
+ ---
197
+
198
+ ## DWL Utility Module: `parseAndConvert`
199
+
200
+ The Salesforce connector requires Java-typed values (DateTime, Date, Boolean) — not strings. Use a shared DWL module for type coercion:
201
+
202
+ ```dataweave
203
+ %dw 2.0
204
+ // dwl/modules/salesforceUtility.dwl
205
+
206
+ var dateTimePattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?(Z|[+-]\d{2}:\d{2})?$/
207
+ var dateOnlyPattern = /^\d{4}-\d{2}-\d{2}$/
208
+
209
+ fun parseAndConvert(obj: Object) =
210
+ obj mapObject ((value, key) ->
211
+ if ((value is String) and ((value as String) matches dateTimePattern))
212
+ (key): (value as String) as DateTime
213
+ else if ((value is String) and ((value as String) matches dateOnlyPattern))
214
+ (key): (value as String) as Date
215
+ else if ((value is String) and ((value as String) == ""))
216
+ (key): null
217
+ else if (value is Object)
218
+ (key): parseAndConvert(value)
219
+ else
220
+ (key): value
221
+ )
222
+ ```
223
+
224
+ **Usage in flow XML:**
225
+
226
+ ```xml
227
+ <ee:transform>
228
+ <ee:set-payload><![CDATA[%dw 2.0
229
+ import dwl::modules::salesforceUtility
230
+ output application/java
231
+ ---
232
+ salesforceUtility::parseAndConvert(payload)
233
+ ]]></ee:set-payload>
234
+ </ee:transform>
235
+ ```
236
+
237
+ > ⚠️ **DWL import path rule:** Always use the full path prefix `dwl::modules::moduleName`. Short paths like `modules::moduleName` will fail at runtime.
238
+
239
+ ---
240
+
241
+ ## Checklist
242
+
243
+ - [ ] Entity configs externalized to `entity-config/{entity}.yaml`
244
+ - [ ] All connector credentials use `${secure::...}` property placeholders
245
+ - [ ] Reconnection strategies configured on all connectors
246
+ - [ ] `responseTimeout` explicitly set on HTTP request configs
247
+ - [ ] No hardcoded connector attribute values (hosts, ports, keys)
248
+ - [ ] DWL modules imported with full `dwl::modules::` path prefix
249
+ - [ ] Salesforce payloads pass through `parseAndConvert()` before connector call
250
+
251
+ ---
252
+
253
+ **See also:** [Security](security.md) · [Performance](performance.md) · [DataWeave Patterns](dataweave-patterns.md)