@@ -2,7 +2,8 @@ const { TwilioClientCommand } = require('@twilio/cli-core').baseCommands;
22const Twilio = require ( 'twilio' ) ;
33const createToken = require ( '../../helpers/accessToken.js' ) ;
44const globalFlags = require ( '../../helpers/globalFlags.js' ) ;
5- const { voiceFlags, validateTwimlAppSid, validatePushCredentialSid } = require ( '../../helpers/voiceGlobals.js' ) ;
5+ const { voiceFlags } = require ( '../../helpers/voiceGlobals.js' ) ;
6+ const { validateSid } = require ( '../../helpers/validation-helpers.js' ) ;
67
78class VoiceTokenGenerator extends TwilioClientCommand {
89 constructor ( argv , config ) {
@@ -15,27 +16,31 @@ class VoiceTokenGenerator extends TwilioClientCommand {
1516 await super . run ( ) ;
1617
1718 const accessToken = createToken . call ( this ) ;
19+ // all flags
20+ const voiceAppSid = await this . flags [ 'voice-app-sid' ] ;
21+ const pushCredentialSid = await this . flags [ 'push-credential-sid' ] ;
22+ const incomingAllow = await this . flags [ 'allow-incoming' ] ;
1823
19- if ( ! validateTwimlAppSid ( this . flags [ 'voice-app-sid' ] ) ) {
24+ if ( ! validateSid ( 'AP' , voiceAppSid ) ) {
2025 this . logger . error (
2126 'Invalid TwiML Application SID, must look like APxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
2227 ) ;
2328 process . exit ( 1 ) ;
2429 }
2530
26- let pushCredentialSid = this . flags [ 'push-credential-sid' ] ;
27- if ( pushCredentialSid && ! validatePushCredentialSid ( pushCredentialSid ) ) {
31+ // logic for optional pushCredential
32+ if ( pushCredentialSid && ! validateSid ( 'CR' , pushCredentialSid ) ) {
2833 this . logger . error (
2934 'Invalid Push Credential SID, must look like CRxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
3035 ) ;
3136 process . exit ( 1 ) ;
3237 }
3338
34- let incomingAllow = ( this . flags [ 'allow-incoming' ] == 'true' ) ;
35- let voiceGrant = new Twilio . jwt . AccessToken . VoiceGrant ( {
36- outgoingApplicationSid : this . flags [ 'voice-app-sid' ] ,
39+ const voiceGrant = new Twilio . jwt . AccessToken . VoiceGrant ( {
40+ outgoingApplicationSid : voiceAppSid ,
3741 incomingAllow
3842 } ) ;
43+
3944 if ( pushCredentialSid ) {
4045 voiceGrant . pushCredentialSid = pushCredentialSid ;
4146 }
0 commit comments