@@ -28,6 +28,7 @@ import {
2828 ScratchOrgInfo ,
2929 ScratchOrgRequest ,
3030} from '@salesforce/core' ;
31+ import { lowerToUpper } from '../../../shared/utils' ;
3132import { SandboxReporter } from '../../../shared/sandboxReporter' ;
3233
3334Messages . importMessagesDirectory ( __dirname ) ;
@@ -122,43 +123,29 @@ export class Create extends SfdxCommand {
122123 }
123124
124125 if ( this . flags . clientid ) {
125- this . ux . warn ( messages . getMessage ( 'clientIdNotSupported' , [ this . flags . clientid ] ) ) ;
126+ this . ux . warn ( messages . getMessage ( 'clientIdNotSupported' , [ this . flags . clientid as string ] ) ) ;
126127 }
127128 if ( this . flags . nonamespace ) {
128- this . ux . warn ( messages . getMessage ( 'noNamespaceNotSupported' , [ this . flags . nonamespace ] ) ) ;
129+ this . ux . warn ( messages . getMessage ( 'noNamespaceNotSupported' , [ this . flags . nonamespace as boolean ] ) ) ;
129130 }
130131 if ( this . flags . noancestors ) {
131- this . ux . warn ( messages . getMessage ( 'noAncestorsNotSupported' , [ this . flags . noancestors ] ) ) ;
132+ this . ux . warn ( messages . getMessage ( 'noAncestorsNotSupported' , [ this . flags . noancestors as boolean ] ) ) ;
132133 }
133134 if ( this . flags . durationdays ) {
134- this . ux . warn ( messages . getMessage ( 'durationDaysNotSupported' , [ this . flags . durationdays ] ) ) ;
135+ this . ux . warn ( messages . getMessage ( 'durationDaysNotSupported' , [ this . flags . durationdays as number ] ) ) ;
135136 }
136137 }
137138
138- private lowerToUpper ( object : Record < string , unknown > ) : Record < string , unknown > {
139- // the API has keys defined in capital camel case, while the definition schema has them as lower camel case
140- // we need to convert lower camel case to upper before merging options so they will override properly
141- Object . keys ( object ) . map ( ( key ) => {
142- const upperCase = key . charAt ( 0 ) . toUpperCase ( ) ;
143- if ( key . charAt ( 0 ) !== upperCase ) {
144- const capitalKey = upperCase + key . slice ( 1 ) ;
145- object [ capitalKey ] = object [ key ] ;
146- delete object [ key ] ;
147- }
148- } ) ;
149- return object ;
150- }
151-
152139 private createSandboxRequest ( ) : SandboxRequest {
153140 this . logger . debug ( 'Create Varargs: %s ' , this . varargs ) ;
154141 let sandboxDefFileContents = this . readJsonDefFile ( ) ;
155142 let capitalizedVarArgs = { } ;
156143
157144 if ( sandboxDefFileContents ) {
158- sandboxDefFileContents = this . lowerToUpper ( sandboxDefFileContents ) ;
145+ sandboxDefFileContents = lowerToUpper ( sandboxDefFileContents ) ;
159146 }
160147 if ( this . varargs ) {
161- capitalizedVarArgs = this . lowerToUpper ( this . varargs ) ;
148+ capitalizedVarArgs = lowerToUpper ( this . varargs ) ;
162149 }
163150 // varargs override file input
164151 const sandboxReq : SandboxRequest = { SandboxName : undefined , ...sandboxDefFileContents , ...capitalizedVarArgs } ;
@@ -184,7 +171,9 @@ export class Create extends SfdxCommand {
184171 // `on` doesn't support synchronous methods
185172 // eslint-disable-next-line @typescript-eslint/require-await
186173 lifecycle . on ( SandboxEvents . EVENT_ASYNC_RESULT , async ( results : SandboxProcessObject ) => {
187- this . ux . log ( messages . getMessage ( 'sandboxSuccess' , [ results . Id , results . SandboxName , this . flags . targetusername ] ) ) ;
174+ this . ux . log (
175+ messages . getMessage ( 'sandboxSuccess' , [ results . Id , results . SandboxName , this . flags . targetusername as string ] )
176+ ) ;
188177 } ) ;
189178
190179 // eslint-disable-next-line @typescript-eslint/require-await
@@ -208,7 +197,7 @@ export class Create extends SfdxCommand {
208197 if ( results . sandboxRes ?. authUserName ) {
209198 if ( this . flags . setalias ) {
210199 const stateAggregator = await StateAggregator . getInstance ( ) ;
211- stateAggregator . aliases . set ( this . flags . setalias , results . sandboxRes . authUserName ) ;
200+ stateAggregator . aliases . set ( this . flags . setalias as string , results . sandboxRes . authUserName ) ;
212201 const result = await stateAggregator . aliases . write ( ) ;
213202 this . logger . debug ( 'Set Alias: %s result: %s' , this . flags . setalias , result ) ;
214203 }
@@ -227,15 +216,15 @@ export class Create extends SfdxCommand {
227216 const wait = this . flags . wait as Duration ;
228217
229218 try {
230- return prodOrg . createSandbox ( sandboxReq , { wait } ) ;
219+ return await prodOrg . createSandbox ( sandboxReq , { wait } ) ;
231220 } catch ( e ) {
232221 // guaranteed to be SfdxError from core;
233222 const err = e as SfError ;
234223 if ( err ?. message . includes ( 'The org cannot be found' ) ) {
235224 // there was most likely an issue with DNS when auth'ing to the new sandbox, but it was created.
236225 if ( this . flags . setalias && this . sandboxAuth ) {
237226 const stateAggregator = await StateAggregator . getInstance ( ) ;
238- stateAggregator . aliases . set ( this . flags . setalias , this . sandboxAuth . authUserName ) ;
227+ stateAggregator . aliases . set ( this . flags . setalias as string , this . sandboxAuth . authUserName ) ;
239228 const result = await stateAggregator . aliases . write ( ) ;
240229 this . logger . debug ( 'Set Alias: %s result: %s' , this . flags . setalias , result ) ;
241230 }
@@ -256,7 +245,7 @@ export class Create extends SfdxCommand {
256245 // the -f option
257246 if ( this . flags . definitionfile ) {
258247 this . logger . debug ( 'Reading JSON DefFile %s ' , this . flags . definitionfile ) ;
259- return JSON . parse ( fs . readFileSync ( this . flags . definitionfile , 'utf-8' ) ) as Record < string , unknown > ;
248+ return JSON . parse ( fs . readFileSync ( this . flags . definitionfile as string , 'utf-8' ) ) as Record < string , unknown > ;
260249 }
261250 }
262251
0 commit comments