@@ -33,6 +33,8 @@ import { GlobalAutoNumberMigrationTool } from '../../../migration/globalautonumb
3333// Initialize Messages with the current plugin directory
3434Messages . importMessagesDirectory ( __dirname ) ;
3535
36+ const authEnvKey = 'OMA_AUTH_KEY' ;
37+
3638// Load the specific messages for this file. Messages from @salesforce /command, @salesforce/core,
3739// or any library that is using the messages framework can also be loaded this way.
3840const messages = Messages . loadMessages ( '@salesforce/plugin-omnistudio-migration-tool' , 'migrate' ) ;
@@ -135,7 +137,7 @@ export default class Migrate extends OmniStudioBaseCommand {
135137 const preMigrate : PreMigrate = new PreMigrate ( this . org , namespace , conn , this . logger , messages , this . ux ) ;
136138 const isExperienceBundleMetadataAPIProgramaticallyEnabled : { value : boolean } = { value : false } ;
137139
138- let autoDeploy = false ;
140+ let deploymentConfig = { autoDeploy : false , authKey : undefined } ;
139141 if ( relatedObjects ) {
140142 const relatedObjectMigrationResult = await this . migrateRelatedObjects (
141143 relatedObjects ,
@@ -146,7 +148,7 @@ export default class Migrate extends OmniStudioBaseCommand {
146148 objectsToProcess = relatedObjectMigrationResult . objectsToProcess ;
147149 projectPath = relatedObjectMigrationResult . projectPath ;
148150 targetApexNamespace = relatedObjectMigrationResult . targetApexNamespace ;
149- autoDeploy = relatedObjectMigrationResult . autoDeploy ;
151+ deploymentConfig = relatedObjectMigrationResult . deploymentConfig ;
150152 }
151153
152154 Logger . log ( messages . getMessage ( 'migrationInitialization' , [ String ( namespace ) ] ) ) ;
@@ -192,16 +194,10 @@ export default class Migrate extends OmniStudioBaseCommand {
192194 messages ,
193195 this . ux ,
194196 objectsToProcess ,
195- autoDeploy ,
197+ deploymentConfig ,
196198 projectPath
197199 ) ;
198200
199- try {
200- postMigrate . deploy ( ) ;
201- } catch ( error ) {
202- Logger . error ( messages . getMessage ( 'errorDeployingComponents' ) , error ) ;
203- }
204-
205201 if ( ! migrateOnly ) {
206202 await postMigrate . setDesignersToUseStandardDataModel ( namespace , actionItems ) ;
207203 }
@@ -216,12 +212,18 @@ export default class Migrate extends OmniStudioBaseCommand {
216212
217213 generatePackageXml . createChangeList (
218214 relatedObjectMigrationResult . apexAssessmentInfos ,
219- relatedObjectMigrationResult . lwcAssessmentInfos ,
215+ deploymentConfig . autoDeploy && deploymentConfig . authKey ? relatedObjectMigrationResult . lwcAssessmentInfos : [ ] ,
220216 relatedObjectMigrationResult . experienceSiteAssessmentInfos ,
221217 relatedObjectMigrationResult . flexipageAssessmentInfos ,
222218 this . org . getConnection ( ) . version
223219 ) ;
224220
221+ try {
222+ postMigrate . deploy ( ) ;
223+ } catch ( error ) {
224+ Logger . error ( messages . getMessage ( 'errorDeployingComponents' ) , error ) ;
225+ }
226+
225227 await ResultsBuilder . generateReport (
226228 objectMigrationResults ,
227229 relatedObjectMigrationResult ,
@@ -241,7 +243,12 @@ export default class Migrate extends OmniStudioBaseCommand {
241243 preMigrate : PreMigrate ,
242244 conn : Connection ,
243245 isExperienceBundleMetadataAPIProgramaticallyEnabled : { value : boolean }
244- ) : Promise < { objectsToProcess : string [ ] ; projectPath : string ; targetApexNamespace : string ; autoDeploy : boolean } > {
246+ ) : Promise < {
247+ objectsToProcess : string [ ] ;
248+ projectPath : string ;
249+ targetApexNamespace : string ;
250+ deploymentConfig : { autoDeploy : boolean ; authKey : string | undefined } ;
251+ } > {
245252 const validOptions = [ Constants . Apex , Constants . ExpSites , Constants . FlexiPage ] ;
246253 const objectsToProcess = relatedObjects . split ( ',' ) . map ( ( obj ) => obj . trim ( ) ) ;
247254 // Validate input
@@ -252,7 +259,7 @@ export default class Migrate extends OmniStudioBaseCommand {
252259 }
253260 }
254261
255- const autoDeploy = await this . getAutoDeployConsent ( ) ;
262+ const deploymentConfig = await this . getAutoDeployConsent ( ) ;
256263 let projectPath : string ;
257264 let targetApexNamespace : string ;
258265 // Check for general consent to make modifications with OMT
@@ -271,10 +278,10 @@ export default class Migrate extends OmniStudioBaseCommand {
271278 ) ;
272279 }
273280
274- return { objectsToProcess, projectPath, targetApexNamespace, autoDeploy } ;
281+ return { objectsToProcess, projectPath, targetApexNamespace, deploymentConfig } ;
275282 }
276283
277- private async getAutoDeployConsent ( ) : Promise < boolean > {
284+ private async getAutoDeployConsent ( ) : Promise < { autoDeploy : boolean ; authKey : string | undefined } > {
278285 const askWithTimeOut = PromptUtil . askWithTimeOut ( messages ) ;
279286 let validResponse = false ;
280287 let consent = false ;
@@ -299,7 +306,18 @@ export default class Migrate extends OmniStudioBaseCommand {
299306 }
300307 }
301308
302- return consent ;
309+ const deploymentConfig = {
310+ autoDeploy : consent ,
311+ authKey : undefined ,
312+ } ;
313+ if ( consent ) {
314+ deploymentConfig . authKey = process . env [ authEnvKey ] ;
315+ if ( ! deploymentConfig . authKey ) {
316+ Logger . error ( messages . getMessage ( 'authKeyEnvVarNotSet' ) ) ;
317+ }
318+ }
319+
320+ return deploymentConfig ;
303321 }
304322
305323 private async getMigrationConsent ( ) : Promise < boolean > {
0 commit comments