@salesforce/metadata-plugins 1.13.0 → 1.14.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.
package/README.md CHANGED
@@ -11,13 +11,14 @@ This package provides metadata visualization plugins that parse Salesforce XML m
11
11
 
12
12
  ## Supported Metadata Types
13
13
 
14
- | Metadata Type | File Pattern | Plugin ID | Description |
15
- | -------------- | ------------------------------------------- | --------------- | ---------------------------------------------------------------------------------- |
16
- | FlexiPages | `.flexipage-meta.xml` | `flexipage` | Lightning Page layout visualization |
17
- | Data Model | `.object-meta.xml`, `.field-meta.xml` | `schema` | Interactive ERD visualization of objects, fields, and relationships |
18
- | Agent Script | `.agent` | `agent` | Agent script visualization |
19
- | Flow | `.flow-meta.xml` | `flow` | Interactive Flow diagram with decisions, loops, and fault paths |
20
- | Permission Set | `.permissionset-meta.xml`, `.permissionset` | `permissionset` | Permission set overview — object, field, tab, record-type, and named-access grants |
14
+ | Metadata Type | File Pattern | Plugin ID | Description |
15
+ | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
16
+ | FlexiPages | `.flexipage-meta.xml` | `flexipage` | Lightning Page layout visualization |
17
+ | Data Model | `.object-meta.xml`, `.field-meta.xml` | `schema` | Interactive ERD visualization of objects, fields, and relationships |
18
+ | Agent Script | `.agent` | `agent` | Agent script visualization |
19
+ | Flow | `.flow-meta.xml` | `flow` | Interactive Flow diagram with decisions, loops, and fault paths |
20
+ | Permission Set | `.permissionset-meta.xml`, `.permissionset` | `permissionset` | Permission set overview — object, field, tab, record-type, and named-access grants |
21
+ | Key-Value Table | `.md`, `.labels`, `.listView`, `.globalValueSetTranslation`, `.tab`, `.fieldSet`, `.profile`, `.workflowAlert`, `.customPermission`, `.globalValueSet`, `.standardValueSetTranslation`, `.reportFolder`, `.standardValueSet`, `.documentFolder`, `.emailFolder`, `.businessProcess`, `.fieldSrcTrgtRelationship`, `.webLink`, `.workflowFieldUpdate`, `.remoteSite`, `.compactLayout`, `.featureParameterInteger`, `.role`, `.group`, `.featureParameterBoolean`, `.sharingReason` (each followed by `-meta.xml`) | `keyvaluetable` | Overview, setting/value table and list tables for flat metadata such as custom metadata, labels, list views, value sets and folders |
21
22
 
22
23
  ## Installation
23
24
 
@@ -63,6 +64,7 @@ import {
63
64
  AgentVisualizer,
64
65
  FlowVisualizer,
65
66
  PermissionSetVisualizer,
67
+ KeyValueTableVisualizer,
66
68
  } from '@salesforce/metadata-plugins';
67
69
 
68
70
  const flexipageViz = new FlexipageVisualizer();
@@ -70,6 +72,7 @@ const schemaViz = new SchemaVisualizer();
70
72
  const agentViz = new AgentVisualizer();
71
73
  const flowViz = new FlowVisualizer();
72
74
  const permissionSetViz = new PermissionSetVisualizer();
75
+ const keyValueTableViz = new KeyValueTableVisualizer();
73
76
 
74
77
  // Check plugin metadata
75
78
  const info = schemaViz.getMetadataPluginInfo();
@@ -90,6 +93,7 @@ console.log(info.filePatterns); // ['.object-meta.xml', '.field-meta.xml']
90
93
  - **`AgentVisualizer`** — Implements `IVisualizationPlugin<AgentScriptData>` for Agent script metadata
91
94
  - **`FlowVisualizer`** — Implements `IVisualizationPlugin<FlowModel>` for Flow metadata
92
95
  - **`PermissionSetVisualizer`** — Implements `IVisualizationPlugin<PermissionSetData>` for Permission Set metadata
96
+ - **`KeyValueTableVisualizer`** — Implements `IVisualizationPlugin<KeyValueTableData>` for 26 flat metadata types (custom metadata, labels, list views, value sets, folders, ...)
93
97
 
94
98
  ### Parsers
95
99
 
@@ -98,6 +102,7 @@ console.log(info.filePatterns); // ['.object-meta.xml', '.field-meta.xml']
98
102
  - **`AgentParser`** — Implements `IMetadataParser<AgentScriptData>`
99
103
  - **`FlowParser`** — Implements `IMetadataParser<FlowModel>`
100
104
  - **`PermissionSetParser`** — Implements `IMetadataParser<PermissionSetData>`
105
+ - **`KeyValueTableParser`** — Implements `IMetadataParser<KeyValueTableData>`
101
106
 
