-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathflex.js
59 lines (49 loc) · 1.62 KB
/
flex.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const { TwilioClientCommand } = require('@twilio/cli-core').baseCommands;
const { TwilioCliError } = require('@twilio/cli-core').services.error;
const Twilio = require('twilio');
const createToken = require('../../helpers/accessToken.js');
const globalFlags = require('../../helpers/globalFlags.js');
const { taskrouterFlags } = require('../../helpers/taskrouterGlobals.js');
const { validateSid } = require('../../helpers/validation-helpers.js');
class FlexTokenGenerator extends TwilioClientCommand {
constructor(argv, config) {
super(argv, config);
this.showHeaders = true;
}
async run() {
await super.run();
const workerSid = await this.flags['worker-sid'];
const workspaceSid = await this.flags['workspace-sid'];
const accessToken = createToken.call(this);
if (!validateSid('WK', workerSid)) {
this.logger.error(
'Invalid Worker SID, must look like WKxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
);
process.exit(1);
}
if (!validateSid('WS', workspaceSid)) {
this.logger.error(
'Invalid Workspace SID, must look like WSxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
);
process.exit(1);
}
const flexGrant = new Twilio.jwt.AccessToken.TaskRouterGrant({
workerSid,
workspaceSid,
role: 'worker',
});
accessToken.addGrant(flexGrant);
this.logger.info('Copy/paste this video token into your test application:');
this.output({ jwt: accessToken.toJwt() }, undefined, {
showHeaders: false,
});
}
}
const globals = { ...globalFlags };
delete globals.identity;
FlexTokenGenerator.flags = Object.assign(
taskrouterFlags,
TwilioClientCommand.flags,
globals,
);
module.exports = FlexTokenGenerator;