@salesforce/plugin-omnistudio-migration-tool 2.0.0-rc.6 → 2.0.0-rc.61
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 +165 -73
- package/lib/commands/omnistudio/migration/assess.d.ts +23 -15
- package/lib/commands/omnistudio/migration/assess.js +250 -89
- package/lib/commands/omnistudio/migration/assess.js.map +1 -1
- package/lib/commands/omnistudio/migration/clean.d.ts +13 -0
- package/lib/commands/omnistudio/migration/clean.js +162 -0
- package/lib/commands/omnistudio/migration/clean.js.map +1 -0
- package/lib/commands/omnistudio/migration/info.d.ts +10 -16
- package/lib/commands/omnistudio/migration/info.js +53 -35
- package/lib/commands/omnistudio/migration/info.js.map +1 -1
- package/lib/commands/omnistudio/migration/migrate.d.ts +78 -18
- package/lib/commands/omnistudio/migration/migrate.js +461 -175
- package/lib/commands/omnistudio/migration/migrate.js.map +1 -1
- package/lib/error/deploymentErrors.d.ts +15 -0
- package/lib/error/deploymentErrors.js +35 -0
- package/lib/error/deploymentErrors.js.map +1 -0
- package/lib/error/errorInterfaces.d.ts +5 -0
- package/lib/error/errorInterfaces.js +9 -1
- package/lib/error/errorInterfaces.js.map +1 -1
- package/lib/javascripts/reportGeneratorUtility.js +585 -22
- package/lib/migration/ApexNamespaceRegistry.d.ts +49 -0
- package/lib/migration/ApexNamespaceRegistry.js +130 -0
- package/lib/migration/ApexNamespaceRegistry.js.map +1 -0
- package/lib/migration/CustomCssRegistry.d.ts +117 -0
- package/lib/migration/CustomCssRegistry.js +234 -0
- package/lib/migration/CustomCssRegistry.js.map +1 -0
- package/lib/migration/NameMappingRegistry.d.ts +134 -0
- package/lib/migration/NameMappingRegistry.js +411 -0
- package/lib/migration/NameMappingRegistry.js.map +1 -0
- package/lib/migration/base.d.ts +8 -6
- package/lib/migration/base.js +25 -8
- package/lib/migration/base.js.map +1 -1
- package/lib/migration/customLabels.d.ts +70 -0
- package/lib/migration/customLabels.js +177 -0
- package/lib/migration/customLabels.js.map +1 -0
- package/lib/migration/dataraptor.d.ts +13 -0
- package/lib/migration/dataraptor.js +205 -80
- package/lib/migration/dataraptor.js.map +1 -1
- package/lib/migration/deployer.d.ts +14 -0
- package/lib/migration/deployer.js +105 -0
- package/lib/migration/deployer.js.map +1 -0
- package/lib/migration/flexcard.d.ts +256 -6
- package/lib/migration/flexcard.js +1808 -268
- package/lib/migration/flexcard.js.map +1 -1
- package/lib/migration/globalautonumber.d.ts +8 -8
- package/lib/migration/globalautonumber.js +49 -24
- package/lib/migration/globalautonumber.js.map +1 -1
- package/lib/migration/interfaces.d.ts +14 -0
- package/lib/migration/interfaces.js.map +1 -1
- package/lib/migration/metadataobjnamecheck.js.map +1 -1
- package/lib/migration/omniscript.d.ts +218 -4
- package/lib/migration/omniscript.js +1709 -247
- package/lib/migration/omniscript.js.map +1 -1
- package/lib/migration/omniscriptInstance.d.ts +90 -0
- package/lib/migration/omniscriptInstance.js +755 -0
- package/lib/migration/omniscriptInstance.js.map +1 -0
- package/lib/migration/postMigrate.d.ts +20 -4
- package/lib/migration/postMigrate.js +199 -12
- package/lib/migration/postMigrate.js.map +1 -1
- package/lib/migration/premigrate.d.ts +51 -0
- package/lib/migration/premigrate.js +325 -0
- package/lib/migration/premigrate.js.map +1 -0
- package/lib/migration/related/ApexMigration.d.ts +3 -0
- package/lib/migration/related/ApexMigration.js +222 -56
- package/lib/migration/related/ApexMigration.js.map +1 -1
- package/lib/migration/related/ExperienceSiteMigration.d.ts +30 -5
- package/lib/migration/related/ExperienceSiteMigration.js +263 -73
- package/lib/migration/related/ExperienceSiteMigration.js.map +1 -1
- package/lib/migration/related/FlexipageMigration.d.ts +5 -5
- package/lib/migration/related/FlexipageMigration.js +60 -38
- package/lib/migration/related/FlexipageMigration.js.map +1 -1
- package/lib/migration/related/LwcMigration.js +45 -26
- package/lib/migration/related/LwcMigration.js.map +1 -1
- package/lib/migration/related/OmnistudioRelatedObjectMigrationFacade.js +48 -32
- package/lib/migration/related/OmnistudioRelatedObjectMigrationFacade.js.map +1 -1
- package/lib/styles/reportGenerator.css +241 -16
- package/lib/templates/assessmentReport.template +78 -8
- package/lib/templates/dashboard.template +86 -57
- package/lib/templates/migrationReport.template +151 -0
- package/lib/utils/OmnistudioSettingsPrefManager.d.ts +14 -0
- package/lib/utils/OmnistudioSettingsPrefManager.js +112 -0
- package/lib/utils/OmnistudioSettingsPrefManager.js.map +1 -0
- package/lib/utils/XMLUtil.js +2 -1
- package/lib/utils/XMLUtil.js.map +1 -1
- package/lib/utils/apex/executor/AnonymousApexRunner.d.ts +1 -1
- package/lib/utils/apex/parser/apexparser.d.ts +8 -1
- package/lib/utils/apex/parser/apexparser.js +79 -13
- package/lib/utils/apex/parser/apexparser.js.map +1 -1
- package/lib/utils/config/ExistingRecordCleanupService.d.ts +30 -0
- package/lib/utils/config/ExistingRecordCleanupService.js +266 -0
- package/lib/utils/config/ExistingRecordCleanupService.js.map +1 -0
- package/lib/utils/config/OmniStudioMetadataCleanupService.d.ts +36 -0
- package/lib/utils/config/OmniStudioMetadataCleanupService.js +123 -0
- package/lib/utils/config/OmniStudioMetadataCleanupService.js.map +1 -0
- package/lib/utils/config/SpecialCharacterRecordCleanupService.d.ts +17 -0
- package/lib/utils/config/SpecialCharacterRecordCleanupService.js +186 -0
- package/lib/utils/config/SpecialCharacterRecordCleanupService.js.map +1 -0
- package/lib/utils/constants/documentRegistry.d.ts +9 -17
- package/lib/utils/constants/documentRegistry.js +9 -17
- package/lib/utils/constants/documentRegistry.js.map +1 -1
- package/lib/utils/constants/stringContants.d.ts +78 -0
- package/lib/utils/constants/stringContants.js +91 -4
- package/lib/utils/constants/stringContants.js.map +1 -1
- package/lib/utils/customLabels.d.ts +35 -0
- package/lib/utils/customLabels.js +100 -0
- package/lib/utils/customLabels.js.map +1 -0
- package/lib/utils/dataModelService.d.ts +18 -0
- package/lib/utils/dataModelService.js +72 -0
- package/lib/utils/dataModelService.js.map +1 -0
- package/lib/utils/file/fileUtil.d.ts +3 -1
- package/lib/utils/file/fileUtil.js +30 -13
- package/lib/utils/file/fileUtil.js.map +1 -1
- package/lib/utils/flexipage/flexiPageTransformer.js +119 -23
- package/lib/utils/flexipage/flexiPageTransformer.js.map +1 -1
- package/lib/utils/formula/FormulaUtil.d.ts +1 -1
- package/lib/utils/formula/FormulaUtil.js +17 -9
- package/lib/utils/formula/FormulaUtil.js.map +1 -1
- package/lib/utils/formula/Stack.js.map +1 -1
- package/lib/utils/generatePackageXml.d.ts +6 -2
- package/lib/utils/generatePackageXml.js +73 -33
- package/lib/utils/generatePackageXml.js.map +1 -1
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +1 -0
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/interfaces.d.ts +69 -8
- package/lib/utils/json/jsonutil.js.map +1 -1
- package/lib/utils/logger/fileLogger.js +17 -7
- package/lib/utils/logger/fileLogger.js.map +1 -1
- package/lib/utils/logger.d.ts +3 -3
- package/lib/utils/logger.js +10 -6
- package/lib/utils/logger.js.map +1 -1
- package/lib/utils/logging/debugtimer.js.map +1 -1
- package/lib/utils/lwcparser/fileutils/FileDiffUtil.js +30 -22
- package/lib/utils/lwcparser/fileutils/FileDiffUtil.js.map +1 -1
- package/lib/utils/lwcparser/fileutils/FileProcessorFactory.js.map +1 -1
- package/lib/utils/lwcparser/fileutils/HtmlFileProcessor.js.map +1 -1
- package/lib/utils/lwcparser/fileutils/JavascriptFileProcessor.js.map +1 -1
- package/lib/utils/lwcparser/fileutils/XmlFileProcessor.js.map +1 -1
- package/lib/utils/lwcparser/htmlParser/HTMLParser.js +29 -10
- package/lib/utils/lwcparser/htmlParser/HTMLParser.js.map +1 -1
- package/lib/utils/lwcparser/jsParser/JavaScriptParser.js +29 -11
- package/lib/utils/lwcparser/jsParser/JavaScriptParser.js.map +1 -1
- package/lib/utils/lwcparser/xmlParser/XmlParser.js +19 -8
- package/lib/utils/lwcparser/xmlParser/XmlParser.js.map +1 -1
- package/lib/utils/net/index.d.ts +5 -0
- package/lib/utils/net/index.js +40 -2
- package/lib/utils/net/index.js.map +1 -1
- package/lib/utils/omniscriptPackageManager.d.ts +31 -0
- package/lib/utils/omniscriptPackageManager.js +215 -0
- package/lib/utils/omniscriptPackageManager.js.map +1 -0
- package/lib/utils/orgPreferences.d.ts +25 -0
- package/lib/utils/orgPreferences.js +124 -8
- package/lib/utils/orgPreferences.js.map +1 -1
- package/lib/utils/orgUtils/index.d.ts +12 -5
- package/lib/utils/orgUtils/index.js +52 -22
- package/lib/utils/orgUtils/index.js.map +1 -1
- package/lib/utils/projectPathUtil.d.ts +1 -1
- package/lib/utils/projectPathUtil.js +27 -10
- package/lib/utils/projectPathUtil.js.map +1 -1
- package/lib/utils/promptUtil.d.ts +11 -1
- package/lib/utils/promptUtil.js +92 -0
- package/lib/utils/promptUtil.js.map +1 -1
- package/lib/utils/query/index.d.ts +1 -0
- package/lib/utils/query/index.js +18 -1
- package/lib/utils/query/index.js.map +1 -1
- package/lib/utils/recordPrioritization.d.ts +44 -0
- package/lib/utils/recordPrioritization.js +69 -0
- package/lib/utils/recordPrioritization.js.map +1 -0
- package/lib/utils/reportGenerator/reportInterfaces.d.ts +12 -0
- package/lib/utils/reportGenerator/reportUtil.d.ts +6 -1
- package/lib/utils/reportGenerator/reportUtil.js +22 -7
- package/lib/utils/reportGenerator/reportUtil.js.map +1 -1
- package/lib/utils/resultsbuilder/ApexAssessmentReporter.d.ts +1 -0
- package/lib/utils/resultsbuilder/ApexAssessmentReporter.js +40 -17
- package/lib/utils/resultsbuilder/ApexAssessmentReporter.js.map +1 -1
- package/lib/utils/resultsbuilder/CustomLabelAssessmentReporter.d.ts +13 -0
- package/lib/utils/resultsbuilder/CustomLabelAssessmentReporter.js +179 -0
- package/lib/utils/resultsbuilder/CustomLabelAssessmentReporter.js.map +1 -0
- package/lib/utils/resultsbuilder/CustomLabelMigrationReporter.d.ts +27 -0
- package/lib/utils/resultsbuilder/CustomLabelMigrationReporter.js +262 -0
- package/lib/utils/resultsbuilder/CustomLabelMigrationReporter.js.map +1 -0
- package/lib/utils/resultsbuilder/DRAssessmentReporter.js +38 -70
- package/lib/utils/resultsbuilder/DRAssessmentReporter.js.map +1 -1
- package/lib/utils/resultsbuilder/ExperienceSiteAssessmentReporter.d.ts +14 -0
- package/lib/utils/resultsbuilder/ExperienceSiteAssessmentReporter.js +143 -0
- package/lib/utils/resultsbuilder/ExperienceSiteAssessmentReporter.js.map +1 -0
- package/lib/utils/resultsbuilder/FlexcardAssessmentReporter.js +46 -85
- package/lib/utils/resultsbuilder/FlexcardAssessmentReporter.js.map +1 -1
- package/lib/utils/resultsbuilder/FlexipageAssessmentReporter.d.ts +1 -0
- package/lib/utils/resultsbuilder/FlexipageAssessmentReporter.js +37 -19
- package/lib/utils/resultsbuilder/FlexipageAssessmentReporter.js.map +1 -1
- package/lib/utils/resultsbuilder/GlobalAutoNumberAssessmentReporter.js +22 -14
- package/lib/utils/resultsbuilder/GlobalAutoNumberAssessmentReporter.js.map +1 -1
- package/lib/utils/resultsbuilder/IPAssessmentReporter.js +38 -71
- package/lib/utils/resultsbuilder/IPAssessmentReporter.js.map +1 -1
- package/lib/utils/resultsbuilder/LWCAssessmentReporter.d.ts +14 -0
- package/lib/utils/resultsbuilder/LWCAssessmentReporter.js +143 -139
- package/lib/utils/resultsbuilder/LWCAssessmentReporter.js.map +1 -1
- package/lib/utils/resultsbuilder/OSAssessmentReporter.js +41 -88
- package/lib/utils/resultsbuilder/OSAssessmentReporter.js.map +1 -1
- package/lib/utils/resultsbuilder/SaveForLaterAssessmentReporter.d.ts +12 -0
- package/lib/utils/resultsbuilder/SaveForLaterAssessmentReporter.js +109 -0
- package/lib/utils/resultsbuilder/SaveForLaterAssessmentReporter.js.map +1 -0
- package/lib/utils/resultsbuilder/assessmentReporter.d.ts +16 -6
- package/lib/utils/resultsbuilder/assessmentReporter.js +96 -152
- package/lib/utils/resultsbuilder/assessmentReporter.js.map +1 -1
- package/lib/utils/resultsbuilder/helpers/AssessmentReportHelper.d.ts +104 -0
- package/lib/utils/resultsbuilder/helpers/AssessmentReportHelper.js +380 -0
- package/lib/utils/resultsbuilder/helpers/AssessmentReportHelper.js.map +1 -0
- package/lib/utils/resultsbuilder/index.d.ts +37 -1
- package/lib/utils/resultsbuilder/index.js +582 -151
- package/lib/utils/resultsbuilder/index.js.map +1 -1
- package/lib/utils/resultsbuilder/reportingHelper.d.ts +2 -7
- package/lib/utils/resultsbuilder/reportingHelper.js +0 -43
- package/lib/utils/resultsbuilder/reportingHelper.js.map +1 -1
- package/lib/utils/sfcli/project/sfProject.d.ts +29 -0
- package/lib/utils/sfcli/project/sfProject.js +220 -2
- package/lib/utils/sfcli/project/sfProject.js.map +1 -1
- package/lib/utils/shell/cli.js +20 -14
- package/lib/utils/shell/cli.js.map +1 -1
- package/lib/utils/storageUtil.d.ts +14 -1
- package/lib/utils/storageUtil.js +31 -1
- package/lib/utils/storageUtil.js.map +1 -1
- package/lib/utils/stringUtils.d.ts +24 -0
- package/lib/utils/stringUtils.js +76 -9
- package/lib/utils/stringUtils.js.map +1 -1
- package/lib/utils/templateParser/__tests__/test.js +1 -2
- package/lib/utils/templateParser/__tests__/test.js.map +1 -1
- package/lib/utils/templateParser/generate.d.ts +1 -1
- package/lib/utils/templateParser/generate.js.map +1 -1
- package/lib/utils/templateParser/model/elementNode.d.ts +2 -2
- package/lib/utils/templateParser/model/elementNode.js +11 -2
- package/lib/utils/templateParser/model/elementNode.js.map +1 -1
- package/lib/utils/templateParser/model/nodeTypes.js +1 -1
- package/lib/utils/templateParser/model/nodeTypes.js.map +1 -1
- package/lib/utils/templateParser/util.d.ts +2 -2
- package/lib/utils/templateParser/util.js.map +1 -1
- package/lib/utils/validatorService.d.ts +14 -0
- package/lib/utils/validatorService.js +136 -0
- package/lib/utils/validatorService.js.map +1 -0
- package/messages/assess.json +220 -103
- package/messages/clean.json +40 -0
- package/messages/info.json +2 -1
- package/messages/migrate.json +314 -102
- package/oclif.manifest.json +1 -1
- package/package.json +49 -13
- package/lib/commands/basecommand.d.ts +0 -8
- package/lib/commands/basecommand.js +0 -13
- package/lib/commands/basecommand.js.map +0 -1
- package/lib/utils/OmniGlobalAutoNumberPrefManager.d.ts +0 -40
- package/lib/utils/OmniGlobalAutoNumberPrefManager.js +0 -65
- package/lib/utils/OmniGlobalAutoNumberPrefManager.js.map +0 -1
|
@@ -0,0 +1,755 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OmniScriptInstanceMigrationTool = void 0;
|
|
7
|
+
const OmniScriptInstance_1 = __importDefault(require("../mappings/OmniScriptInstance"));
|
|
8
|
+
const OmniScript_1 = __importDefault(require("../mappings/OmniScript"));
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
|
+
const logger_1 = require("../utils/logger");
|
|
11
|
+
const net_1 = require("../utils/net");
|
|
12
|
+
const dataModelService_1 = require("../utils/dataModelService");
|
|
13
|
+
const stringContants_1 = require("../utils/constants/stringContants");
|
|
14
|
+
const base_1 = require("./base");
|
|
15
|
+
const interfaces_1 = require("./interfaces");
|
|
16
|
+
const base_2 = require("./base");
|
|
17
|
+
class OmniScriptInstanceMigrationTool extends base_1.BaseMigrationTool {
|
|
18
|
+
constructor(namespace, connection, logger, messages, ux) {
|
|
19
|
+
super(namespace, connection, logger, messages, ux);
|
|
20
|
+
this.IS_STANDARD_DATA_MODEL = (0, dataModelService_1.isStandardDataModel)();
|
|
21
|
+
}
|
|
22
|
+
getName() {
|
|
23
|
+
return stringContants_1.Constants.OmniScriptSavedSessionsDisplayName;
|
|
24
|
+
}
|
|
25
|
+
getRecordName(record) {
|
|
26
|
+
return record['Name'] || record['Id'];
|
|
27
|
+
}
|
|
28
|
+
getMappings() {
|
|
29
|
+
return [
|
|
30
|
+
{
|
|
31
|
+
source: stringContants_1.Constants.OmniScriptInstanceObjectName,
|
|
32
|
+
target: stringContants_1.Constants.OmniScriptSavedSessionObjectName,
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
async truncate() {
|
|
37
|
+
// Truncation is needed when we migrate from custom to standard data model
|
|
38
|
+
// For custom data model, no truncation is required
|
|
39
|
+
if (this.IS_STANDARD_DATA_MODEL) {
|
|
40
|
+
logger_1.Logger.logVerbose(this.messages.getMessage('skippingTruncation'));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// Delete ALL records from Core, just like OS, IP, and DM do
|
|
44
|
+
// This ensures a clean migration state
|
|
45
|
+
await super.truncate(stringContants_1.Constants.OmniScriptSavedSessionObjectName);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Assess Save for Later instances for migration readiness
|
|
49
|
+
* Checks dependencies on OmniScript migration status
|
|
50
|
+
*/
|
|
51
|
+
async assess(omniAssessmentInfos) {
|
|
52
|
+
try {
|
|
53
|
+
if ((0, dataModelService_1.isStandardDataModelWithMetadataAPIEnabled)()) {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
logger_1.Logger.log(this.messages.getMessage('startingOmniScriptAssessment', [stringContants_1.Constants.OmniScriptSavedSessionsDisplayName]));
|
|
57
|
+
const omniscriptInstances = await this.queryOmniscriptInstance();
|
|
58
|
+
logger_1.Logger.log(this.messages.getMessage('foundOmniScriptsToAssess', [
|
|
59
|
+
omniscriptInstances.length,
|
|
60
|
+
stringContants_1.Constants.OmniScriptSavedSessionsDisplayName,
|
|
61
|
+
]));
|
|
62
|
+
if (omniscriptInstances.length === 0) {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
const { omniProcessMap, omniscriptSet } = await this.assessPrepare(omniscriptInstances, omniAssessmentInfos);
|
|
66
|
+
const progressBar = (0, base_2.createProgressBar)('Assessing', this.getName());
|
|
67
|
+
progressBar.start(omniscriptInstances.length, 0);
|
|
68
|
+
const assessmentInfos = [];
|
|
69
|
+
let progressCounter = 0;
|
|
70
|
+
// Process and set the migration status for both saved sessions and omniscripts
|
|
71
|
+
for (const osInstance of omniscriptInstances) {
|
|
72
|
+
const assessInfo = this.performAssessment(osInstance, omniProcessMap, omniscriptSet);
|
|
73
|
+
assessmentInfos.push(assessInfo);
|
|
74
|
+
progressBar.update(++progressCounter);
|
|
75
|
+
}
|
|
76
|
+
progressBar.stop();
|
|
77
|
+
logger_1.Logger.log(this.messages.getMessage('assessedOmniScriptsCount', [
|
|
78
|
+
assessmentInfos.length,
|
|
79
|
+
stringContants_1.Constants.OmniScriptSavedSessionsDisplayName,
|
|
80
|
+
]));
|
|
81
|
+
return assessmentInfos;
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
if (err instanceof interfaces_1.InvalidEntityTypeError) {
|
|
85
|
+
throw err;
|
|
86
|
+
}
|
|
87
|
+
logger_1.Logger.error(this.messages.getMessage('errorDuringSaveForLaterAssessment', [err.message]));
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Migration of Save for Later instances
|
|
93
|
+
*/
|
|
94
|
+
async migrate() {
|
|
95
|
+
var _a;
|
|
96
|
+
if ((0, dataModelService_1.isStandardDataModelWithMetadataAPIEnabled)()) {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
const originalOsInstanceRecords = new Map();
|
|
100
|
+
const osInstanceUploadInfo = new Map();
|
|
101
|
+
try {
|
|
102
|
+
// verify custom field PackageSavedSessionId__c exists in OmniScriptSavedSession
|
|
103
|
+
const hasCustomField = await this.hasCustomFieldPackageSavedSessionId();
|
|
104
|
+
if (!hasCustomField) {
|
|
105
|
+
logger_1.Logger.error(this.messages.getMessage('ossMissingCustomField'));
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
const omniscriptInstances = await this.queryOmniscriptInstance();
|
|
109
|
+
logger_1.Logger.log(this.messages.getMessage('foundOmniScriptsToMigrate', [
|
|
110
|
+
omniscriptInstances.length,
|
|
111
|
+
stringContants_1.Constants.OmniScriptSavedSessionsDisplayName,
|
|
112
|
+
]));
|
|
113
|
+
if (omniscriptInstances.length === 0) {
|
|
114
|
+
return [];
|
|
115
|
+
}
|
|
116
|
+
const { omniProcessMap } = await this.assessPrepare(omniscriptInstances);
|
|
117
|
+
const progressBar = (0, base_2.createProgressBar)('Migrating', this.getName());
|
|
118
|
+
progressBar.start(omniscriptInstances.length, 0);
|
|
119
|
+
let progressCounter = 0;
|
|
120
|
+
// Process and set the migration status for both saved sessions and omniscripts
|
|
121
|
+
for (const osInstance of omniscriptInstances) {
|
|
122
|
+
const migratedInfo = await this.performMigration(osInstance, omniProcessMap);
|
|
123
|
+
const osInstanceId = String((_a = osInstance['Id']) !== null && _a !== void 0 ? _a : '');
|
|
124
|
+
osInstanceUploadInfo.set(osInstanceId, migratedInfo);
|
|
125
|
+
originalOsInstanceRecords.set(osInstanceId, osInstance);
|
|
126
|
+
progressBar.update(++progressCounter);
|
|
127
|
+
}
|
|
128
|
+
progressBar.stop();
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
logger_1.Logger.error(this.messages.getMessage('ossMigrationFailed'), error);
|
|
132
|
+
}
|
|
133
|
+
return [
|
|
134
|
+
{
|
|
135
|
+
name: this.getName(),
|
|
136
|
+
results: osInstanceUploadInfo,
|
|
137
|
+
records: originalOsInstanceRecords,
|
|
138
|
+
},
|
|
139
|
+
];
|
|
140
|
+
}
|
|
141
|
+
async assessPrepare(omniscriptInstances, omniAssessmentInfos) {
|
|
142
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
143
|
+
let omniscriptSet = new Set();
|
|
144
|
+
if (omniAssessmentInfos && omniAssessmentInfos.osAssessmentInfos) {
|
|
145
|
+
omniscriptSet = this.extractUniqueNamesFromOmniscriptAssessment(omniAssessmentInfos.osAssessmentInfos);
|
|
146
|
+
}
|
|
147
|
+
const omniscriptTypes = new Set();
|
|
148
|
+
// extract all OmniscriptType__c field from omniscriptInstance to prepare for query
|
|
149
|
+
// NOTE : if OmniscriptType__c is null for an omniscriptInstance,
|
|
150
|
+
// it means that the original omniscript has been deleted AND this specific instance might be unrepairable
|
|
151
|
+
for (const osInst of omniscriptInstances) {
|
|
152
|
+
const osType = String((_a = osInst[this.getOmniscriptInstancePackageFieldKey('OmniScriptType__c')]) !== null && _a !== void 0 ? _a : '');
|
|
153
|
+
if (osInst && osType !== '') {
|
|
154
|
+
omniscriptTypes.add(osType);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// query for Omniscript__c if omniscriptAssessment did not provide any information
|
|
158
|
+
if (omniscriptSet.size === 0) {
|
|
159
|
+
const packageOmniscripts = await this.queryPackageOmniscriptsWithType(omniscriptTypes);
|
|
160
|
+
const osType = this.getOmniscriptPackageFieldKey('Type__c');
|
|
161
|
+
const osSubType = this.getOmniscriptPackageFieldKey('SubType__c');
|
|
162
|
+
const osLanguage = this.getOmniscriptPackageFieldKey('Language__c');
|
|
163
|
+
omniscriptSet = new Set();
|
|
164
|
+
for (const pkgos of packageOmniscripts) {
|
|
165
|
+
const uniqueOmniProcessString = String((_b = pkgos[osType]) !== null && _b !== void 0 ? _b : '') + String((_c = pkgos[osSubType]) !== null && _c !== void 0 ? _c : '') + String((_d = pkgos[osLanguage]) !== null && _d !== void 0 ? _d : '');
|
|
166
|
+
if (uniqueOmniProcessString !== '') {
|
|
167
|
+
omniscriptSet.add(uniqueOmniProcessString);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// query for OmniProcesses matching the types defined in the OmniscriptInstance__c
|
|
172
|
+
const omniProcesses = await this.queryOmniProcessesWithType(omniscriptTypes);
|
|
173
|
+
// extract the unique string for each omni process, store it in a set, it will be used
|
|
174
|
+
// later to determine the omniscript migration status
|
|
175
|
+
const omniProcessMap = new Map();
|
|
176
|
+
for (const omniProcess of omniProcesses) {
|
|
177
|
+
const uniqueOmniProcessString = String((_e = omniProcess['Type']) !== null && _e !== void 0 ? _e : '') +
|
|
178
|
+
String((_f = omniProcess['SubType']) !== null && _f !== void 0 ? _f : '') +
|
|
179
|
+
String((_g = omniProcess['Language']) !== null && _g !== void 0 ? _g : '');
|
|
180
|
+
const recordId = String(omniProcess['Id']);
|
|
181
|
+
if (uniqueOmniProcessString !== '' && recordId !== '') {
|
|
182
|
+
omniProcessMap.set(uniqueOmniProcessString, recordId);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
omniProcessMap,
|
|
187
|
+
omniscriptSet,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
extractUniqueNamesFromOmniscriptAssessment(osAssessmentInfos) {
|
|
191
|
+
var _a, _b, _c;
|
|
192
|
+
const omniscriptSet = new Set();
|
|
193
|
+
if (Array.isArray(osAssessmentInfos)) {
|
|
194
|
+
for (const osAssessInfo of osAssessmentInfos) {
|
|
195
|
+
// assessment info for omniscripts will show what the old and newType, newSubtype and newLanguage
|
|
196
|
+
// newType, newSubType, newLanguage will show up regardless of migration,
|
|
197
|
+
// so that OmniProcess doesn't even have to exist
|
|
198
|
+
if (osAssessInfo) {
|
|
199
|
+
const nameMapping = osAssessInfo['nameMapping'];
|
|
200
|
+
if (nameMapping != null) {
|
|
201
|
+
const uniqueOmniscriptString = String((_a = nameMapping['newType']) !== null && _a !== void 0 ? _a : '') +
|
|
202
|
+
String((_b = nameMapping['newSubType']) !== null && _b !== void 0 ? _b : '') +
|
|
203
|
+
String((_c = nameMapping['newLanguage']) !== null && _c !== void 0 ? _c : '');
|
|
204
|
+
if (uniqueOmniscriptString !== '') {
|
|
205
|
+
omniscriptSet.add(uniqueOmniscriptString);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return omniscriptSet;
|
|
212
|
+
}
|
|
213
|
+
performAssessment(osInstance, omniProcessMap, omniscriptSet) {
|
|
214
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
215
|
+
const osId = String((_a = osInstance[this.getOmniscriptInstancePackageFieldKey('OmniScriptId__c')]) !== null && _a !== void 0 ? _a : '');
|
|
216
|
+
const osType = String((_b = osInstance[this.getOmniscriptInstancePackageFieldKey('OmniScriptType__c')]) !== null && _b !== void 0 ? _b : '');
|
|
217
|
+
const osSubType = String((_c = osInstance[this.getOmniscriptInstancePackageFieldKey('OmniScriptSubType__c')]) !== null && _c !== void 0 ? _c : '');
|
|
218
|
+
const osLanguage = String((_d = osInstance[this.getOmniscriptInstancePackageFieldKey('OmniScriptLanguage__c')]) !== null && _d !== void 0 ? _d : '');
|
|
219
|
+
const osInstanceId = String((_e = osInstance['Id']) !== null && _e !== void 0 ? _e : '');
|
|
220
|
+
const osInstanceName = String((_f = osInstance['Name']) !== null && _f !== void 0 ? _f : '');
|
|
221
|
+
const osInstanceStatus = String((_g = osInstance[this.getOmniscriptInstancePackageFieldKey('Status__c')]) !== null && _g !== void 0 ? _g : '');
|
|
222
|
+
const osInstanceLastSaved = String((_h = osInstance[this.getOmniscriptInstancePackageFieldKey('LastSaved__c')]) !== null && _h !== void 0 ? _h : '');
|
|
223
|
+
const uniqueOmniProcessString = osType + osSubType + osLanguage;
|
|
224
|
+
const osUniqueName = osType !== '' ? `${osType}_${osSubType}_${osLanguage}` : '';
|
|
225
|
+
const errors = [];
|
|
226
|
+
const dependencies = [];
|
|
227
|
+
let migrationStatus = 'Ready for migration';
|
|
228
|
+
let omniScriptMigrationStatus = 'Ready for migration';
|
|
229
|
+
// if omniscriptInstance's referenced omniscript is not migrated to core
|
|
230
|
+
// then check the passed in omniscripts assessments from managed package
|
|
231
|
+
if (omniProcessMap.has(uniqueOmniProcessString)) {
|
|
232
|
+
// active Omni Process is in the org (already migrated)
|
|
233
|
+
migrationStatus = 'Ready for migration';
|
|
234
|
+
omniScriptMigrationStatus = 'Complete';
|
|
235
|
+
}
|
|
236
|
+
else if (omniscriptSet.has(uniqueOmniProcessString)) {
|
|
237
|
+
// active Omniscript__c is in the org
|
|
238
|
+
// No active Omni Process
|
|
239
|
+
migrationStatus = 'Ready for migration';
|
|
240
|
+
omniScriptMigrationStatus = 'Ready for migration';
|
|
241
|
+
const osNeedsToBeDeployed = this.messages.getMessage('omniscriptNeedsToBeMigrated', [osUniqueName]);
|
|
242
|
+
errors.push(osNeedsToBeDeployed);
|
|
243
|
+
dependencies.push(osUniqueName);
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
// both Omniscript__c and Omni Process does not exist in the org, panic
|
|
247
|
+
// OR
|
|
248
|
+
// OmniscriptInstance having no data for OmniScriptType__c probably means the Omniscript__c no longer exists in the Org.
|
|
249
|
+
migrationStatus = 'Needs manual intervention';
|
|
250
|
+
omniScriptMigrationStatus = 'Needs manual intervention';
|
|
251
|
+
const unableToFindOs = this.messages.getMessage('unableToFindActiveOmniscript', [osUniqueName]);
|
|
252
|
+
const followUpMsg = this.messages.getMessage('omniscriptDoesNotExistOrActivate');
|
|
253
|
+
let msg = `${unableToFindOs}`;
|
|
254
|
+
if (osType === '') {
|
|
255
|
+
const noOsFound = this.messages.getMessage('noOmniscriptFoundForOsInstance', [osInstanceName]);
|
|
256
|
+
// OmniscriptInstance having no data for OmniScriptType__c probably means the Omniscript no longer exists in the Org.
|
|
257
|
+
msg = `${noOsFound}`;
|
|
258
|
+
}
|
|
259
|
+
errors.push(msg);
|
|
260
|
+
errors.push(followUpMsg);
|
|
261
|
+
}
|
|
262
|
+
const assessInfo = {
|
|
263
|
+
id: osInstanceId,
|
|
264
|
+
name: osInstanceName,
|
|
265
|
+
oldName: osInstanceName,
|
|
266
|
+
omniScriptId: osId,
|
|
267
|
+
omniScriptName: osUniqueName,
|
|
268
|
+
status: osInstanceStatus,
|
|
269
|
+
lastSaved: osInstanceLastSaved,
|
|
270
|
+
migrationStatus,
|
|
271
|
+
omniScriptMigrationStatus,
|
|
272
|
+
dependenciesOS: dependencies,
|
|
273
|
+
errors,
|
|
274
|
+
infos: [],
|
|
275
|
+
warnings: [],
|
|
276
|
+
};
|
|
277
|
+
return assessInfo;
|
|
278
|
+
}
|
|
279
|
+
async performMigration(osInstance, omniProcessMap) {
|
|
280
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
281
|
+
const errors = [];
|
|
282
|
+
const warnings = [];
|
|
283
|
+
let skipped = false;
|
|
284
|
+
// Extract OmniScript Instance data
|
|
285
|
+
const osInstanceId = String((_a = osInstance['Id']) !== null && _a !== void 0 ? _a : '');
|
|
286
|
+
const osInstanceName = String((_b = osInstance['Name']) !== null && _b !== void 0 ? _b : '');
|
|
287
|
+
const osTypeFieldKey = this.getOmniscriptInstancePackageFieldKey('OmniScriptType__c');
|
|
288
|
+
const osSubTypeFieldKey = this.getOmniscriptInstancePackageFieldKey('OmniScriptSubType__c');
|
|
289
|
+
const osLanguageFieldKey = this.getOmniscriptInstancePackageFieldKey('OmniScriptLanguage__c');
|
|
290
|
+
const osType = String((_c = osInstance[osTypeFieldKey]) !== null && _c !== void 0 ? _c : '');
|
|
291
|
+
const osSubType = String((_d = osInstance[osSubTypeFieldKey]) !== null && _d !== void 0 ? _d : '');
|
|
292
|
+
const osLanguage = String((_e = osInstance[osLanguageFieldKey]) !== null && _e !== void 0 ? _e : '');
|
|
293
|
+
if (osType === '' || osSubType === '' || osLanguage === '') {
|
|
294
|
+
errors.push(this.messages.getMessage('ossMissingFieldValue', [
|
|
295
|
+
osInstanceName,
|
|
296
|
+
osTypeFieldKey,
|
|
297
|
+
osSubTypeFieldKey,
|
|
298
|
+
osLanguageFieldKey,
|
|
299
|
+
]));
|
|
300
|
+
skipped = true;
|
|
301
|
+
const uploadedRecord = {
|
|
302
|
+
referenceId: osInstanceId,
|
|
303
|
+
id: '',
|
|
304
|
+
success: errors.length === 0,
|
|
305
|
+
hasErrors: errors.length > 0,
|
|
306
|
+
errors,
|
|
307
|
+
warnings,
|
|
308
|
+
newName: osInstanceName,
|
|
309
|
+
skipped,
|
|
310
|
+
};
|
|
311
|
+
return uploadedRecord;
|
|
312
|
+
}
|
|
313
|
+
// Extract OmniProcess Id from omniProcessSet
|
|
314
|
+
const uniqueOmniProcessString = osType + osSubType + osLanguage;
|
|
315
|
+
const targetOmniProcessId = omniProcessMap.get(uniqueOmniProcessString);
|
|
316
|
+
if (!targetOmniProcessId) {
|
|
317
|
+
errors.push(this.messages.getMessage('ossOmniscriptNeedsMigration', [osType, osSubType, osLanguage]));
|
|
318
|
+
skipped = true;
|
|
319
|
+
const uploadedRecord = {
|
|
320
|
+
referenceId: osInstanceId,
|
|
321
|
+
id: '',
|
|
322
|
+
success: errors.length === 0,
|
|
323
|
+
hasErrors: errors.length > 0,
|
|
324
|
+
errors,
|
|
325
|
+
warnings,
|
|
326
|
+
newName: osInstanceName,
|
|
327
|
+
skipped,
|
|
328
|
+
};
|
|
329
|
+
return uploadedRecord;
|
|
330
|
+
}
|
|
331
|
+
logger_1.Logger.debug(this.messages.getMessage('ossFoundOmniProcess', [osType, osSubType, osLanguage, targetOmniProcessId]));
|
|
332
|
+
// Construct data for OmniScriptSavedSession
|
|
333
|
+
const savedSessionData = {};
|
|
334
|
+
// Map fields from OmniScriptInstance__c to OmniScriptSavedSession
|
|
335
|
+
for (const [packageField, coreField] of Object.entries(OmniScriptInstance_1.default)) {
|
|
336
|
+
const packageFieldKey = this.getOmniscriptInstancePackageFieldKey(packageField);
|
|
337
|
+
const sourceValue = String((_f = osInstance[packageFieldKey]) !== null && _f !== void 0 ? _f : '');
|
|
338
|
+
if (sourceValue !== '') {
|
|
339
|
+
savedSessionData[coreField] = sourceValue;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
delete savedSessionData['IsWebCompEnabled'];
|
|
343
|
+
delete savedSessionData['OmniScriptVersionNumber'];
|
|
344
|
+
delete savedSessionData['OmniScriptType'];
|
|
345
|
+
delete savedSessionData['OmniScriptSubType'];
|
|
346
|
+
delete savedSessionData['OmniScriptLanguage'];
|
|
347
|
+
savedSessionData['Name'] = osInstanceName;
|
|
348
|
+
savedSessionData['OmniScriptId'] = targetOmniProcessId;
|
|
349
|
+
savedSessionData['PackageSavedSessionId__c'] = osInstanceId;
|
|
350
|
+
// Upload to OmniScriptSavedSession
|
|
351
|
+
const omniscriptSavedSessionResult = await this.migrateCreateOmniscriptSavedSession(osInstanceId, osInstanceName, osType, osSubType, osLanguage, savedSessionData);
|
|
352
|
+
if (((_g = omniscriptSavedSessionResult === null || omniscriptSavedSessionResult === void 0 ? void 0 : omniscriptSavedSessionResult.errors) === null || _g === void 0 ? void 0 : _g.length) > 0) {
|
|
353
|
+
errors.push(...omniscriptSavedSessionResult.errors);
|
|
354
|
+
}
|
|
355
|
+
// Extract Id for OmniScriptSavedSession
|
|
356
|
+
const newSavedSessionId = omniscriptSavedSessionResult === null || omniscriptSavedSessionResult === void 0 ? void 0 : omniscriptSavedSessionResult.id;
|
|
357
|
+
if (!newSavedSessionId) {
|
|
358
|
+
const errMsg = this.messages.getMessage('ossSkipAttachmentUpload', [osInstanceName]);
|
|
359
|
+
logger_1.Logger.error(errMsg);
|
|
360
|
+
errors.push(errMsg);
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
// Extract all attachment object information for current omniscriptInstance record
|
|
364
|
+
// includes the url to the content of the attachment Body
|
|
365
|
+
const attachments = await this.queryAttachments(osInstanceId);
|
|
366
|
+
logger_1.Logger.log(this.messages.getMessage('ossFoundAttachments', [attachments.length, osInstanceId]));
|
|
367
|
+
// Download attachment body
|
|
368
|
+
const attachmentBodyData = await this.downloadAttachments(attachments);
|
|
369
|
+
// Transform / replace references to managed package in attachments Body : OmniscriptFullJSON.json
|
|
370
|
+
// Upload Attachment with Saved Session's Id as ParentId
|
|
371
|
+
const uploadAttachmentResult = await this.migrateUploadAttachments(attachmentBodyData, newSavedSessionId, osInstanceName);
|
|
372
|
+
if (((_h = uploadAttachmentResult === null || uploadAttachmentResult === void 0 ? void 0 : uploadAttachmentResult.errors) === null || _h === void 0 ? void 0 : _h.length) > 0) {
|
|
373
|
+
errors.concat(uploadAttachmentResult.errors);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
const uploadedRecord = {
|
|
377
|
+
referenceId: osInstanceId,
|
|
378
|
+
id: newSavedSessionId,
|
|
379
|
+
success: errors.length === 0,
|
|
380
|
+
hasErrors: errors.length > 0,
|
|
381
|
+
errors,
|
|
382
|
+
warnings,
|
|
383
|
+
newName: osInstanceName,
|
|
384
|
+
skipped,
|
|
385
|
+
};
|
|
386
|
+
return uploadedRecord;
|
|
387
|
+
}
|
|
388
|
+
async migrateCreateOmniscriptSavedSession(osInstanceId, osInstanceName, osType, osSubType, osLanguage, savedSessionData) {
|
|
389
|
+
var _a, _b;
|
|
390
|
+
const errors = [];
|
|
391
|
+
let recordId = '';
|
|
392
|
+
let uploadResult;
|
|
393
|
+
try {
|
|
394
|
+
uploadResult = await net_1.NetUtils.createOne(this.connection, stringContants_1.Constants.OmniScriptSavedSessionObjectName, osInstanceId, savedSessionData);
|
|
395
|
+
if (!uploadResult.success || uploadResult.hasErrors) {
|
|
396
|
+
const errMsg = this.messages.getMessage('ossCreateOssFailure', [osInstanceName, JSON.stringify(uploadResult)]);
|
|
397
|
+
logger_1.Logger.error(errMsg);
|
|
398
|
+
errors.push(errMsg);
|
|
399
|
+
}
|
|
400
|
+
recordId = uploadResult.id || '';
|
|
401
|
+
logger_1.Logger.logVerbose(this.messages.getMessage('ossCreateOssSuccess', [recordId]));
|
|
402
|
+
}
|
|
403
|
+
catch (error) {
|
|
404
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
405
|
+
const msg = this.messages.getMessage('ossCreateOssError', [osInstanceName, errorMsg]);
|
|
406
|
+
logger_1.Logger.error(msg);
|
|
407
|
+
errors.push(msg);
|
|
408
|
+
}
|
|
409
|
+
if (savedSessionData && recordId !== '') {
|
|
410
|
+
// update the Session Id's Resume Urls with its own record Id
|
|
411
|
+
// replace the URLS
|
|
412
|
+
savedSessionData['ResumeUrl'] = this.replaceResumeSessionUrl(String((_a = savedSessionData['ResumeUrl']) !== null && _a !== void 0 ? _a : ''), osType, osSubType, osLanguage, recordId);
|
|
413
|
+
savedSessionData['RelativeResumeUrl'] = this.replaceResumeSessionUrl(String((_b = savedSessionData['RelativeResumeUrl']) !== null && _b !== void 0 ? _b : ''), osType, osSubType, osLanguage, recordId);
|
|
414
|
+
// resume urls have been updated, show as debugging log
|
|
415
|
+
logger_1.Logger.debug(this.messages.getMessage('ossSessionDataShape', [JSON.stringify(savedSessionData)]));
|
|
416
|
+
try {
|
|
417
|
+
uploadResult = await net_1.NetUtils.updateOne(this.connection, stringContants_1.Constants.OmniScriptSavedSessionObjectName, osInstanceId, recordId, savedSessionData);
|
|
418
|
+
if (!uploadResult.success || uploadResult.hasErrors) {
|
|
419
|
+
const errMsg = this.messages.getMessage('ossUpdateOssFailure', [
|
|
420
|
+
osInstanceName,
|
|
421
|
+
JSON.stringify(uploadResult),
|
|
422
|
+
]);
|
|
423
|
+
logger_1.Logger.error(errMsg);
|
|
424
|
+
errors.push(errMsg);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
catch (error) {
|
|
428
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
429
|
+
const msg = this.messages.getMessage('ossUpdateOssError', [osInstanceName, errorMsg]);
|
|
430
|
+
logger_1.Logger.error(msg);
|
|
431
|
+
errors.push(msg);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return {
|
|
435
|
+
id: recordId,
|
|
436
|
+
createOmniscriptSavedSessionSuccess: errors.length === 0,
|
|
437
|
+
errors,
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
async migrateUploadAttachments(attachments, savedSessionId, osInstanceName) {
|
|
441
|
+
var _a, _b, _c;
|
|
442
|
+
let attachmentsUploaded = 0;
|
|
443
|
+
const errors = [];
|
|
444
|
+
if (attachments.length > 0) {
|
|
445
|
+
logger_1.Logger.logVerbose(this.messages.getMessage('ossAttachmentUploadStart', [attachments.length, osInstanceName]));
|
|
446
|
+
for (const attachment of attachments) {
|
|
447
|
+
const attachmentName = String((_a = attachment['name']) !== null && _a !== void 0 ? _a : '');
|
|
448
|
+
const attachmentData = {
|
|
449
|
+
ParentId: savedSessionId,
|
|
450
|
+
Name: attachmentName,
|
|
451
|
+
Body: String((_b = attachment['body']) !== null && _b !== void 0 ? _b : ''),
|
|
452
|
+
};
|
|
453
|
+
const attachmentId = String((_c = attachment['id']) !== null && _c !== void 0 ? _c : '');
|
|
454
|
+
try {
|
|
455
|
+
const attachResult = await net_1.NetUtils.createOne(this.connection, stringContants_1.Constants.AttachmentObjectName, attachmentId, attachmentData);
|
|
456
|
+
if (!attachResult.success || attachResult.hasErrors) {
|
|
457
|
+
const errorMsg = this.messages.getMessage('ossAttachmentUploadFailed', [
|
|
458
|
+
attachmentName,
|
|
459
|
+
JSON.stringify(attachResult.errors),
|
|
460
|
+
]);
|
|
461
|
+
logger_1.Logger.warn(errorMsg);
|
|
462
|
+
errors.push(errorMsg);
|
|
463
|
+
}
|
|
464
|
+
else {
|
|
465
|
+
attachmentsUploaded++;
|
|
466
|
+
logger_1.Logger.logVerbose(this.messages.getMessage('ossAttachmentUploadSuccess', [attachmentName]));
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
catch (error) {
|
|
470
|
+
const errMsg = error instanceof Error ? error.message : String(error);
|
|
471
|
+
const errorMsg = this.messages.getMessage('ossAttachmentUploadError', [attachmentName, errMsg]);
|
|
472
|
+
logger_1.Logger.warn(errorMsg);
|
|
473
|
+
errors.push(errorMsg);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
logger_1.Logger.logVerbose(this.messages.getMessage('ossAttachmentUploadEnd', [attachmentsUploaded, attachments.length, osInstanceName]));
|
|
477
|
+
}
|
|
478
|
+
return {
|
|
479
|
+
attachmentUploadSuccess: attachmentsUploaded === 3,
|
|
480
|
+
errors,
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
replaceResumeSessionUrl(url, osType, osSubType, osLanguage, osInstanceId) {
|
|
484
|
+
let updatedUrl = url;
|
|
485
|
+
// not a real url
|
|
486
|
+
const urlHostTemp = 'https://migrationtool.omnistudio.salesforce.com';
|
|
487
|
+
let urlObj;
|
|
488
|
+
if (this.isAbsoluteUrl(updatedUrl)) {
|
|
489
|
+
urlObj = new URL(updatedUrl);
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
492
|
+
// relative url requires a temporary host
|
|
493
|
+
urlObj = new URL(updatedUrl, urlHostTemp);
|
|
494
|
+
}
|
|
495
|
+
urlObj.searchParams.set('c__InstanceId', osInstanceId);
|
|
496
|
+
urlObj.searchParams.set('omniscript__type', osType);
|
|
497
|
+
urlObj.searchParams.set('omniscript__subType', osSubType);
|
|
498
|
+
urlObj.searchParams.set('omniscript__language', osLanguage);
|
|
499
|
+
urlObj.searchParams.delete('c__target');
|
|
500
|
+
// replace aura wrapper
|
|
501
|
+
if (urlObj.pathname.indexOf('vlocityLWCOmniWrapper') > -1) {
|
|
502
|
+
urlObj.pathname = '/lightning/page/omnistudio/omniscript';
|
|
503
|
+
}
|
|
504
|
+
if (urlObj.origin === urlHostTemp) {
|
|
505
|
+
updatedUrl = urlObj.pathname + urlObj.search;
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
updatedUrl = urlObj.toString();
|
|
509
|
+
}
|
|
510
|
+
return updatedUrl;
|
|
511
|
+
}
|
|
512
|
+
isAbsoluteUrl(urlString) {
|
|
513
|
+
try {
|
|
514
|
+
new URL(urlString);
|
|
515
|
+
return true; // If no error, it's absolute
|
|
516
|
+
}
|
|
517
|
+
catch {
|
|
518
|
+
return false; // If error, it's relative or invalid
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Query Omni Process (Core) and filter by type using QueryTools pattern
|
|
523
|
+
* Uses mappings to determine which fields to query
|
|
524
|
+
*/
|
|
525
|
+
async queryOmniProcessesWithType(omniProcessTypes) {
|
|
526
|
+
const fields = ['Id', 'Name', 'Type', 'SubType', 'Language'];
|
|
527
|
+
const osTypeList = Array.from(omniProcessTypes);
|
|
528
|
+
const typeInListFilter = `Type IN (${osTypeList.map((s) => `'${s}'`).join(',')})`;
|
|
529
|
+
const filters = ['IsActive = true'];
|
|
530
|
+
let filterQuery = '';
|
|
531
|
+
if (osTypeList.length > 0) {
|
|
532
|
+
filters.push(typeInListFilter);
|
|
533
|
+
filterQuery = filters.join(' AND ');
|
|
534
|
+
}
|
|
535
|
+
else {
|
|
536
|
+
filterQuery = filters.join('');
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* SELECT Name, Type, SubType, Language FROM OmniProcess WHERE Type IN ('sfl','test','other') AND IsActive = true
|
|
540
|
+
*/
|
|
541
|
+
const queryString = `SELECT ${fields.join(',')}
|
|
542
|
+
FROM ${stringContants_1.Constants.OmniProcessObjectName}
|
|
543
|
+
WHERE ${filterQuery}`;
|
|
544
|
+
try {
|
|
545
|
+
return await utils_1.QueryTools.queryCustom(this.connection, queryString);
|
|
546
|
+
}
|
|
547
|
+
catch (err) {
|
|
548
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
549
|
+
logger_1.Logger.error(this.messages.getMessage('errorOmniProcessWithTypeQuery'), error);
|
|
550
|
+
return [];
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Query Omniscripts__c (Package) and filter by type using QueryTools pattern
|
|
555
|
+
* Uses mappings to determine which fields to query
|
|
556
|
+
*/
|
|
557
|
+
async queryPackageOmniscriptsWithType(omniscriptTypes) {
|
|
558
|
+
var _a, _b, _c, _d;
|
|
559
|
+
const osType = String((_a = this.getOmniscriptPackageFieldKey('Type__c')) !== null && _a !== void 0 ? _a : '');
|
|
560
|
+
const osSubType = String((_b = this.getOmniscriptPackageFieldKey('SubType__c')) !== null && _b !== void 0 ? _b : '');
|
|
561
|
+
const osLanguage = String((_c = this.getOmniscriptPackageFieldKey('Language__c')) !== null && _c !== void 0 ? _c : '');
|
|
562
|
+
const osIsActive = String((_d = this.getOmniscriptPackageFieldKey('IsActive__c')) !== null && _d !== void 0 ? _d : '');
|
|
563
|
+
const fields = [osType, osSubType, osLanguage];
|
|
564
|
+
const osTypeList = Array.from(omniscriptTypes);
|
|
565
|
+
const typeInListFilter = `${osType} IN (${osTypeList.map((s) => `'${s}'`).join(',')})`;
|
|
566
|
+
const filters = [`${osIsActive} = true`];
|
|
567
|
+
let filterQuery = '';
|
|
568
|
+
if (osTypeList.length > 0) {
|
|
569
|
+
filters.push(typeInListFilter);
|
|
570
|
+
filterQuery = filters.join(' AND ');
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
573
|
+
filterQuery = filters.join('');
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* SELECT Name, Type, SubType, Language FROM OmniProcess WHERE Type IN ('sfl','test','other') AND IsActive = true
|
|
577
|
+
*/
|
|
578
|
+
const queryString = `SELECT ${fields.join(',')}
|
|
579
|
+
FROM ${this.namespace}__${stringContants_1.Constants.OmniscriptObjectName}
|
|
580
|
+
WHERE ${filterQuery}`;
|
|
581
|
+
try {
|
|
582
|
+
return await utils_1.QueryTools.queryCustom(this.connection, queryString);
|
|
583
|
+
}
|
|
584
|
+
catch (err) {
|
|
585
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
586
|
+
logger_1.Logger.error(this.messages.getMessage('errorOmniProcessWithTypeQuery'), error);
|
|
587
|
+
return [];
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Query OmniscriptInstance__c (Package) using QueryTools pattern
|
|
592
|
+
* Uses mappings to determine which fields to query
|
|
593
|
+
*/
|
|
594
|
+
async queryOmniscriptInstance() {
|
|
595
|
+
const fields = this.getQueryFields(OmniScriptInstance_1.default, false);
|
|
596
|
+
const filters = new Map();
|
|
597
|
+
// Only migrate 'In Progress' sessions
|
|
598
|
+
filters.set(this.getOmniscriptInstanceFieldKey('Status__c'), 'In Progress');
|
|
599
|
+
try {
|
|
600
|
+
return await utils_1.QueryTools.queryWithFilter(this.connection, this.getQueryNamespace(), stringContants_1.Constants.OmniScriptInstanceObjectName, fields, filters);
|
|
601
|
+
}
|
|
602
|
+
catch (err) {
|
|
603
|
+
if (err && typeof err === 'object' && 'errorCode' in err && err.errorCode === 'INVALID_TYPE') {
|
|
604
|
+
throw new interfaces_1.InvalidEntityTypeError(`${stringContants_1.Constants.OmniScriptInstanceObjectName} type is not found under this namespace`);
|
|
605
|
+
}
|
|
606
|
+
return [];
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Query for all attachments with the following parent ids
|
|
611
|
+
*
|
|
612
|
+
* @param attachmentParentIds a set containing ids
|
|
613
|
+
* @returns a list of attachment records with parent ids matching the list of parent ids provided
|
|
614
|
+
*/
|
|
615
|
+
async queryAttachments(attachmentParentId) {
|
|
616
|
+
const fields = ['Id', 'Name', 'Body', 'ContentType'];
|
|
617
|
+
const filterStr = `WHERE ParentId = '${attachmentParentId}'`;
|
|
618
|
+
/**
|
|
619
|
+
* SELECT Id, Name, Body, ContentType FROM Attachment WHERE ParentId = a3eSB000000DI0jYAG)
|
|
620
|
+
*/
|
|
621
|
+
const queryString = `SELECT ${fields.join(',')}
|
|
622
|
+
FROM ${stringContants_1.Constants.AttachmentObjectName}
|
|
623
|
+
${filterStr}`;
|
|
624
|
+
try {
|
|
625
|
+
return await utils_1.QueryTools.queryCustom(this.connection, queryString);
|
|
626
|
+
}
|
|
627
|
+
catch (err) {
|
|
628
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
629
|
+
logger_1.Logger.error(this.messages.getMessage('errorOmniProcessWithTypeQuery'), error);
|
|
630
|
+
return [];
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
async hasCustomFieldPackageSavedSessionId() {
|
|
634
|
+
const fields = ['Name', 'PackageSavedSessionId__c'];
|
|
635
|
+
/**
|
|
636
|
+
* SELECT Name, PackageSavedSessionId__c FROM OmniscriptSavedSession LIMIT 1
|
|
637
|
+
*/
|
|
638
|
+
const queryString = `SELECT ${fields.join(',')}
|
|
639
|
+
FROM ${stringContants_1.Constants.OmniScriptSavedSessionObjectName}
|
|
640
|
+
LIMIT 1`;
|
|
641
|
+
try {
|
|
642
|
+
await utils_1.QueryTools.queryCustom(this.connection, queryString);
|
|
643
|
+
return true;
|
|
644
|
+
}
|
|
645
|
+
catch (err) {
|
|
646
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
647
|
+
logger_1.Logger.error('Does not have PackageSavedSessionId__c', error);
|
|
648
|
+
return false;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Download attachment bodies from Salesforce
|
|
653
|
+
*
|
|
654
|
+
* @param connection - Salesforce connection instance
|
|
655
|
+
* @param attachmentBodyPaths - Array of attachment body URLs (e.g., /services/data/v67.0/sobjects/Attachment/00PSB000003DJG12AO/Body)
|
|
656
|
+
* @returns Array of downloaded attachment data with bodies and any errors
|
|
657
|
+
*/
|
|
658
|
+
async downloadAttachments(attachments) {
|
|
659
|
+
var _a, _b, _c;
|
|
660
|
+
const results = [];
|
|
661
|
+
for (const attachment of attachments) {
|
|
662
|
+
const errors = [];
|
|
663
|
+
const attachmentId = String((_a = attachment['Id']) !== null && _a !== void 0 ? _a : '');
|
|
664
|
+
const attachmentName = String((_b = attachment['Name']) !== null && _b !== void 0 ? _b : '');
|
|
665
|
+
const path = String((_c = attachment['Body']) !== null && _c !== void 0 ? _c : '');
|
|
666
|
+
let body = '';
|
|
667
|
+
try {
|
|
668
|
+
const raw = await this.connection.request({
|
|
669
|
+
method: 'GET',
|
|
670
|
+
url: path,
|
|
671
|
+
});
|
|
672
|
+
if (typeof raw === 'object') {
|
|
673
|
+
body = JSON.stringify(raw);
|
|
674
|
+
}
|
|
675
|
+
else if (typeof raw === 'string') {
|
|
676
|
+
body = raw;
|
|
677
|
+
}
|
|
678
|
+
logger_1.Logger.logVerbose(this.messages.getMessage('ossAttachmentDownloadSuccess', [attachmentId, body.length]));
|
|
679
|
+
}
|
|
680
|
+
catch (error) {
|
|
681
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
682
|
+
const msg = this.messages.getMessage('ossAttachmentDownloadFailed', [path, JSON.stringify(errorMsg)]);
|
|
683
|
+
logger_1.Logger.error(msg);
|
|
684
|
+
errors.push(msg);
|
|
685
|
+
}
|
|
686
|
+
results.push({
|
|
687
|
+
id: attachmentId,
|
|
688
|
+
name: attachmentName,
|
|
689
|
+
body,
|
|
690
|
+
originalPath: path,
|
|
691
|
+
errors,
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
return results;
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* Get field key with namespace prefix from OmniscriptInstanceMapping
|
|
698
|
+
* Uses mappings object to get the source field name, then adds namespace if needed
|
|
699
|
+
*/
|
|
700
|
+
getOmniscriptInstanceFieldKey(fieldName, useStandardDataModel = false) {
|
|
701
|
+
// If fieldName is already a key in mappings, use it directly
|
|
702
|
+
if (Object.prototype.hasOwnProperty.call(OmniScriptInstance_1.default, fieldName)) {
|
|
703
|
+
if (useStandardDataModel) {
|
|
704
|
+
const mappedValue = OmniScriptInstance_1.default[fieldName];
|
|
705
|
+
return mappedValue;
|
|
706
|
+
}
|
|
707
|
+
return `${this.namespace}__${fieldName}`;
|
|
708
|
+
}
|
|
709
|
+
// Otherwise, assume it's already the correct field name
|
|
710
|
+
return fieldName;
|
|
711
|
+
}
|
|
712
|
+
getOmniscriptInstancePackageFieldKey(fieldName) {
|
|
713
|
+
return this.getOmniscriptInstanceFieldKey(fieldName, false);
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Get field key with namespace prefix from OmniscriptMapping
|
|
717
|
+
* Uses mappings object to get the source field name, then adds namespace if needed
|
|
718
|
+
*/
|
|
719
|
+
getOmniscriptFieldKey(fieldName, useStandardDataModel = false) {
|
|
720
|
+
// If fieldName is already a key in mappings, use it directly
|
|
721
|
+
if (Object.prototype.hasOwnProperty.call(OmniScript_1.default, fieldName)) {
|
|
722
|
+
if (useStandardDataModel) {
|
|
723
|
+
const mappedValue = OmniScript_1.default[fieldName];
|
|
724
|
+
return mappedValue;
|
|
725
|
+
}
|
|
726
|
+
return `${this.namespace}__${fieldName}`;
|
|
727
|
+
}
|
|
728
|
+
// Otherwise, assume it's already the correct field name
|
|
729
|
+
return fieldName;
|
|
730
|
+
}
|
|
731
|
+
getOmniscriptPackageFieldKey(fieldName) {
|
|
732
|
+
return this.getOmniscriptFieldKey(fieldName, false);
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Get all field keys from mappings for querying
|
|
736
|
+
* Returns field names without namespace prefix - QueryTools will add it
|
|
737
|
+
*/
|
|
738
|
+
getQueryFields(objectMap, useStandardDataModel) {
|
|
739
|
+
if (useStandardDataModel) {
|
|
740
|
+
return Object.values(objectMap);
|
|
741
|
+
}
|
|
742
|
+
return Object.keys(objectMap);
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Returns the namespace of the managed package
|
|
746
|
+
*
|
|
747
|
+
* @param useStandardDataModel false by default
|
|
748
|
+
* @returns empty string or namespace
|
|
749
|
+
*/
|
|
750
|
+
getQueryNamespace(useStandardDataModel = false) {
|
|
751
|
+
return useStandardDataModel ? '' : this.namespace;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
exports.OmniScriptInstanceMigrationTool = OmniScriptInstanceMigrationTool;
|
|
755
|
+
//# sourceMappingURL=omniscriptInstance.js.map
|