Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@doodle/doodle-node-cli / src / prompts / add-meeting-prompt.js
Size: Mime:
const inquirer = require('inquirer');
const ora = require('ora');
const chalk = require('chalk');
const superb = require('superb');
const { obfuscateString, titleCase } = require('../utils/strings');
const {
  DOODLE_ENVS,
  CONFIG_EMAIL_KEY,
  CONFIG_PASSWORD_KEY,
  verboseLogging,
  MEETING_TYPES,
  VIDEO_CONFERENCING_TOOLS,
} = require('../constants');
const { getTokenForUser } = require('../apis/keycloak');
const { createSchedulingAttempt } = require('../apis/schedex');

const superbWord = superb.random();

/**
 * Create a new Keycloak user.
 *
 * @param {Object} options
 * @param {String} options.email
 * @param {String} options.password
 * @param {String} options.target
 * @param {Boolean} options.premium
 * @param {Object} config
 */
async function createNewMeeting(options = {}, config) {
  await inquirer
    .prompt([
      {
        type: 'list',
        name: 'target',
        message: 'Which environment should meeting be created?',
        choices: Object.keys(DOODLE_ENVS),
        default: 'staging',
        when: !options.target,
      },
      {
        type: 'email',
        name: 'email',
        default: config[CONFIG_EMAIL_KEY],
        message: `Enter the email address of the user:`,
        when: !options.email,
      },
      {
        type: 'password',
        name: 'password',
        message: `Enter the user's password (leave blank for default: ${obfuscateString(
          config[CONFIG_PASSWORD_KEY]
        )}):`,
        default: config[CONFIG_PASSWORD_KEY],
        when: !options.password,
      },
      {
        type: 'list',
        name: 'meetingType',
        message: 'What is the meeting type?',
        choices: Object.keys(MEETING_TYPES),
        filter: input => MEETING_TYPES[input],
        when: !options.meetingType,
      },
      {
        type: 'confirm',
        name: 'allDay',
        message: 'Use All-day time options?',
        default: false,
        when: !options.allDay,
      },
      {
        type: 'input',
        name: 'meetingTitle',
        message: 'Meeting Title:',
        when: !options.meetingTitle,
        default: `My ${titleCase(superbWord)} Test Meeting`,
      },
      {
        type: 'input',
        name: 'locationText',
        message: 'Location Text',
        default: `A ${superbWord} location`,
        when: !options.locationText,
      },
      {
        type: 'input',
        name: 'descriptionText',
        message: 'Meeting Description',
        when: !options.descriptionText,
        default: `A ${superbWord} test meeting created with doodle-node-cli`,
      },
      {
        type: 'list',
        name: 'videoConferencing',
        message: 'Add Video Conferencing?',
        choices: [...Object.keys(VIDEO_CONFERENCING_TOOLS), 'No'],
        default: 'No',
        filter: input => (input === 'No' ? null : VIDEO_CONFERENCING_TOOLS[input]),
        when: !options.videoConferencing,
      },
    ])
    .then(async answers => {
      const finalAnswers = {
        ...options,
        ...answers,
      };

      const { target, email, password, meetingTitle } = finalAnswers;

      const spinner = ora(`Creating scheduling attempt: ${chalk.yellow(meetingTitle)}`).start();
      let userAccountToken;

      try {
        // Get the service account token to manage users
        const userToken = await getTokenForUser(target, email, password);
        userAccountToken = userToken.access_token;

        if (verboseLogging) {
          console.log({
            ...finalAnswers,
            userAccountToken,
          });
        }

        const SchedulingAttempt = await createSchedulingAttempt(target, userAccountToken, finalAnswers);

        spinner.succeed(`Created scheduling attempt: ${chalk.yellow(meetingTitle)}`);

        const { baseUrl } = DOODLE_ENVS[target];
        const inviteeUrl = `${baseUrl}/meeting/participate/id/${SchedulingAttempt.id}`;

        console.log(SchedulingAttempt);

        spinner.info(`${chalk.yellow('Invitee URL')}: ${inviteeUrl}`);
      } catch (err) {
        spinner.fail(err.message || 'Could not create meeting');
        console.error(err);
        process.exit(1);
      }
    });
}

module.exports = createNewMeeting;