102
107
  ### Types
103
108
 
@@ -106,6 +111,7 @@ console.log(info.filePatterns); // ['.object-meta.xml', '.field-meta.xml']
106
111
  - **`AgentScriptData`** — Parsed Agent script structure
107
112
  - **`FlowModel`** — Parsed Flow structure with nodes, connectors, and metadata
108
113
  - **`PermissionSetData`** — Parsed Permission Set structure with object, field, tab, record-type, and named-access grants
114
+ - **`KeyValueTableData`** — Parsed flat metadata: scalar `entries`, repeated-child `lists`, and nested `trees`
109
115
 
110
116
  ## Package Exports
111
117
 
@@ -117,6 +123,7 @@ import {
117
123
  AgentVisualizer,
118
124
  FlowVisualizer,
119
125
  PermissionSetVisualizer,
126
+ KeyValueTableVisualizer,
120
127
  getAllVisualizers,
121
128
  } from '@salesforce/metadata-plugins';
122
129
 
@@ -127,6 +134,7 @@ import {
127
134
  AgentParser,
128
135
  FlowParser,
129
136
  PermissionSetParser,
137
+ KeyValueTableParser,
130
138
  } from '@salesforce/metadata-plugins';
131
139
 
132
140
  // Types
@@ -136,6 +144,7 @@ import type {
136
144
  AgentScriptData,
137
145
  FlowModel,
138
146
  PermissionSetData,
147
+ KeyValueTableData,
139
148
  } from '@salesforce/metadata-plugins';
