@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.
Files changed (48) hide show
  1. package/lib/enrichment/constants/api.d.ts +33 -4
  2. package/lib/enrichment/constants/api.js +37 -9
  3. package/lib/enrichment/constants/api.js.map +1 -1
  4. package/lib/enrichment/constants/component.d.ts +4 -9
  5. package/lib/enrichment/constants/component.js +4 -12
  6. package/lib/enrichment/constants/component.js.map +1 -1
  7. package/lib/enrichment/constants/index.d.ts +3 -2
  8. package/lib/enrichment/constants/index.js +2 -2
  9. package/lib/enrichment/constants/index.js.map +1 -1
  10. package/lib/enrichment/constants/mimeTypes.js +7 -3
  11. package/lib/enrichment/constants/mimeTypes.js.map +1 -1
  12. package/lib/enrichment/enrichmentHandler.d.ts +5 -16
  13. package/lib/enrichment/enrichmentHandler.js +6 -13
  14. package/lib/enrichment/enrichmentHandler.js.map +1 -1
  15. package/lib/enrichment/enrichmentMetrics.d.ts +1 -1
  16. package/lib/enrichment/enrichmentMetrics.js +1 -1
  17. package/lib/enrichment/enrichmentMetrics.js.map +1 -1
  18. package/lib/enrichment/enrichmentRecords.d.ts +3 -4
  19. package/lib/enrichment/enrichmentRecords.js +7 -57
  20. package/lib/enrichment/enrichmentRecords.js.map +1 -1
  21. package/lib/enrichment/index.d.ts +3 -3
  22. package/lib/enrichment/index.js +2 -2
  23. package/lib/enrichment/index.js.map +1 -1
  24. package/lib/enrichment/types/requestTypes.d.ts +1 -1
  25. package/lib/files/fileProcessor.d.ts +11 -14
  26. package/lib/files/fileProcessor.js +109 -29
  27. package/lib/files/fileProcessor.js.map +1 -1
  28. package/lib/files/sourceComponentProcessor.d.ts +2 -2
  29. package/lib/files/sourceComponentProcessor.js +25 -7
  30. package/lib/files/sourceComponentProcessor.js.map +1 -1
  31. package/lib/index.d.ts +1 -1
  32. package/lib/index.js +1 -1
  33. package/lib/index.js.map +1 -1
  34. package/lib/schemas/index.d.ts +2 -0
  35. package/lib/{enrichment/validators → schemas}/index.js +1 -1
  36. package/lib/schemas/index.js.map +1 -0
  37. package/lib/schemas/schemas.d.ts +47 -0
  38. package/lib/schemas/schemas.js +113 -0
  39. package/lib/schemas/schemas.js.map +1 -0
  40. package/package.json +5 -5
  41. package/lib/enrichment/validators/index.d.ts +0 -1
  42. package/lib/enrichment/validators/index.js.map +0 -1
  43. package/lib/enrichment/validators/lwcComponentValidator.d.ts +0 -8
  44. package/lib/enrichment/validators/lwcComponentValidator.js +0 -26
  45. package/lib/enrichment/validators/lwcComponentValidator.js.map +0 -1
  46. package/lib/files/lwcProcessor.d.ts +0 -14
  47. package/lib/files/lwcProcessor.js +0 -125
  48. package/lib/files/lwcProcessor.js.map +0 -1
