Skip to content

Commit 05c063f

Browse files
committed
chore: adds jsdocs
1 parent 4321696 commit 05c063f

File tree

4 files changed

+208
-1
lines changed

4 files changed

+208
-1
lines changed

src/migration/related/FlexipageMigration.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/*
2+
* Copyright (c) 2025, salesforce.com, 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+
18
import * as fs from 'fs';
29
import * as path from 'path';
310
import * as shell from 'shelljs';
@@ -13,28 +20,83 @@ import { transformFlexipageBundle } from '../../utils/flexipage/flexiPageTransfo
1320
import { Flexipage } from '../interfaces';
1421
import { BaseRelatedObjectMigration } from './BaseRealtedObjectMigration';
1522

23+
/**
24+
* FlexipageMigration handles the migration and assessment of FlexiPage components
25+
* in Salesforce OmniStudio migration operations.
26+
*
27+
* This class provides functionality to:
28+
* - Assess FlexiPage components for migration readiness
29+
* - Migrate FlexiPage components to the target format
30+
* - Process FlexiPage XML files and transform their content
31+
* - Generate assessment reports with detailed status information
32+
* - Handle errors and provide detailed error reporting
33+
*
34+
* The migration process involves:
35+
* - Retrieving FlexiPage metadata from the Salesforce org
36+
* - Parsing and analyzing FlexiPage XML files
37+
* - Transforming component structures and properties
38+
* - Generating diff information for visual comparison
39+
* - Writing transformed files back to the project structure
40+
*/
1641
export class FlexipageMigration extends BaseRelatedObjectMigration {
42+
/** Messages instance for internationalization */
1743
private messages: Messages;
1844

45+
/**
46+
* Creates a new FlexipageMigration instance.
47+
*
48+
* @param projectPath - The path to the Salesforce project
49+
* @param namespace - The namespace for the migration operation
50+
* @param org - The Salesforce org connection
51+
* @param messages - Messages instance for internationalization
52+
*/
1953
public constructor(projectPath: string, namespace: string, org: Org, messages: Messages) {
2054
super(projectPath, namespace, org);
2155
this.messages = messages;
2256
}
2357

58+
/**
59+
* Returns the object type constant for FlexiPage components.
60+
*
61+
* @returns The FlexiPage constant string
62+
*/
2463
public processObjectType(): string {
2564
return Constants.FlexiPage;
2665
}
2766

67+
/**
68+
* Performs assessment of FlexiPage components to determine migration readiness.
69+
*
70+
* @returns Array of FlexiPage assessment information
71+
*/
2872
public assess(): FlexiPageAssessmentInfo[] {
2973
Logger.info(this.messages.getMessage('assessingFlexiPages'));
3074
return this.process('assess');
3175
}
3276

77+
/**
78+
* Performs migration of FlexiPage components to the target format.
79+
*
80+
* @returns Array of FlexiPage assessment information after migration
81+
*/
3382
public migrate(): FlexiPageAssessmentInfo[] {
3483
Logger.info(this.messages.getMessage('migratingFlexiPages'));
3584
return this.process('migrate');
3685
}
3786

87+
/**
88+
* Processes FlexiPage files in either assessment or migration mode.
89+
*
90+
* This method:
91+
* - Retrieves FlexiPage metadata from the Salesforce org
92+
* - Reads and processes each FlexiPage XML file
93+
* - Transforms the content based on the specified mode
94+
* - Handles errors and provides detailed logging
95+
* - Generates progress indicators for long-running operations
96+
*
97+
* @param mode - The processing mode: 'assess' for analysis only, 'migrate' for actual transformation
98+
* @returns Array of FlexiPage assessment information
99+
*/
38100
private process(mode: 'assess' | 'migrate'): FlexiPageAssessmentInfo[] {
39101
Logger.info(this.messages.getMessage('retrievingFlexiPages'));
40102
shell.cd(this.projectPath);
@@ -76,6 +138,22 @@ export class FlexipageMigration extends BaseRelatedObjectMigration {
76138
return flexPageAssessmentInfos;
77139
}
78140

141+
/**
142+
* Processes a single FlexiPage file for assessment or migration.
143+
*
144+
* This method:
145+
* - Reads the FlexiPage XML file content
146+
* - Parses the XML structure into a JavaScript object
147+
* - Transforms the FlexiPage bundle using the flexipage transformer
148+
* - Generates diff information for visual comparison
149+
* - Writes transformed content back to file in migration mode
150+
* - Handles errors and provides detailed error information
151+
*
152+
* @param fileName - The name of the FlexiPage file
153+
* @param filePath - The full path to the FlexiPage file
154+
* @param mode - The processing mode: 'assess' or 'migrate'
155+
* @returns FlexiPage assessment information with status and error details
156+
*/
79157
private processFlexiPage(fileName: string, filePath: string, mode: 'assess' | 'migrate'): FlexiPageAssessmentInfo {
80158
Logger.logVerbose(this.messages.getMessage('startingFlexiPageProcessing', [fileName]));
81159
const fileContent = fs.readFileSync(filePath, 'utf8');

src/utils/XMLUtil.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,39 @@
1+
/*
2+
* Copyright (c) 2025, salesforce.com, 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+
18
import { XMLParser, XMLBuilder } from 'fast-xml-parser';
29

10+
/**
11+
* XMLUtil provides XML parsing and building functionality using the fast-xml-parser library.
12+
*
13+
* This class handles:
14+
* - Parsing XML strings into JavaScript objects
15+
* - Building XML strings from JavaScript objects
16+
* - Configuring parser options for Salesforce metadata XML structures
17+
* - Handling arrays for specific FlexiPage elements
18+
*/
319
class XMLUtil {
20+
/** XML parser instance configured for Salesforce metadata */
421
private parser: XMLParser;
22+
/** XML builder instance configured for formatted output */
523
private builder: XMLBuilder;
624

25+
/**
26+
* Initializes the XMLUtil with configured parser and builder instances.
27+
*
28+
* The parser is configured to:
29+
* - Preserve attributes with '@' prefix
30+
* - Handle arrays for FlexiPage regions and item instances
31+
* - Parse Salesforce metadata XML structures
32+
*
33+
* The builder is configured to:
34+
* - Format output with proper indentation
35+
* - Preserve attributes with '@' prefix
36+
*/
737
public constructor() {
838
this.parser = new XMLParser({
939
ignoreAttributes: false,
@@ -20,11 +50,23 @@ class XMLUtil {
2050
});
2151
}
2252

53+
/**
54+
* Parses an XML string into a JavaScript object.
55+
*
56+
* @param xml - The XML string to parse
57+
* @returns JavaScript object representation of the XML structure
58+
*/
2359
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2460
public parse(xml: string): any {
2561
return this.parser.parse(xml);
2662
}
2763

64+
/**
65+
* Builds an XML string from a JavaScript object.
66+
*
67+
* @param json - The JavaScript object to convert to XML
68+
* @returns Formatted XML string
69+
*/
2870
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2971
public build(json: any): string {
3072
return this.builder.build(json);

src/utils/flexipage/flexiPageTransformer.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,47 @@
1+
/*
2+
* Copyright (c) 2025, salesforce.com, 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+
18
import { Flexipage, FlexiComponentInstanceProperty } from '../../migration/interfaces';
29

10+
/** Attributes to remove during transformation */
311
const attrsToRemove = ['target'];
412

13+
/** Component name to look for during transformation */
514
const lookupComponentName = 'vlocityLWCOmniWrapper';
15+
/** Target component name after transformation */
616
const targetComponentName = 'runtime_omnistudio:omniscript';
17+
/** Target identifier after transformation */
718
const targetIdentifier = 'runtime_omnistudio_omniscript';
819

20+
/**
21+
* Transforms a Flexipage bundle by replacing vlocityLWCOmniWrapper components
22+
* with runtime_omnistudio:omniscript components and updating their properties.
23+
*
24+
* This function performs the following transformations:
25+
* - Identifies vlocityLWCOmniWrapper components within the specified namespace
26+
* - Removes the 'target' property from component instance properties
27+
* - Creates new properties for language, subType, theme, and type
28+
* - Updates the component name and identifier to the target runtime component
29+
*
30+
* @param ogBundle - The original Flexipage bundle to transform
31+
* @param namespace - The namespace to filter components by
32+
* @returns The transformed Flexipage bundle if changes were made, or false if no changes were needed
33+
* @throws Error if the 'target' property is not found for a component
34+
*/
935
export function transformFlexipageBundle(ogBundle: Flexipage, namespace: string): Flexipage | boolean {
1036
const bundle: Flexipage = JSON.parse(JSON.stringify(ogBundle)) as Flexipage;
1137
let changes = false;
1238

39+
/**
40+
* Filters out properties that should be removed during transformation
41+
*
42+
* @param item - The component instance property to check
43+
* @returns true if the property should be kept, false if it should be removed
44+
*/
1345
const propRemover = (item: FlexiComponentInstanceProperty): boolean => {
1446
return !attrsToRemove.includes(item.name);
1547
};
@@ -48,7 +80,13 @@ export function transformFlexipageBundle(ogBundle: Flexipage, namespace: string)
4880
return changes ? bundle : false;
4981
}
5082

51-
// will change after Aastha's utility
83+
/**
84+
* Creates new properties for the transformed component.
85+
* TODO: This function will be updated after Aastha's utility is available.
86+
*
87+
* @param _property - The original property value (currently unused)
88+
* @returns Object containing the new properties for the transformed component
89+
*/
5290
// eslint-disable-next-line @typescript-eslint/no-unused-vars
5391
function createNewProps(_property: string): Record<string, string> {
5492
return {

src/utils/resultsbuilder/FlexipageAssessmentReporter.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
* Copyright (c) 2025, salesforce.com, 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+
*/
17
import { FlexiPageAssessmentInfo } from '../interfaces';
28
import { FileDiffUtil } from '../lwcparser/fileutils/FileDiffUtil';
39
import { OmnistudioOrgDetails } from '../orgUtils';
@@ -9,10 +15,31 @@ import {
915
} from '../reportGenerator/reportInterfaces';
1016
import { createFilterGroupParam, createRowDataParam, getOrgDetailsForReport } from '../reportGenerator/reportUtil';
1117

18+
/**
19+
* FlexipageAssessmentReporter provides functionality to generate assessment reports
20+
* for Flexipage migration operations. It processes FlexiPage assessment information
21+
* and converts it into report-ready data structures.
22+
*
23+
* This class handles:
24+
* - Converting FlexiPage assessment data into report parameters
25+
* - Generating summary statistics for different migration statuses
26+
* - Creating report rows with proper formatting and styling
27+
* - Managing header groups and filter options for reports
28+
* - Ensuring unique row IDs for report data
29+
*/
1230
export class FlexipageAssessmentReporter {
31+
/** Static counter for generating unique row IDs */
1332
private static rowId = 0;
33+
/** Prefix for row ID generation */
1434
private static rowIdPrefix = 'flexipage-row-data-';
1535

36+
/**
37+
* Generates comprehensive assessment data for Flexipage migration reports.
38+
*
39+
* @param flexipageAssessmentInfos - Array of FlexiPage assessment information
40+
* @param omnistudioOrgDetails - Organization details for the report
41+
* @returns Complete report parameters including title, headers, filters, and rows
42+
*/
1643
public static getFlexipageAssessmentData(
1744
flexipageAssessmentInfos: FlexiPageAssessmentInfo[],
1845
omnistudioOrgDetails: OmnistudioOrgDetails
@@ -29,6 +56,12 @@ export class FlexipageAssessmentReporter {
2956
};
3057
}
3158

59+
/**
60+
* Generates summary statistics for Flexipage assessment data.
61+
*
62+
* @param flexipageAssessmentInfos - Array of FlexiPage assessment information
63+
* @returns Array of summary items with counts and CSS classes for different statuses
64+
*/
3265
public static getSummaryData(
3366
flexipageAssessmentInfos: FlexiPageAssessmentInfo[]
3467
): Array<import('../reportGenerator/reportInterfaces').SummaryItemDetailParam> {
@@ -51,6 +84,12 @@ export class FlexipageAssessmentReporter {
5184
];
5285
}
5386

87+
/**
88+
* Converts FlexiPage assessment information into report row data.
89+
*
90+
* @param flexipageAssessmentInfos - Array of FlexiPage assessment information
91+
* @returns Array of report row parameters with formatted data and unique row IDs
92+
*/
5493
private static getRowsForReport(flexipageAssessmentInfos: FlexiPageAssessmentInfo[]): ReportRowParam[] {
5594
if (!flexipageAssessmentInfos || flexipageAssessmentInfos.length === 0) {
5695
return [];
@@ -98,6 +137,11 @@ export class FlexipageAssessmentReporter {
98137
}));
99138
}
100139

140+
/**
141+
* Generates header groups for Flexipage assessment reports.
142+
*
143+
* @returns Array of header group parameters defining the report column structure
144+
*/
101145
private static getHeaderGroupsForReport(): ReportHeaderGroupParam[] {
102146
return [
103147
{
@@ -126,6 +170,11 @@ export class FlexipageAssessmentReporter {
126170
},
127171
];
128172
}
173+
/**
174+
* Generates filter groups for Flexipage assessment reports.
175+
*
176+
* @returns Array of filter group parameters for filtering by errors and status
177+
*/
129178
private static getFilterGroupsForReport(): FilterGroupParam[] {
130179
return [
131180
createFilterGroupParam('Filter by Errors', 'errors', ['Has Errors', 'Has No Errors']),

0 commit comments

Comments
 (0)