140
149
  ```
141
150
 
package/dist/index.d.ts CHANGED
@@ -10,18 +10,21 @@ export { AgentVisualizer } from './plugins/agent/AgentVisualizer.js';
10
10
  export { FlowVisualizer } from './plugins/flow/FlowVisualizer.js';
11
11
  export { PermissionSetVisualizer } from './plugins/permissionset/PermissionSetVisualizer.js';
12
12
  export { FlowIntentVisualizer } from './plugins/flowintent/FlowIntentVisualizer.js';
13
+ export { KeyValueTableVisualizer } from './plugins/keyvaluetable/KeyValueTableVisualizer.js';
13
14
  export { FlexipageParser } from './plugins/flexipage/FlexipageParser.js';
14
15
  export { SchemaParser } from './plugins/schema/SchemaParser.js';
15
16
  export { AgentParser } from './plugins/agent/AgentParser.js';
16
17
  export { FlowParser } from './plugins/flow/FlowParser.js';
17
18
  export { PermissionSetParser } from './plugins/permissionset/PermissionSetParser.js';
18
19
  export { FlowIntentParser } from './plugins/flowintent/FlowIntentParser.js';
20
+ export { KeyValueTableParser } from './plugins/keyvaluetable/KeyValueTableParser.js';
19
21
  export type { FlexipageMetadata } from './plugins/flexipage/types/FlexipageMetadata.js';
20
22
  export type { SchemaERDData } from './plugins/schema/types/SchemaERDData.js';
21
23
  export type { AgentScriptData } from './plugins/agent/types/AgentScriptData.js';
22
24
  export type { FlowModel } from './plugins/flow/types/FlowData.js';
23
25
  export type { PermissionSetData } from './plugins/permissionset/types/PermissionSetData.js';
24
26
  export type { IntentFlow } from './plugins/flowintent/types/index.js';
27
+ export type { KeyValueTableData } from './plugins/keyvaluetable/types/KeyValueTableData.js';
25
28
  import { IVisualizationPlugin, PluginConfig } from '@salesforce/metadata-core-sdk';
26
29
  /**
27
30
  * Get all visualization plugins
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAsBJ,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,MAAM,oDAAoD,CAAC;AAC7F,OAAO,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,CAAC;AAGpF,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AACrF,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAG5E,YAAY,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AACxF,YAAY,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAC7E,YAAY,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAChF,YAAY,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAClE,YAAY,EAAE,iBAAiB,EAAE,MAAM,oDAAoD,CAAC;AAC5F,YAAY,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AAGtE,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEnF;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,oBAAoB,EAAE,CAmB/E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAuBJ,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,MAAM,oDAAoD,CAAC;AAC7F,OAAO,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,CAAC;AACpF,OAAO,EAAE,uBAAuB,EAAE,MAAM,oDAAoD,CAAC;AAG7F,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AACrF,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AAGrF,YAAY,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AACxF,YAAY,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAC7E,YAAY,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAChF,YAAY,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAClE,YAAY,EAAE,iBAAiB,EAAE,MAAM,oDAAoD,CAAC;AAC5F,YAAY,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACtE,YAAY,EAAE,iBAAiB,EAAE,MAAM,oDAAoD,CAAC;AAG5F,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEnF;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,oBAAoB,EAAE,CAoB/E"}
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ import { AgentVisualizer } from './plugins/agent/AgentVisualizer.js';
21
21
  import { FlowVisualizer } from './plugins/flow/FlowVisualizer.js';
22
22
  import { PermissionSetVisualizer } from './plugins/permissionset/PermissionSetVisualizer.js';
23
23
  import { FlowIntentVisualizer } from './plugins/flowintent/FlowIntentVisualizer.js';
24
+ import { KeyValueTableVisualizer } from './plugins/keyvaluetable/KeyValueTableVisualizer.js';
24
25
  // Export visualization plugins
25
26
  export { FlexipageVisualizer } from './plugins/flexipage/FlexipageVisualizer.js';
26
27
  export { SchemaVisualizer } from './plugins/schema/SchemaVisualizer.js';
@@ -28,6 +29,7 @@ export { AgentVisualizer } from './plugins/agent/AgentVisualizer.js';
28
29
  export { FlowVisualizer } from './plugins/flow/FlowVisualizer.js';
29
30
  export { PermissionSetVisualizer } from './plugins/permissionset/PermissionSetVisualizer.js';
30
31
  export { FlowIntentVisualizer } from './plugins/flowintent/FlowIntentVisualizer.js';
32
+ export { KeyValueTableVisualizer } from './plugins/keyvaluetable/KeyValueTableVisualizer.js';
31
33
  // Export parsers
32
34
  export { FlexipageParser } from './plugins/flexipage/FlexipageParser.js';
33
35
  export { SchemaParser } from './plugins/schema/SchemaParser.js';
@@ -35,6 +37,7 @@ export { AgentParser } from './plugins/agent/AgentParser.js';
35
37
  export { FlowParser } from './plugins/flow/FlowParser.js';
36
38
  export { PermissionSetParser } from './plugins/permissionset/PermissionSetParser.js';
37
39
  export { FlowIntentParser } from './plugins/flowintent/FlowIntentParser.js';
40
+ export { KeyValueTableParser } from './plugins/keyvaluetable/KeyValueTableParser.js';
38
41
  /**
39
42
  * Get all visualization plugins
40
43
  *
@@ -53,6 +56,7 @@ export function getAllVisualizers(config) {
53
56
  new FlowVisualizer(),
54
57
  new PermissionSetVisualizer(),
55
58
  new FlowIntentVisualizer(),
59
+ new KeyValueTableVisualizer(),
56
60
  ];
57
61
  if (!config?.pluginSettings) {
58
62
  return all;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Copyright (c) 2026, Salesforce, Inc.
3
+ * All rights reserved.
4
+ * Licensed under the BSD 3-Clause license.
5
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
+ **/
7
+ import { IMetadataParser, MetadataFileInfo, ValidationResult, IPlatformContext, SalesforceXMLParser, VersionInfo } from '@salesforce/metadata-core-sdk';
8
+ import { KeyValueTableData } from './types/KeyValueTableData.js';
9
+ /**
10
+ * Decode predefined XML entities and numeric character references.
11
+ * `SalesforceXMLParser` runs with `processEntities: false`, so text arrives still
12
+ * encoded (a WebLink's `&amp;` in a URL, JavaScript with `&lt;`). Single pass, so
13
+ * `&amp;lt;` becomes `&lt;`.
14
+ */
15
+ export declare function decodeEntities(text: string): string;
16
+ /** Attribute / text-node keys the XML parser adds alongside real elements. */
17
+ export declare function isAttributeKey(key: string): boolean;
18
+ /** Flatten an XML value to display text; undefined when it has nothing to show. */
19
+ export declare function toText(value: unknown): string | undefined;
20
+ export declare function basename(filePath: string): string;
21
+ export declare class KeyValueTableParser implements IMetadataParser<KeyValueTableData> {
22
+ private platformContext?;
23
+ private logger?;
24
+ private telemetry?;
25
+ readonly xmlParser: SalesforceXMLParser;
26
+ setPlatformContext(context: IPlatformContext): void;
27
+ parse(filePath: string, _versionInfo: VersionInfo): Promise<KeyValueTableData>;
28
+ extractMetadataInfo(data: KeyValueTableData): MetadataFileInfo | null;
29
+ validate(data: KeyValueTableData): ValidationResult;
30
+ private transform;
31
+ private deriveStatus;
32
+ /** ".../objects/Book__c/webLinks/X.webLink-meta.xml" (or fieldSets/, listViews/, ...) → "Book__c" */
33
+ private deriveObjectName;
34
+ private buildList;
35
+ }
36
+ //# sourceMappingURL=KeyValueTableParser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyValueTableParser.d.ts","sourceRoot":"","sources":["../../../src/plugins/keyvaluetable/KeyValueTableParser.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAYJ,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAGhB,mBAAmB,EACnB,WAAW,EAGZ,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAGL,iBAAiB,EAIlB,MAAM,8BAA8B,CAAC;AA+EtC;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAWnD;AAED,8EAA8E;AAC9E,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEnD;AAOD,mFAAmF;AACnF,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CA2BzD;AAED,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEjD;AA6HD,qBAAa,mBAAoB,YAAW,eAAe,CAAC,iBAAiB,CAAC;IAC5E,OAAO,CAAC,eAAe,CAAC,CAAmB;IAC3C,OAAO,CAAC,MAAM,CAAC,CAAU;IACzB,OAAO,CAAC,SAAS,CAAC,CAAa;IAG/B,QAAQ,CAAC,SAAS,sBAAqD;IAEvE,kBAAkB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI;IAM7C,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA8EpF,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,gBAAgB,GAAG,IAAI;IAIrE,QAAQ,CAAC,IAAI,EAAE,iBAAiB,GAAG,gBAAgB;IAUnD,OAAO,CAAC,SAAS;IAyGjB,OAAO,CAAC,YAAY;IASpB,qGAAqG;IACrG,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,SAAS;CAqBlB"}
@@ -0,0 +1,429 @@
1
+ /**
2
+ * Copyright (c) 2026, Salesforce, Inc.
3
+ * All rights reserved.
4
+ * Licensed under the BSD 3-Clause license.
5
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
+ **/
7
+ /**
8
+ * Key/value + list metadata parser.
9
+ *
10
+ * Maps the root element's top-level children to key/value entries. Nothing is
11
+ * configured per metadata type: the layout is inferred from the XML. Repeated object
12
+ * children become tables (one column per distinct child key), a wide lone object
13
+ * becomes a Field / Value table, and anything nested deeper becomes a tree.
14
+ */
15
+ import { humanize } from './humanize.js';
16
+ import { SalesforceXMLParser, ErrorBuilder, ErrorCategory, } from '@salesforce/metadata-core-sdk';
17
+ import { isPluginError } from '../../shared/utils/isPluginError.js';
18
+ /** A lone object with more keys than this reads better as a Field / Value table than as one wide row. */
19
+ const MAX_ROW_COLUMNS = 4;
20
+ /**
21
+ * Root element names of the metadata types this plugin claims. `metadataType` comes
22
+ * from the file's own root element, so only these values may reach telemetry or logs.
23
+ */
24
+ const KNOWN_METADATA_TYPES = new Set([
25
+ 'CustomMetadata',
26
+ 'CustomPermission',
27
+ 'CustomTab',
28
+ 'FieldSet',
29
+ 'GlobalValueSet',
30
+ 'CustomLabels',
31
+ 'ListView',
32
+ 'StandardValueSet',
33
+ 'GlobalValueSetTranslation',
34
+ 'StandardValueSetTranslation',
35
+ 'WorkflowAlert',
36
+ 'BusinessProcess',
37
+ 'WebLink',
38
+ 'RemoteSiteSetting',
39
+ 'FieldSrcTrgtRelationship',
40
+ 'SharingReason',
41
+ 'FeatureParameterInteger',
42
+ 'FeatureParameterBoolean',
43
+ 'CompactLayout',
44
+ 'Role',
45
+ 'Group',
46
+ 'Profile',
47
+ 'ReportFolder',
48
+ 'DocumentFolder',
49
+ 'EmailFolder',
50
+ 'WorkflowFieldUpdate',
51
+ ]);
52
+ /** Telemetry-safe metadata type: the known root name, or `unknown`. */
53
+ function telemetryMetadataType(metadataType) {
54
+ return KNOWN_METADATA_TYPES.has(metadataType) ? metadataType : 'unknown';
55
+ }
56
+ /** Fixed `parse_error` reason from the error category — never the message text. */
57
+ function errorReason(error) {
58
+ if (!isPluginError(error)) {
59
+ return 'unexpected';
60
+ }
61
+ switch (error.category) {
62
+ case ErrorCategory.Dependency:
63
+ return 'read_failed';
64
+ case ErrorCategory.Parsing:
65
+ return 'parse_failed';
66
+ default:
67
+ return 'unexpected';
68
+ }
69
+ }
70
+ const XML_ENTITIES = {
71
+ lt: '<',
72
+ gt: '>',
73
+ amp: '&',
74
+ quot: '"',
75
+ apos: "'",
76
+ };
77
+ /**
78
+ * Decode predefined XML entities and numeric character references.
79
+ * `SalesforceXMLParser` runs with `processEntities: false`, so text arrives still
80
+ * encoded (a WebLink's `&amp;` in a URL, JavaScript with `&lt;`). Single pass, so
81
+ * `&amp;lt;` becomes `&lt;`.
82
+ */
83
+ export function decodeEntities(text) {
84
+ return text.replace(/&(?:#(\d+)|#x([0-9a-fA-F]+)|(lt|gt|amp|quot|apos));/g, (m, dec, hex, name) => {
85
+ if (name) {
86
+ return XML_ENTITIES[name];
87
+ }
88
+ const code = dec !== undefined ? parseInt(dec, 10) : parseInt(hex ?? '', 16);
89
+ return code <= 0x10ffff ? String.fromCodePoint(code) : m;
90
+ });
91
+ }
92
+ /** Attribute / text-node keys the XML parser adds alongside real elements. */
93
+ export function isAttributeKey(key) {
94
+ return key.startsWith('@_') || key === '#text' || key.startsWith('?');
95
+ }
96
+ /** True when the object holds at least one child element (not just attributes / text). */
97
+ function hasElementChildren(obj) {
98
+ return Object.keys(obj).some((k) => !isAttributeKey(k));
99
+ }
100
+ /** Flatten an XML value to display text; undefined when it has nothing to show. */
101
+ export function toText(value) {
102
+ if (typeof value === 'string') {
103
+ return decodeEntities(value).trim() || undefined;
104
+ }
105
+ if (typeof value === 'number' || typeof value === 'boolean') {
106
+ return String(value);
107
+ }
108
+ if (Array.isArray(value)) {
109
+ const parts = value.map(toText).filter((v) => v !== undefined);
110
+ return parts.length ? parts.join(', ') : undefined;
111
+ }
112
+ if (value && typeof value === 'object') {
113
+ const obj = value;
114
+ // `<url xml:lang="en">text</url>`: attributes plus text, no child elements.
115
+ if (!hasElementChildren(obj) && '#text' in obj) {
116
+ return toText(obj['#text']);
117
+ }
118
+ const lines = Object.entries(obj)
119
+ .filter(([k]) => !isAttributeKey(k))
120
+ .map(([k, v]) => {
121
+ const text = toText(v);
122
+ return text === undefined ? undefined : `${k}: ${text}`;
123
+ })
124
+ .filter((v) => v !== undefined);
125
+ return lines.length ? lines.join('\n') : undefined;
126
+ }
127
+ return undefined;
128
+ }
129
+ export function basename(filePath) {
130
+ return filePath.split(/[\\/]/).pop() ?? filePath;
131
+ }
132
+ /** One XML value as a table cell text; nested elements fall back to `key: value` lines. */
133
+ function cell(value) {
134
+ return toText(value) ?? '';
135
+ }
136
+ /** First non-empty text among the given XML values (label, masterLabel, name, ...). */
137
+ function firstText(...values) {
138
+ return values.map(cell).find((v) => v !== '');
139
+ }
140
+ function toArray(value) {
141
+ return value === undefined || value === null ? [] : Array.isArray(value) ? value : [value];
142
+ }
143
+ /** Levels and nodes rendered per tree; recursive types (Report blocks, bot steps) hit these, not the end. */
144
+ const MAX_TREE_DEPTH = 10;
145
+ const MAX_TREE_NODES = 1500;
146
+ /** 0 for text, 1 for an element of text children, 2 once an element holds another element, ... */
147
+ function depthOf(value, level = 0) {
148
+ if (level > MAX_TREE_DEPTH) {
149
+ return level;
150
+ }
151
+ if (Array.isArray(value)) {
152
+ return value.reduce((max, v) => Math.max(max, depthOf(v, level)), 0);
153
+ }
154
+ if (value && typeof value === 'object') {
155
+ const kids = Object.entries(value).filter(([k]) => !isAttributeKey(k));
156
+ // `<x xml:lang="en">text</x>`: attributes plus text is a scalar, not a nested element.
157
+ if (kids.length === 0 && '#text' in value) {
158
+ return 0;
159
+ }
160
+ return 1 + kids.reduce((max, [, v]) => Math.max(max, depthOf(v, level + 1)), 0);
161
+ }
162
+ return 0;
163
+ }
164
+ function summaryOf(obj) {
165
+ return firstText(obj.name, obj.label, obj.fullName, obj.masterLabel, obj.apiName, obj.field, obj.title, obj.header, obj.developerName);
166
+ }
167
+ function buildTreeNodes(key, raw, level, budget) {
168
+ if (Array.isArray(raw)) {
169
+ return raw.flatMap((item) => buildTreeNodes(key, item, level, budget));
170
+ }
171
+ if (budget.left <= 0) {
172
+ budget.truncated = true;
173
+ return [];
174
+ }
175
+ budget.left -= 1;
176
+ if (!raw || typeof raw !== 'object') {
177
+ const value = toText(raw);
178
+ return value === undefined ? [] : [{ key, value }];
179
+ }
180
+ const obj = raw;
181
+ if (!hasElementChildren(obj)) {
182
+ const value = toText(obj);
183
+ return value === undefined ? [] : [{ key, value }];
184
+ }
185
+ const node = { key, summary: summaryOf(obj) };
186
+ const entries = Object.entries(obj).filter(([k]) => !isAttributeKey(k));
187
+ if (level >= MAX_TREE_DEPTH) {
188
+ // Too deep to expand further: keep this element's own fields, drop nested elements.
189
+ node.children = entries
190
+ .filter(([, v]) => depthOf(v) === 0)
191
+ .flatMap(([k, v]) => buildTreeNodes(k, v, level + 1, budget));
192
+ node.truncated = true;
193
+ budget.truncated = true;
194
+ return [node];
195
+ }
196
+ node.children = entries.flatMap(([k, v]) => buildTreeNodes(k, v, level + 1, budget));
197
+ return [node];
198
+ }
199
+ function buildTree(element, raw) {
200
+ const budget = { left: MAX_TREE_NODES, truncated: false };
201
+ const nodes = buildTreeNodes(element, raw, 1, budget);
202
+ return {
203
+ title: humanize(element),
204
+ nodes,
205
+ nodeCount: MAX_TREE_NODES - budget.left,
206
+ truncated: budget.truncated,
207
+ };
208
+ }
209
+ /** Table layout for a repeated element: one column per distinct child key, in first-seen order. */
210
+ function tableSpecFor(element, items) {
211
+ const keys = [];
212
+ for (const item of items) {
213
+ if (item && typeof item === 'object') {
214
+ for (const k of Object.keys(item)) {
215
+ if (!isAttributeKey(k) && !keys.includes(k)) {
216
+ keys.push(k);
217
+ }
218
+ }
219
+ }
220
+ }
221
+ return {
222
+ element,
223
+ title: humanize(element),
224
+ columns: keys.length
225
+ ? keys.map((k) => ({ header: humanize(k), key: k }))
226
+ : [{ header: humanize(element) }],
227
+ };
228
+ }
229
+ export class KeyValueTableParser {
230
+ constructor() {
231
+ // Keep every value as text: `005xx...`-style IDs and `007` must not become numbers.
232
+ this.xmlParser = new SalesforceXMLParser({ parseTagValue: false });
233
+ }
234
+ setPlatformContext(context) {
235
+ this.platformContext = context;
236
+ this.logger = context.logger.createChild('KeyValueTableParser');
237
+ this.telemetry = context.telemetry.createChild({ component: 'KeyValueTableParser' });
238
+ }
239
+ async parse(filePath, _versionInfo) {
240
+ const fileName = basename(filePath);
241
+ if (!this.platformContext) {
242
+ throw ErrorBuilder.create()
243
+ .category(ErrorCategory.Configuration)
244
+ .message('KeyValueTableParser not initialized with platform context')
245
+ .context({ fileName })
246
+ .build();
247
+ }
248
+ const ctx = this.platformContext;
249
+ const log = this.logger ?? ctx.logger.createChild('KeyValueTableParser');
250
+ const telemetry = this.telemetry ?? ctx.telemetry.createChild({ component: 'KeyValueTableParser' });
251
+ return telemetry.withSpan('keyvaluetable.parse', async (span) => {
252
+ try {
253
+ const readResult = await ctx.fileSystem.readFile(filePath);
254
+ if (!readResult.success || !readResult.data) {
255
+ throw ErrorBuilder.create()
256
+ .category(ErrorCategory.Dependency)
257
+ .message(`Failed to read file: ${readResult.error?.message ?? 'file is empty or unreadable'}`)
258
+ .context({ fileName })
259
+ .build();
260
+ }
261
+ span.setAttribute('sourceLength', String(readResult.data.length));
262
+ const data = this.transform(readResult.data, filePath);
263
+ data.filePath = filePath;
264
+ // Counts and allowlisted names only — customer-authored names and values never
265
+ // reach telemetry or logs.
266
+ const metadataType = telemetryMetadataType(data.metadataType);
267
+ const entryCount = data.metadata.entryCount;
268
+ const listRowCount = data.lists.reduce((n, l) => n + l.rows.length, 0);
269
+ // A file with nothing in it is legitimate but worth tracking, so a regression in
270
+ // layout inference doesn't hide behind it.
271
+ if (entryCount === 0 && listRowCount === 0 && !data.trees?.length) {
272
+ telemetry.sendEvent('keyvaluetable.parse_incomplete', { pluginId: 'keyvaluetable', metadataType, reason: 'no_entries' }, { entryCount, listRowCount });
273
+ log.warn(`Parsed ${metadataType} with no entries or rows`);
274
+ }
275
+ telemetry.sendEvent('keyvaluetable.parse_complete', { pluginId: 'keyvaluetable', metadataType }, { entryCount, listRowCount });
276
+ log.info(`Parsed ${metadataType} (entries=${entryCount})`);
277
+ return data;
278
+ }
279
+ catch (error) {
280
+ telemetry.sendEvent('keyvaluetable.parse_error', { pluginId: 'keyvaluetable', reason: errorReason(error) }, {});
281
+ if (isPluginError(error)) {
282
+ throw error;
283
+ }
284
+ throw ErrorBuilder.create()
285
+ .category(ErrorCategory.Parsing)
286
+ .message(error instanceof Error ? error.message : String(error))
287
+ .context({ fileName })
288
+ .build();
289
+ }
290
+ }, { pluginId: 'keyvaluetable' });
291
+ }
292
+ extractMetadataInfo(data) {
293
+ return data.apiName ? { label: data.title } : null;
294
+ }
295
+ validate(data) {
296
+ const warnings = [];
297
+ if (data.status && !data.status.active) {
298
+ warnings.push(`${data.apiName}: ${data.metadataTypeLabel} is inactive`);
299
+ }
300
+ return { valid: true, errors: [], warnings };
301
+ }
302
+ // ─── Private helpers ───────────────────────────────────────────────
303
+ transform(xmlContent, filePath) {
304
+ const fileName = basename(filePath);
305
+ let parsed;
306
+ try {
307
+ parsed = this.xmlParser.parse(xmlContent);
308
+ }
309
+ catch {
310
+ throw ErrorBuilder.create()
311
+ .category(ErrorCategory.Parsing)
312
+ .message('Invalid XML in metadata file')
313
+ .context({ fileName })
314
+ .build();
315
+ }
316
+ const metadataType = Object.keys(parsed).find((k) => !isAttributeKey(k));
317
+ // A self-closed root (`<WebLink/>`) parses to '': a valid file with nothing in it.
318
+ const root = metadataType
319
+ ? parsed[metadataType] === ''
320
+ ? {}
321
+ : parsed[metadataType]
322
+ : undefined;
323
+ if (!metadataType || !root || typeof root !== 'object' || Array.isArray(root)) {
324
+ throw ErrorBuilder.create()
325
+ .category(ErrorCategory.Parsing)
326
+ .message('Invalid metadata: expected a single root element with child elements')
327
+ .context({ fileName })
328
+ .build();
329
+ }
330
+ const fields = root;
331
+ const entries = [];
332
+ const trees = [];
333
+ const lists = [];
334
+ const objectLists = [];
335
+ for (const [key, raw] of Object.entries(fields)) {
336
+ if (isAttributeKey(key)) {
337
+ continue;
338
+ }
339
+ if (depthOf(raw) > 1) {
340
+ trees.push(buildTree(key, raw));
341
+ continue;
342
+ }
343
+ if (raw &&
344
+ typeof raw === 'object' &&
345
+ !Array.isArray(raw) &&
346
+ hasElementChildren(raw)) {
347
+ const obj = raw;
348
+ const keys = Object.keys(obj).filter((k) => !isAttributeKey(k));
349
+ // A narrow lone object is a one-row table, so it looks the same whether the file has one
350
+ // or two of them (`values`). Field / Value rows fit better when it is wide (`loginHours`),
351
+ // repeats a child (`sharedTo`'s `<role>`s) or holds only empty children (`<allInternalUsers/>`).
352
+ const asFieldValue = keys.length > MAX_ROW_COLUMNS ||
353
+ keys.some((k) => Array.isArray(obj[k])) ||
354
+ keys.every((k) => cell(obj[k]) === '');
355
+ if (!asFieldValue) {
356
+ lists.push(this.buildList(tableSpecFor(key, [raw]), raw));
357
+ continue;
358
+ }
359
+ const rows = keys.flatMap((k) => toArray(obj[k]).map((item) => [humanize(k), cell(item)]));
360
+ objectLists.push({ title: humanize(key), columns: ['Field', 'Value'], rows });
361
+ continue;
362
+ }
363
+ // Several objects or several plain values of one element read best as a table.
364
+ if (Array.isArray(raw) &&
365
+ (raw.length > 1 || raw.some((item) => item && typeof item === 'object'))) {
366
+ lists.push(this.buildList(tableSpecFor(key, raw), raw));
367
+ continue;
368
+ }
369
+ const value = toText(raw);
370
+ if (value !== undefined) {
371
+ entries.push({ key, value });
372
+ }
373
+ }
374
+ const nonEmptyLists = lists.filter((l) => l.rows.length > 0);
375
+ nonEmptyLists.push(...objectLists);
376
+ // `Name.suffix-meta.xml` → `Name`; the name itself may contain dots (custom metadata records).
377
+ const baseName = basename(filePath);
378
+ const fileBase = /\.[^.]+-meta\.xml$/.test(baseName)
379
+ ? baseName.replace(/\.[^.]+-meta\.xml$/, '')
380
+ : baseName.replace(/\.[^.]+$/, '');
381
+ const apiName = toText(fields.fullName) ?? fileBase;
382
+ return {
383
+ apiName,
384
+ filePath,
385
+ metadataType,
386
+ metadataTypeLabel: humanize(metadataType),
387
+ objectName: this.deriveObjectName(filePath),
388
+ title: firstText(fields.label, fields.masterLabel, fields.name, fields.fullName) ?? fileBase,
389
+ description: toText(fields.description),
390
+ status: this.deriveStatus(fields),
391
+ license: firstText(fields.license, fields.userLicense),
392
+ entries,
393
+ lists: nonEmptyLists,
394
+ ...(trees.length ? { trees } : {}),
395
+ metadata: { parsedAt: new Date().toISOString(), entryCount: entries.length },
396
+ };
397
+ }
398
+ deriveStatus(fields) {
399
+ const raw = toText(fields.isActive);
400
+ if (raw === undefined) {
401
+ return undefined;
402
+ }
403
+ const active = raw.toLowerCase() === 'true';
404
+ return { label: active ? 'Active' : 'Inactive', active };
405
+ }
406
+ /** ".../objects/Book__c/webLinks/X.webLink-meta.xml" (or fieldSets/, listViews/, ...) → "Book__c" */
407
+ deriveObjectName(filePath) {
408
+ return (filePath.match(/[\\/]objects[\\/]([^\\/]+)[\\/](?:fieldSets|listViews|businessProcesses|webLinks|sharingReasons|compactLayouts)[\\/]/)?.[1] ?? filePath.match(/[\\/]workflows[\\/]([^\\/]+)[\\/]/)?.[1]);
409
+ }
410
+ buildList(spec, raw) {
411
+ const columns = spec.columns.map((c) => c.header);
412
+ const rows = toArray(raw)
413
+ .map((item) => spec.columns.map((c, i) => {
414
+ if (c.key && item && typeof item === 'object' && !Array.isArray(item)) {
415
+ return cell(item[c.key]);
416
+ }
417
+ // A bare string fills the first column only, not every column.
418
+ return c.key && i > 0 ? '' : cell(item);
419
+ }))
420
+ .filter((row) => row.some((v) => v !== ''));
421
+ // Drop columns no row fills, so a sparse union of keys stays readable.
422
+ const keep = spec.columns.map((_, i) => rows.some((r) => r[i] !== ''));
423
+ return {
424
+ title: spec.title,
425
+ columns: columns.filter((_, i) => keep[i]),
426
+ rows: rows.map((r) => r.filter((_, i) => keep[i])),
427
+ };
428
+ }
429
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Copyright (c) 2026, Salesforce, Inc.
3
+ * All rights reserved.
4
+ * Licensed under the BSD 3-Clause license.
5
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
+ **/
7
+ /**
8
+ * Key/Value Table Visualizer Plugin
9
+ *
10
+ * Flat metadata with optional repeated child lists, for the 26 file patterns below (the parser
11
+ * infers each file's layout from its XML, so a type needs only a pattern here): CustomMetadata, Custom Labels, List Views, Field Sets,
12
+ * Value Sets and their translations, Custom Tabs, Profiles, the Report/Document/Email Folders,
13
+ * Compact Layouts and the rest. Overview card, a Field / Value table for the scalar fields,
14
+ * and one table per repeated list.
15
+ */
16
+ import { IVisualizationPlugin, MetadataPluginInfo, IPlatformContext } from '@salesforce/metadata-core-sdk';
17
+ import { KeyValueTableData } from './types/KeyValueTableData.js';
18
+ import { KeyValueTableParser } from './KeyValueTableParser.js';
19
+ export declare class KeyValueTableVisualizer implements IVisualizationPlugin<KeyValueTableData> {
20
+ private readonly pluginMetadata;
21
+ readonly parser: KeyValueTableParser;
22
+ private logger?;
23
+ constructor();
24
+ getMetadataPluginInfo(): MetadataPluginInfo;
25
+ canHandle(filePath: string): boolean;
26
+ initialize(context: IPlatformContext): Promise<void>;
27
+ dispose?(): void;
28
+ }
29
+ //# sourceMappingURL=KeyValueTableVisualizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyValueTableVisualizer.d.ts","sourceRoot":"","sources":["../../../src/plugins/keyvaluetable/KeyValueTableVisualizer.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ;;;;;;;;GAQG;AAEH,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAEjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG/D,qBAAa,uBAAwB,YAAW,oBAAoB,CAAC,iBAAiB,CAAC;IACrF,OAAO,CAAC,QAAQ,CAAC,cAAc,CAoC7B;IAEF,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;IAErC,OAAO,CAAC,MAAM,CAAC,CAAU;;IAMzB,qBAAqB,IAAI,kBAAkB;IAI3C,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAM9B,UAAU,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAO1D,OAAO,CAAC,IAAI,IAAI;CAGjB"}