Skip to content

Commit fc59625

Browse files
Refactor and pull out sid validation to helper func
1 parent 31e7df4 commit fc59625

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/commands/token/chat.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const { TwilioClientCommand } = require('@twilio/cli-core').baseCommands;
33
const Twilio = require('twilio');
44
const createToken = require('../../helpers/accessToken.js');
55
const globalFlags = require('../../helpers/globalFlags.js');
6+
const { validateSid } = require('../../helpers/validation-helpers.js');
67

78
class ChatTokenGenerator extends TwilioClientCommand {
89
constructor(argv, config) {
@@ -11,20 +12,13 @@ class ChatTokenGenerator extends TwilioClientCommand {
1112
this.showHeaders = true;
1213
}
1314

14-
validateChatServiceSid(sid) {
15-
return (
16-
sid.startsWith('IS') &&
17-
sid.length === 34
18-
);
19-
}
20-
2115
async run() {
2216
await super.run();
2317

2418
const chatServiceSid = await this.flags['chat-service-sid'];
2519
const accessToken = createToken.call(this);
2620

27-
if (!this.validateChatServiceSid(chatServiceSid)) {
21+
if (!validateSid('IS', chatServiceSid)) {
2822
this.logger.error(
2923
'Invalid Chat Service SID, must look like ISxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
3024
);

src/helpers/validation-helpers.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const validateSid = function (prefix, sid) {
2+
return (sid.startsWith(prefix) &&
3+
sid.length === 34
4+
);
5+
};
6+
7+
module.exports = { validateSid };

0 commit comments

Comments
 (0)