@@ -1,125 +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
- import { basename } from 'node:path';
17
- import { writeFile } from 'node:fs/promises';
18
- import { SfError } from '@salesforce/core';
19
- import { Messages } from '@salesforce/core/messages';
20
- import { XMLParser, XMLBuilder } from 'fast-xml-parser';
21
- import { EnrichmentStatus } from '../enrichment/enrichmentHandler.js';
22
- import { FileProcessor } from './fileProcessor.js';
23
- Messages.importMessagesDirectory(import.meta.dirname);
24
- const messages = Messages.loadMessages('@salesforce/metadata-enrichment', 'errors');
25
- /**
26
- * A LWC specific processor for reading and updating LWC metadata files.
27
- */
28
- /* eslint-disable class-methods-use-this */
29
- export class LwcProcessor {
30
- async updateMetadata(lightningComponentBundles, enrichmentRecords) {
31
- const fileContents = await this.readComponentFiles(lightningComponentBundles);
32
- for (const file of fileContents) {
33
- if (!this.isMetaXmlFile(file.filePath)) {
34
- continue;
35
- }
36
- let enrichmentRecord;
37
- for (const record of enrichmentRecords) {
38
- if (record.componentName === file.componentName) {
39
- enrichmentRecord = record;
40
- break;
41
- }
42
- }
43
- if (!enrichmentRecord?.response) {
44
- continue;
45
- }
46
- const enrichmentResult = enrichmentRecord.response.results[0];
47
- if (!enrichmentResult) {
48
- continue;
49
- }
50
- // Check if skipUplift is enabled before processing
51
- if (this.isSkipUpliftEnabled(file.fileContents)) {
52
- enrichmentRecord.message = 'skipUplift is set to true';
53
- enrichmentRecord.status = EnrichmentStatus.SKIPPED;
54
- continue;
55
- }
56
- try {
57
- const updatedXml = this.updateMetaXml(file.fileContents, enrichmentResult);
58
- // eslint-disable-next-line no-await-in-loop
59
- await writeFile(file.filePath, updatedXml, 'utf-8');
60
- }
61
- catch (error) {
62
- const errorMessage = error instanceof Error ? error.message : String(error);
63
- enrichmentRecord.message = errorMessage;
64
- }
65
- }
66
- return enrichmentRecords;
67
- }
68
- async readComponentFiles(sourceComponents) {
69
- const fileReadPromises = [];
70
- for (const component of sourceComponents) {
71
- const componentName = component.fullName ?? component.name;
72
- if (!componentName || !component.xml) {
73
- continue;
74
- }
75
- fileReadPromises.push(FileProcessor.readComponentFile(componentName, component.xml));
76
- }
77
- const fileResults = await Promise.all(fileReadPromises);
78
- return fileResults.filter((result) => result !== null);
79
- }
80
- updateMetaXml(xmlContent, result) {
81
- const parser = new XMLParser({
82
- htmlEntities: true,
83
- ignoreAttributes: false,
84
- processEntities: false,
85
- trimValues: true,
86
- });
87
- const builder = new XMLBuilder({
88
- format: true,
89
- ignoreAttributes: false,
90
- processEntities: false,
91
- });
92
- try {
93
- const xmlObj = parser.parse(xmlContent);
94
- if (!xmlObj.LightningComponentBundle) {
95
- xmlObj.LightningComponentBundle = {};
96
- }
97
- xmlObj.LightningComponentBundle.ai = {
98
- skipUplift: 'false',
99
- description: result.description,
100
- score: String(result.descriptionScore),
101
- };
102
- const builtXml = builder.build(xmlObj);
103
- return builtXml.trim().replace(/\n{3,}/g, '\n\n');
104
- }
105
- catch (error) {
106
- throw new SfError(messages.getMessage('errors.parsing.xml', [error instanceof Error ? error.message : String(error)]));
107
- }
108
- }
109
- isMetaXmlFile(filePath) {
110
- const fileName = basename(filePath);
111
- return fileName.endsWith('.js-meta.xml');
112
- }
113
- isSkipUpliftEnabled(xmlContent) {
114
- try {
115
- const parser = new XMLParser({ ignoreAttributes: false, preserveOrder: false, trimValues: true });
116
- const xmlObj = parser.parse(xmlContent);
117
- const skipUplift = xmlObj.LightningComponentBundle?.ai?.skipUplift;
118
- return skipUplift === true || String(skipUplift).toLowerCase() === 'true';
119
- }
120
- catch {
121
- return false;
122
- }
123
- }
124
- }
125
- //# sourceMappingURL=lwcProcessor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lwcProcessor.js","sourceRoot":"","sources":["../../src/files/lwcProcessor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,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;AAGxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAEtE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,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;;GAEG;AACH,2CAA2C;AAC3C,MAA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