@salesforce/metadata-enrichment 0.0.6 → 0.0.7
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/lib/enrichment/constants/api.d.ts +33 -4
- package/lib/enrichment/constants/api.js +37 -9
- package/lib/enrichment/constants/api.js.map +1 -1
- package/lib/enrichment/constants/component.d.ts +4 -9
- package/lib/enrichment/constants/component.js +4 -12
- package/lib/enrichment/constants/component.js.map +1 -1
- package/lib/enrichment/constants/index.d.ts +3 -2
- package/lib/enrichment/constants/index.js +2 -2
- package/lib/enrichment/constants/index.js.map +1 -1
- package/lib/enrichment/constants/mimeTypes.js +7 -3
- package/lib/enrichment/constants/mimeTypes.js.map +1 -1
- package/lib/enrichment/enrichmentHandler.d.ts +5 -16
- package/lib/enrichment/enrichmentHandler.js +6 -13
- package/lib/enrichment/enrichmentHandler.js.map +1 -1
- package/lib/enrichment/enrichmentMetrics.d.ts +1 -1
- package/lib/enrichment/enrichmentMetrics.js +1 -1
- package/lib/enrichment/enrichmentMetrics.js.map +1 -1
- package/lib/enrichment/enrichmentRecords.d.ts +3 -4
- package/lib/enrichment/enrichmentRecords.js +7 -57
- package/lib/enrichment/enrichmentRecords.js.map +1 -1
- package/lib/enrichment/index.d.ts +3 -3
- package/lib/enrichment/index.js +2 -2
- package/lib/enrichment/index.js.map +1 -1
- package/lib/enrichment/types/requestTypes.d.ts +1 -1
- package/lib/files/fileProcessor.d.ts +11 -14
- package/lib/files/fileProcessor.js +109 -29
- package/lib/files/fileProcessor.js.map +1 -1
- package/lib/files/sourceComponentProcessor.d.ts +2 -2
- package/lib/files/sourceComponentProcessor.js +25 -7
- package/lib/files/sourceComponentProcessor.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/schemas/index.d.ts +2 -0
- package/lib/{enrichment/validators → schemas}/index.js +1 -1
- package/lib/schemas/index.js.map +1 -0
- package/lib/schemas/schemas.d.ts +47 -0
- package/lib/schemas/schemas.js +113 -0
- package/lib/schemas/schemas.js.map +1 -0
- package/package.json +5 -5
- package/lib/enrichment/validators/index.d.ts +0 -1
- package/lib/enrichment/validators/index.js.map +0 -1
- package/lib/enrichment/validators/lwcComponentValidator.d.ts +0 -8
- package/lib/enrichment/validators/lwcComponentValidator.js +0 -26
- package/lib/enrichment/validators/lwcComponentValidator.js.map +0 -1
- package/lib/files/lwcProcessor.d.ts +0 -14
- package/lib/files/lwcProcessor.js +0 -125
- package/lib/files/lwcProcessor.js.map +0 -1
|
@@ -13,36 +13,70 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { readFile } from 'node:fs/promises';
|
|
16
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
17
|
+
import { SfError } from '@salesforce/core';
|
|
18
|
+
import { Messages } from '@salesforce/core/messages';
|
|
19
|
+
import { XMLParser, XMLBuilder } from 'fast-xml-parser';
|
|
20
|
+
import { EnrichmentStatus, SUPPORTED_COMPONENT_TYPES, METADATA_TYPE_CONFIGS } from '../enrichment/constants/api.js';
|
|
21
|
+
import { DEFAULT_XML_METADATA_SCHEMA } from '../schemas/index.js';
|
|
17
22
|
import { getMimeTypeFromExtension } from '../enrichment/enrichmentHandler.js';
|
|
18
|
-
import
|
|
19
|
-
|
|
23
|
+
Messages.importMessagesDirectory(import.meta.dirname);
|
|
24
|
+
const messages = Messages.loadMessages('@salesforce/metadata-enrichment', 'errors');
|
|
20
25
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
const COMPONENT_TYPE_PROCESSOR_MAP = new Map([
|
|
25
|
-
[LWC_METADATA_TYPE_NAME, new LwcProcessor()],
|
|
26
|
-
]);
|
|
27
|
-
/**
|
|
28
|
-
* A main entryway for processing file operations for metadata files.
|
|
29
|
-
* This includes reading and writing component files.
|
|
30
|
-
* Supported component types are defined in SUPPORTED_COMPONENT_TYPES and each maps
|
|
31
|
-
* to a dedicated processor in COMPONENT_TYPE_PROCESSOR_MAP.
|
|
26
|
+
* A main entryway for processing metadata file operations
|
|
27
|
+
* with support for reading from and writing to component files.
|
|
28
|
+
* All supported component types write enrichment results to their xml metadata file (component.xml).
|
|
32
29
|
*/
|
|
33
30
|
export class FileProcessor {
|
|
34
31
|
static async updateMetadata(componentsToProcess, enrichmentRecords) {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
if (!SUPPORTED_COMPONENT_TYPES.has(
|
|
32
|
+
for (const component of componentsToProcess) {
|
|
33
|
+
// Skip if unsupported component type
|
|
34
|
+
if (!SUPPORTED_COMPONENT_TYPES.has(component.type?.name ?? '')) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
// Skip if source component is missing name or metadata file location
|
|
38
|
+
const componentName = component.fullName ?? component.name;
|
|
39
|
+
if (!componentName || !component.xml) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
// Find the enrichment record matching the source component
|
|
43
|
+
let enrichmentRecord;
|
|
44
|
+
for (const record of enrichmentRecords) {
|
|
45
|
+
if (record.componentName === componentName) {
|
|
46
|
+
enrichmentRecord = record;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Skip if for some reason the enrichment record is missing a response
|
|
51
|
+
if (!enrichmentRecord?.response) {
|
|
38
52
|
continue;
|
|
39
53
|
}
|
|
40
|
-
const
|
|
41
|
-
if (!
|
|
54
|
+
const enrichmentResult = enrichmentRecord.response.results[0];
|
|
55
|
+
if (!enrichmentResult) {
|
|
42
56
|
continue;
|
|
43
57
|
}
|
|
44
58
|
// eslint-disable-next-line no-await-in-loop
|
|
45
|
-
|
|
59
|
+
const fileResult = await FileProcessor.readComponentFile(componentName, component.xml);
|
|
60
|
+
if (!fileResult) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const componentTypeName = component.type?.name ?? '';
|
|
64
|
+
// Skip processing if <skipUplift> tag is set to true
|
|
65
|
+
if (FileProcessor.isSkipUpliftEnabled(fileResult.fileContents, componentTypeName)) {
|
|
66
|
+
enrichmentRecord.message = 'skipUplift is set to true';
|
|
67
|
+
enrichmentRecord.status = EnrichmentStatus.SKIPPED;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
// Write to component's metadata XML file
|
|
71
|
+
try {
|
|
72
|
+
const updatedXml = FileProcessor.updateMetaXml(fileResult.fileContents, enrichmentResult, componentTypeName);
|
|
73
|
+
// eslint-disable-next-line no-await-in-loop
|
|
74
|
+
await writeFile(component.xml, updatedXml, 'utf-8');
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
78
|
+
enrichmentRecord.message = errorMessage;
|
|
79
|
+
}
|
|
46
80
|
}
|
|
47
81
|
return enrichmentRecords;
|
|
48
82
|
}
|
|
@@ -66,20 +100,66 @@ export class FileProcessor {
|
|
|
66
100
|
if (!componentName) {
|
|
67
101
|
return [];
|
|
68
102
|
}
|
|
69
|
-
|
|
103
|
+
let filePaths = Array.from(component.walkContent());
|
|
104
|
+
// Some component types (e.g. FlexiPage) have no separate content files —
|
|
105
|
+
// their definition lives entirely in the XML metadata file.
|
|
106
|
+
if (filePaths.length === 0 && component.xml) {
|
|
107
|
+
filePaths = [component.xml];
|
|
108
|
+
}
|
|
70
109
|
const fileReadPromises = filePaths.map((filePath) => FileProcessor.readComponentFile(componentName, filePath));
|
|
71
110
|
const fileResults = await Promise.all(fileReadPromises);
|
|
72
111
|
return fileResults.filter((result) => result !== null);
|
|
73
112
|
}
|
|
74
|
-
static
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
113
|
+
static updateMetaXml(xmlContent, result, componentTypeName) {
|
|
114
|
+
const parser = new XMLParser({
|
|
115
|
+
htmlEntities: true,
|
|
116
|
+
ignoreAttributes: false,
|
|
117
|
+
processEntities: false,
|
|
118
|
+
trimValues: true,
|
|
119
|
+
});
|
|
120
|
+
const builder = new XMLBuilder({
|
|
121
|
+
format: true,
|
|
122
|
+
ignoreAttributes: false,
|
|
123
|
+
processEntities: false,
|
|
124
|
+
});
|
|
125
|
+
try {
|
|
126
|
+
const xmlObj = parser.parse(xmlContent);
|
|
127
|
+
const rootKey = Object.keys(xmlObj).find((k) => k !== '?xml');
|
|
128
|
+
if (!rootKey) {
|
|
129
|
+
throw new SfError(messages.getMessage('errors.parsing.xml', [result.resourceName]));
|
|
130
|
+
}
|
|
131
|
+
if (!xmlObj[rootKey]) {
|
|
132
|
+
xmlObj[rootKey] = {};
|
|
133
|
+
}
|
|
134
|
+
const schema = (componentTypeName ? METADATA_TYPE_CONFIGS[componentTypeName]?.xmlSchema : undefined) ?? DEFAULT_XML_METADATA_SCHEMA;
|
|
135
|
+
schema.applyEnrichment(xmlObj[rootKey], result);
|
|
136
|
+
const builtXml = builder.build(xmlObj);
|
|
137
|
+
return builtXml.trim().replace(/\n{3,}/g, '\n\n');
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
throw new SfError(messages.getMessage('errors.parsing.xml', [error instanceof Error ? error.message : String(error)]));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Checks if the component has opted out of enrichment.
|
|
145
|
+
* Delegates to the per-type XML schema's isSkipUpliftEnabled implementation.
|
|
146
|
+
*/
|
|
147
|
+
static isSkipUpliftEnabled(xmlContent, componentTypeName) {
|
|
148
|
+
try {
|
|
149
|
+
const parser = new XMLParser({ ignoreAttributes: false, preserveOrder: false, trimValues: true });
|
|
150
|
+
const xmlObj = parser.parse(xmlContent);
|
|
151
|
+
const rootKey = Object.keys(xmlObj).find((k) => k !== '?xml');
|
|
152
|
+
if (!rootKey)
|
|
153
|
+
return false;
|
|
154
|
+
const xmlRoot = xmlObj[rootKey];
|
|
155
|
+
if (!xmlRoot)
|
|
156
|
+
return false;
|
|
157
|
+
const schema = (componentTypeName ? METADATA_TYPE_CONFIGS[componentTypeName]?.xmlSchema : undefined) ?? DEFAULT_XML_METADATA_SCHEMA;
|
|
158
|
+
return schema.isSkipUpliftEnabled(xmlRoot);
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return false;
|
|
81
162
|
}
|
|
82
|
-
return componentsByType;
|
|
83
163
|
}
|
|
84
164
|
}
|
|
85
165
|
//# sourceMappingURL=fileProcessor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileProcessor.js","sourceRoot":"","sources":["../../src/files/fileProcessor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"fileProcessor.js","sourceRoot":"","sources":["../../src/files/fileProcessor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACpH,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAG9E,QAAQ,CAAC,uBAAuB,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACtD,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,iCAAiC,EAAE,QAAQ,CAAC,CAAC;AASpF;;;;GAIG;AACH,MAAM,OAAO,aAAa;IAEjB,MAAM,C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,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC;YAC9D,IAAI,CAAC,OAAO;gBAAE,OAAO,KAAK,CAAC;YAE3B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAwC,CAAC;YACvE,IAAI,CAAC,OAAO;gBAAE,OAAO,KAAK,CAAC;YAE3B,MAAM,MAAM,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,qBAAqB,CAAC,iBAAiB,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,2BAA2B,CAAC;YACpI,OAAO,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAC7C,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type SourceComponent } from '@salesforce/source-deploy-retrieve';
|
|
2
|
-
import type {
|
|
2
|
+
import type { EnrichmentRequestRecord } from '../enrichment/constants/api.js';
|
|
3
3
|
export declare class SourceComponentProcessor {
|
|
4
4
|
/**
|
|
5
5
|
*
|
|
@@ -14,7 +14,7 @@ export declare class SourceComponentProcessor {
|
|
|
14
14
|
* @param projectDir
|
|
15
15
|
* @returns
|
|
16
16
|
*/
|
|
17
|
-
static getComponentsToSkip(sourceComponents: SourceComponent[], metadataEntries: string[], projectDir?: string): Set<
|
|
17
|
+
static getComponentsToSkip(sourceComponents: SourceComponent[], metadataEntries: string[], projectDir?: string): Set<EnrichmentRequestRecord>;
|
|
18
18
|
private static filterComponents;
|
|
19
19
|
private static diffRequestedComponents;
|
|
20
20
|
private static parseRequestedComponents;
|
|
@@ -14,7 +14,11 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { RegistryAccess } from '@salesforce/source-deploy-retrieve';
|
|
17
|
-
import {
|
|
17
|
+
import { Messages } from '@salesforce/core/messages';
|
|
18
|
+
import { EnrichmentStatus } from '../enrichment/constants/api.js';
|
|
19
|
+
import { SUPPORTED_COMPONENT_TYPES } from '../enrichment/constants/api.js';
|
|
20
|
+
Messages.importMessagesDirectory(import.meta.dirname);
|
|
21
|
+
const messages = Messages.loadMessages('@salesforce/metadata-enrichment', 'errors');
|
|
18
22
|
export class SourceComponentProcessor {
|
|
19
23
|
/**
|
|
20
24
|
*
|
|
@@ -48,17 +52,24 @@ export class SourceComponentProcessor {
|
|
|
48
52
|
// Filter out unsupported component types
|
|
49
53
|
if (!SUPPORTED_COMPONENT_TYPES.has(typeName)) {
|
|
50
54
|
filteredComponents.add({
|
|
51
|
-
typeName: sourceComponent.type.name,
|
|
52
55
|
componentName: requestedComponent.componentName,
|
|
56
|
+
componentType: sourceComponent.type,
|
|
57
|
+
requestBody: null,
|
|
58
|
+
response: null,
|
|
59
|
+
message: messages.getMessage('errors.unsupported.type', [typeName]),
|
|
60
|
+
status: EnrichmentStatus.SKIPPED,
|
|
53
61
|
});
|
|
54
62
|
continue;
|
|
55
63
|
}
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
if (validator && !validator(sourceComponent)) {
|
|
64
|
+
// Filter out supported components missing their metadata file
|
|
65
|
+
if (sourceComponent.xml === undefined) {
|
|
59
66
|
filteredComponents.add({
|
|
60
|
-
typeName: sourceComponent.type.name,
|
|
61
67
|
componentName: requestedComponent.componentName,
|
|
68
|
+
componentType: sourceComponent.type,
|
|
69
|
+
requestBody: null,
|
|
70
|
+
response: null,
|
|
71
|
+
message: messages.getMessage('errors.component.configuration.not.found'),
|
|
72
|
+
status: EnrichmentStatus.SKIPPED,
|
|
62
73
|
});
|
|
63
74
|
}
|
|
64
75
|
}
|
|
@@ -69,7 +80,14 @@ export class SourceComponentProcessor {
|
|
|
69
80
|
const missingComponents = new Set();
|
|
70
81
|
for (const requestedComponent of requestedComponents) {
|
|
71
82
|
if (requestedComponent.componentName && !existingSourceComponentNames.has(requestedComponent.componentName)) {
|
|
72
|
-
missingComponents.add(
|
|
83
|
+
missingComponents.add({
|
|
84
|
+
componentName: requestedComponent.componentName,
|
|
85
|
+
componentType: { name: requestedComponent.typeName },
|
|
86
|
+
requestBody: null,
|
|
87
|
+
response: null,
|
|
88
|
+
message: messages.getMessage('errors.component.not.found'),
|
|
89
|
+
status: EnrichmentStatus.SKIPPED,
|
|
90
|
+
});
|
|
73
91
|
}
|
|
74
92
|
}
|
|
75
93
|
return missingComponents;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sourceComponentProcessor.js","sourceRoot":"","sources":["../../src/files/sourceComponentProcessor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"sourceComponentProcessor.js","sourceRoot":"","sources":["../../src/files/sourceComponentProcessor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,cAAc,EAA2C,MAAM,oCAAoC,CAAC;AAC7G,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAGrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,QAAQ,CAAC,uBAAuB,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACtD,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,iCAAiC,EAAE,QAAQ,CAAC,CAAC;AAEpF,MAAM,OAAO,wBAAwB;IACnC;;;;;;;;;;;;OAYG;IACI,MAAM,CAAC,mBAAmB,CAC/B,gBAAmC,EACnC,eAAyB,EACzB,UAAmB;QAEnB,MAAM,mBAAmB,GAAG,wBAAwB,CAAC,wBAAwB,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;QAC3G,MAAM,iBAAiB,GAAG,wBAAwB,CAAC,uBAAuB,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,CAAC;QAClH,MAAM,kBAAkB,GAAG,wBA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IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;YACrD,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,YAAY,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;YAC7E,4DAA4D;YAC5D,IAAI,YAAY,KAAK,GAAG,EAAE,CAAC;gBACzB,OAAO,IAAI,CAAC;YACd,CAAC;YACD,OAAO;gBACL,QAAQ,EAAE,IAAI,CAAC,IAAI;gBACnB,aAAa,EAAE,YAAY;aAC5B,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { SourceComponentProcessor, FileProcessor } from './files/index.js';
|
|
2
2
|
export type { FileReadResult } from './files/index.js';
|
|
3
|
-
export { getMimeTypeFromExtension, API_ENDPOINT_ENRICHMENT, SUPPORTED_MIME_TYPES, EnrichmentHandler, EnrichmentMetrics, EnrichmentRecords, EnrichmentStatus,
|
|
3
|
+
export { getMimeTypeFromExtension, API_ENDPOINT_ENRICHMENT, SUPPORTED_MIME_TYPES, EnrichmentHandler, EnrichmentMetrics, EnrichmentRecords, EnrichmentStatus, } from './enrichment/index.js';
|
|
4
4
|
export type { ContentBundleFile, ContentBundle, EnrichmentRequestBody, EnrichmentMetadata, EnrichmentResult, EnrichMetadataResponse, EnrichmentRequestRecord, } from './enrichment/index.js';
|
|
5
5
|
export type { ComponentEnrichmentStatus, MetadataTypeAndName } from './common/index.js';
|
package/lib/index.js
CHANGED
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
export { SourceComponentProcessor, FileProcessor } from './files/index.js';
|
|
17
|
-
export { getMimeTypeFromExtension, API_ENDPOINT_ENRICHMENT, SUPPORTED_MIME_TYPES, EnrichmentHandler, EnrichmentMetrics, EnrichmentRecords, EnrichmentStatus,
|
|
17
|
+
export { getMimeTypeFromExtension, API_ENDPOINT_ENRICHMENT, SUPPORTED_MIME_TYPES, EnrichmentHandler, EnrichmentMetrics, EnrichmentRecords, EnrichmentStatus, } from './enrichment/index.js';
|
|
18
18
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAG3E,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAG3E,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC"}
|
|
@@ -13,5 +13,5 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export {
|
|
16
|
+
export { DEFAULT_XML_METADATA_SCHEMA, SALESFORCE_OBJECT_XML_METADATA_SCHEMA } from './schemas.js';
|
|
17
17
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,2BAA2B,EAAE,qCAAqC,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { EnrichmentResult } from '../enrichment/types/index.js';
|
|
2
|
+
export type MetadataTypeXmlSchema = {
|
|
3
|
+
/**
|
|
4
|
+
* Define how to apply enrichment result data into the XML metadata.
|
|
5
|
+
* Called after the metadata file has been parsed and mutates xmlRoot in place.
|
|
6
|
+
*/
|
|
7
|
+
applyEnrichment: (xmlRoot: Record<string, unknown>, result: EnrichmentResult) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Define how to check if the user has opted out of enrichment based on the set <skipUplift> tag.
|
|
10
|
+
* If you want to ignore this capability, always return false.
|
|
11
|
+
*/
|
|
12
|
+
isSkipUpliftEnabled: (xmlRoot: Record<string, unknown>) => boolean;
|
|
13
|
+
};
|
|
14
|
+
export type MetadataTypeConfig = {
|
|
15
|
+
apiType: string;
|
|
16
|
+
xmlSchema: MetadataTypeXmlSchema;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Default XML metadata schema where enrichment is written within <ai> block at metadata's root level.
|
|
20
|
+
*
|
|
21
|
+
* Example output structure:
|
|
22
|
+
* ```
|
|
23
|
+
* <LightningComponentBundle>
|
|
24
|
+
* <ai>
|
|
25
|
+
* <skipUplift>false</skipUplift>
|
|
26
|
+
* <description>...</description>
|
|
27
|
+
* <score>0.95</score>
|
|
28
|
+
* </ai>
|
|
29
|
+
* </LightningComponentBundle>
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const DEFAULT_XML_METADATA_SCHEMA: MetadataTypeXmlSchema;
|
|
33
|
+
/**
|
|
34
|
+
* XML metadata schema for SalesforceObject where enrichment is written within <aiDescriptor> block.
|
|
35
|
+
*
|
|
36
|
+
* Example output structure:
|
|
37
|
+
* ```
|
|
38
|
+
* <CustomObject>
|
|
39
|
+
* <aiDescriptor>
|
|
40
|
+
* <skipUplift>false</skipUplift>
|
|
41
|
+
* <enrichedDescription>...</enrichedDescription>
|
|
42
|
+
* <score>0.95</score>
|
|
43
|
+
* </aiDescriptor>
|
|
44
|
+
* </CustomObject>
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare const SALESFORCE_OBJECT_XML_METADATA_SCHEMA: MetadataTypeXmlSchema;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026, Salesforce, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { XMLParser } from 'fast-xml-parser';
|
|
17
|
+
/**
|
|
18
|
+
* Parses the description field from an EnrichmentResult into an object suitable
|
|
19
|
+
* for embedding in the <ai> XML block.
|
|
20
|
+
*
|
|
21
|
+
* The description may be plain text, or HTML-entity-encoded XML containing a
|
|
22
|
+
* description tag and optionally one or more property tags.
|
|
23
|
+
*/
|
|
24
|
+
function parseDescriptionContent(description) {
|
|
25
|
+
const decodedDescription = description
|
|
26
|
+
.replace(/</g, '<')
|
|
27
|
+
.replace(/>/g, '>')
|
|
28
|
+
.replace(/&/g, '&')
|
|
29
|
+
.replace(/"/g, '"')
|
|
30
|
+
.replace(/'/g, "'");
|
|
31
|
+
// Plain text — no encoded XML tags present
|
|
32
|
+
// Wrap it in <description> tag and return it
|
|
33
|
+
if (!description.includes('<description>')) {
|
|
34
|
+
return { description: decodedDescription };
|
|
35
|
+
}
|
|
36
|
+
// Description contains encoded XML — parse the decoded fragment to extract child elements
|
|
37
|
+
// And return this XML content back within <ai> tags
|
|
38
|
+
const parser = new XMLParser({
|
|
39
|
+
ignoreAttributes: false,
|
|
40
|
+
processEntities: false,
|
|
41
|
+
trimValues: true,
|
|
42
|
+
isArray: (tagName) => tagName === 'property',
|
|
43
|
+
});
|
|
44
|
+
try {
|
|
45
|
+
// Use a temporary <root> element to wrap the XML content for serialization purposes only
|
|
46
|
+
const parsed = parser.parse(`<root>${decodedDescription}</root>`);
|
|
47
|
+
return parsed.root ?? { description: decodedDescription };
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return { description: decodedDescription };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Default XML metadata schema where enrichment is written within <ai> block at metadata's root level.
|
|
55
|
+
*
|
|
56
|
+
* Example output structure:
|
|
57
|
+
* ```
|
|
58
|
+
* <LightningComponentBundle>
|
|
59
|
+
* <ai>
|
|
60
|
+
* <skipUplift>false</skipUplift>
|
|
61
|
+
* <description>...</description>
|
|
62
|
+
* <score>0.95</score>
|
|
63
|
+
* </ai>
|
|
64
|
+
* </LightningComponentBundle>
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export const DEFAULT_XML_METADATA_SCHEMA = {
|
|
68
|
+
applyEnrichment(xmlRoot, result) {
|
|
69
|
+
Object.assign(xmlRoot, {
|
|
70
|
+
ai: {
|
|
71
|
+
skipUplift: 'false',
|
|
72
|
+
...parseDescriptionContent(result.description),
|
|
73
|
+
score: String(result.descriptionScore),
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
isSkipUpliftEnabled(xmlRoot) {
|
|
78
|
+
const root = xmlRoot;
|
|
79
|
+
const skipUplift = root.ai?.skipUplift;
|
|
80
|
+
return skipUplift === true || String(skipUplift).toLowerCase() === 'true';
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* XML metadata schema for SalesforceObject where enrichment is written within <aiDescriptor> block.
|
|
85
|
+
*
|
|
86
|
+
* Example output structure:
|
|
87
|
+
* ```
|
|
88
|
+
* <CustomObject>
|
|
89
|
+
* <aiDescriptor>
|
|
90
|
+
* <skipUplift>false</skipUplift>
|
|
91
|
+
* <enrichedDescription>...</enrichedDescription>
|
|
92
|
+
* <score>0.95</score>
|
|
93
|
+
* </aiDescriptor>
|
|
94
|
+
* </CustomObject>
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export const SALESFORCE_OBJECT_XML_METADATA_SCHEMA = {
|
|
98
|
+
applyEnrichment(xmlRoot, result) {
|
|
99
|
+
Object.assign(xmlRoot, {
|
|
100
|
+
aiDescriptor: {
|
|
101
|
+
skipUplift: 'false',
|
|
102
|
+
enrichedDescription: result.description,
|
|
103
|
+
score: String(result.descriptionScore),
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
isSkipUpliftEnabled(xmlRoot) {
|
|
108
|
+
const root = xmlRoot;
|
|
109
|
+
const skipUplift = root.aiDescriptor?.skipUplift;
|
|
110
|
+
return skipUplift === true || String(skipUplift).toLowerCase() === 'true';
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/schemas/schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAwB5C;;;;;;GAMG;AACH,SAAS,uBAAuB,CAAC,WAAmB;IAClD,MAAM,kBAAkB,GAAG,WAAW;SACnC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;SACrB,OAAO,CAAC,OAAO,EAAE,GAA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AAM,UAAU,GAAG,IAAI,CAAC,EAAE,EAAE,UAAU,CAAC;QACvC,OAAO,UAAU,KAAK,IAAI,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC;IAC5E,CAAC;CACF,CAAC;AAGF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAA0B;IAC1E,eAAe,CAAC,OAAO,EAAE,MAAM;QAC7B,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;YACrB,YAAY,EAAE;gBACZ,UAAU,EAAE,OAAO;gBACnB,mBAAmB,EAAE,MAAM,CAAC,WAAW;gBACvC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC;aACvC;SACF,CAAC,CAAC;IACL,CAAC;IACD,mBAAmB,CAAC,OAAO;QACzB,MAAM,IAAI,GAAG,OAA+D,CAAC;QAC7E,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC;QACjD,OAAO,UAAU,KAAK,IAAI,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC;IAC5E,CAAC;CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/metadata-enrichment",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "A library for handling metadata enrichment",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"main": "lib/index",
|
|
@@ -51,11 +51,11 @@
|
|
|
51
51
|
"string-width": "^4.2.3"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@salesforce/core": "^8.
|
|
54
|
+
"@salesforce/core": "^8.26.3",
|
|
55
55
|
"@salesforce/kit": "^3.2.4",
|
|
56
|
-
"@salesforce/source-deploy-retrieve": "^12.
|
|
56
|
+
"@salesforce/source-deploy-retrieve": "^12.31.14",
|
|
57
57
|
"@salesforce/ts-types": "^2.0.11",
|
|
58
|
-
"fast-xml-parser": "^5.
|
|
58
|
+
"fast-xml-parser": "^5.4.1"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@salesforce/cli-plugins-testkit": "^5.3.41",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"eslint-plugin-sf-plugin": "^1.20.33",
|
|
64
64
|
"ts-node": "^10.9.2",
|
|
65
65
|
"ts-patch": "^3.1.2",
|
|
66
|
-
"typescript": "^5.
|
|
66
|
+
"typescript": "^5.9.2"
|
|
67
67
|
},
|
|
68
68
|
"publishConfig": {
|
|
69
69
|
"access": "public"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { LwcComponentValidator } from './lwcComponentValidator.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/enrichment/validators/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { SourceComponent } from '@salesforce/source-deploy-retrieve';
|
|
2
|
-
/**
|
|
3
|
-
* Validator for LWC - "LightningComponentBundle" source components processing
|
|
4
|
-
* Validates that a corresponding metadata XML file exists
|
|
5
|
-
*/
|
|
6
|
-
export declare class LwcComponentValidator {
|
|
7
|
-
static validate(this: void, component: SourceComponent): boolean;
|
|
8
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2026, Salesforce, Inc.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* Validator for LWC - "LightningComponentBundle" source components processing
|
|
18
|
-
* Validates that a corresponding metadata XML file exists
|
|
19
|
-
*/
|
|
20
|
-
export class LwcComponentValidator {
|
|
21
|
-
static validate(component) {
|
|
22
|
-
const hasMetadataFile = (component.xml !== undefined);
|
|
23
|
-
return hasMetadataFile;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=lwcComponentValidator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lwcComponentValidator.js","sourceRoot":"","sources":["../../../src/enrichment/validators/lwcComponentValidator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IACzB,MAAM,CAAC,QAAQ,CAAa,SAA0B;QAC3D,MAAM,eAAe,GAAG,CAAC,SAAS,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC;QACtD,OAAO,eAAe,CAAC;IACzB,CAAC;CACF"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { SourceComponent } from '@salesforce/source-deploy-retrieve';
|
|
2
|
-
import type { EnrichmentRequestRecord } from '../enrichment/enrichmentHandler.js';
|
|
3
|
-
import type { EnrichmentResult } from '../enrichment/types/index.js';
|
|
4
|
-
import type { ComponentTypeProcessor, FileReadResult } from './fileProcessor.js';
|
|
5
|
-
/**
|
|
6
|
-
* A LWC specific processor for reading and updating LWC metadata files.
|
|
7
|
-
*/
|
|
8
|
-
export declare class LwcProcessor implements ComponentTypeProcessor {
|
|
9
|
-
updateMetadata(lightningComponentBundles: SourceComponent[], enrichmentRecords: Set<EnrichmentRequestRecord>): Promise<Set<EnrichmentRequestRecord>>;
|
|
10
|
-
readComponentFiles(sourceComponents: SourceComponent[]): Promise<FileReadResult[]>;
|
|
11
|
-
updateMetaXml(xmlContent: string, result: EnrichmentResult): string;
|
|
12
|
-
isMetaXmlFile(filePath: string): boolean;
|
|
13
|
-
private isSkipUpliftEnabled;
|
|
14
|
-
}
|