async function runResetTokenWizard(type, options) {
  if (!options.storage) {
    throw new Error(`Cannot run ${type} token wizard without a storage configuration`);
  }

  // Require this only when run since `@lhci/server` is an optional dependency
  assertOptionalDependency('@lhci/server');
  // eslint-disable-next-line import/no-extraneous-dependencies
  const StorageMethod = require('@lhci/server/src/api/storage/storage-method.js');

  const storageMethod = StorageMethod.from(options.storage);
  await storageMethod.initialize(options.storage);
  const projects = await storageMethod.getProjects();

  process.stdout.write(`\nYou are about to reset the ${type} token for an LHCI project.\n`);
  process.stdout.write(`WARNING: all current token holders will be locked out and will need to `);
  process.stdout.write(`re-enter the new ${type} token to retain their privileges.\n\n`);
  process.stdout.write(`THIS ACTION CANNOT BE UNDONE\nPress Ctrl+C at any time to cancel.\n\n`);

  const {project, confirmationName} = await inquirer.prompt([
    {
      type: 'list',
      name: 'project',
      message: 'Which project would you like to reset?',
      choices: projects
        .map(project => ({
          name: project.name,
          value: project,
        }))
        .sort((a, b) => a.name.localeCompare(b.name)),
    },
    {
      type: 'input',
      name: 'confirmationName',
      message: answers => `Type "${answers.project.name}" to confirm the token reset.`,
    },
  ]);

  if (project.name !== confirmationName && project.name !== `"${confirmationName}"`) {
    process.stdout.write(`${confirmationName} did not match ${project.name}, cancelling.`);
    return;
  }

  const newToken =
    type === 'admin'
      ? await storageMethod._resetAdminToken(project.id)
      : await storageMethod._resetProjectToken(project.id);
  const adminWarning = type === 'admin' ? ' to manage data. KEEP THIS SECRET!' : '';
  process.stdout.write(`Reset token for project ${project.name} (${project.id})!\n`);
  process.stdout.write(`Use ${type} token ${log.bold}${newToken}${log.reset}${adminWarning}\n`);
}
@param {'admin'|'build'} type
@param {LHCI.WizardCommand.Options} options
@return {Promise<void>}