11const { TwilioClientCommand } = require ( '@twilio/cli-core' ) . baseCommands ;
22const ClientCapability = require ( 'twilio' ) . jwt . ClientCapability ;
33const globalFlags = require ( '../../../helpers/globalFlags.js' ) ;
4- const { voiceFlags, validateTwimlAppSid } = require ( '../../../helpers/voiceGlobals.js' ) ;
4+ const { voiceFlags } = require ( '../../../helpers/voiceGlobals.js' ) ;
5+ const { validateSid } = require ( '../../../helpers/validation-helpers.js' ) ;
56
67class ClientCapabilityTokenGenerator extends TwilioClientCommand {
78 constructor ( argv , config ) {
@@ -13,27 +14,29 @@ class ClientCapabilityTokenGenerator extends TwilioClientCommand {
1314 async run ( ) {
1415 await super . run ( ) ;
1516
16- let ttl = this . flags [ 'ttl' ] ;
17+ const voiceAppSid = await this . flags [ 'voice-app-sid' ] ;
18+ const ttl = await this . flags [ 'ttl' ] ;
19+ const incomingAllow = await this . flags [ 'allow-incoming' ] ;
20+ const identity = await this . flags [ 'identity' ] ;
1721 const capability = new ClientCapability ( {
1822 accountSid : this . twilioClient . accountSid ,
1923 authToken : this . twilioClient . password ,
2024 ttl
2125 } ) ;
2226
23- if ( ! validateTwimlAppSid ( this . flags [ 'voice-app-sid' ] ) ) {
27+ if ( ! validateSid ( 'AP' , voiceAppSid ) ) {
2428 this . logger . error (
2529 'Invalid TwiML Application SID, must look like APxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
2630 ) ;
2731 process . exit ( 1 ) ;
2832 }
2933
3034 capability . addScope ( new ClientCapability . OutgoingClientScope ( {
31- applicationSid : this . flags [ 'voice-app-sid' ]
35+ applicationSid : voiceAppSid
3236 } ) ) ;
3337
34- let incomingAllow = ( this . flags [ 'allow-incoming' ] == 'true' ) ;
3538 if ( incomingAllow ) {
36- capability . addScope ( new ClientCapability . IncomingClientScope ( this . flags [ ' identity' ] ) )
39+ capability . addScope ( new ClientCapability . IncomingClientScope ( identity ) )
3740 }
3841
3942 this . logger . info ( 'Copy/paste this voice token into your test application:' ) ;
0 commit comments