@@ -18,7 +18,7 @@ import {
18
18
User ,
19
19
UserFields ,
20
20
} from '@salesforce/core' ;
21
- import { get , Dictionary , isArray } from '@salesforce/ts-types' ;
21
+ import { getString , Dictionary , isArray } from '@salesforce/ts-types' ;
22
22
import { flags , FlagsConfig , SfdxCommand } from '@salesforce/command' ;
23
23
24
24
Messages . importMessagesDirectory ( __dirname ) ;
@@ -136,13 +136,13 @@ export class UserCreateCommand extends SfdxCommand {
136
136
private async catchCreateUser ( respBody : Error , fields : UserFields ) : Promise < void > {
137
137
// For Gacks, the error message is on response.body[0].message but for handled errors
138
138
// the error message is on response.body.Errors[0].description.
139
- const errMessage = ( get ( respBody , 'message' ) as string ) || 'Unknown Error' ;
139
+ const errMessage = getString ( respBody , 'message' ) || 'Unknown Error' ;
140
140
const conn : Connection = this . org . getConnection ( ) ;
141
141
142
142
// Provide a more user friendly error message for certain server errors.
143
143
if ( errMessage . includes ( 'LICENSE_LIMIT_EXCEEDED' ) ) {
144
144
const res = await conn . query ( `SELECT name FROM profile WHERE id='${ fields . profileId } '` ) ;
145
- const profileName = get ( res , 'records[0].Name' ) as string ;
145
+ const profileName = getString ( res , 'records[0].Name' ) ;
146
146
throw SfdxError . create ( '@salesforce/plugin-user' , 'create' , 'licenseLimitExceeded' , [ profileName ] ) ;
147
147
} else if ( errMessage . includes ( 'DUPLICATE_USERNAME' ) ) {
148
148
throw SfdxError . create ( '@salesforce/plugin-user' , 'create' , 'duplicateUsername' , [ fields . username ] ) ;
@@ -151,19 +151,24 @@ export class UserCreateCommand extends SfdxCommand {
151
151
}
152
152
}
153
153
154
+ private lowerFirstLetter ( word : string ) : string {
155
+ return word [ 0 ] . toLowerCase ( ) + word . substr ( 1 ) ;
156
+ }
157
+
154
158
private async aggregateFields ( defaultFields : UserFields ) : Promise < UserFields & Dictionary < string > > {
155
159
// start with the default fields, then add the fields from the file, then (possibly overwritting) add the fields from the cli varargs param
156
160
if ( this . flags . definitionfile ) {
157
161
const content = await fs . readJson ( this . flags . definitionfile ) ;
158
162
Object . keys ( content ) . forEach ( ( key ) => {
159
- defaultFields [ key ] = content [ key ] ;
163
+ // cast entries to lowercase to standardize
164
+ defaultFields [ this . lowerFirstLetter ( key ) ] = content [ key ] ;
160
165
} ) ;
161
166
}
162
167
163
168
if ( this . varargs ) {
164
169
Object . keys ( this . varargs ) . forEach ( ( key ) => {
165
170
if ( defaultFields [ key ] ) {
166
- defaultFields [ key ] = this . varargs [ key ] ;
171
+ defaultFields [ this . lowerFirstLetter ( key ) ] = this . varargs [ key ] ;
167
172
}
168
173
} ) ;
169
174
}
@@ -174,7 +179,7 @@ export class UserCreateCommand extends SfdxCommand {
174
179
this . logger . debug ( `Querying org for profile name [${ name } ]` ) ;
175
180
const profileQuery = `SELECT id FROM profile WHERE name='${ name } '` ;
176
181
const response = await this . org . getConnection ( ) . query ( profileQuery ) ;
177
- defaultFields . profileId = get ( response , 'records[0].Id' ) as string ;
182
+ defaultFields . profileId = getString ( response , 'records[0].Id' ) ;
178
183
delete defaultFields [ 'profileName' ] ;
179
184
}
180
185
0 commit comments