given a `UserSession` prompt the user for some search params and search for items
function searchForItems(session) {
  const searchPrompts = [
    {
      type: "text",
      name: "searchText",
      message: "Search Query"
    },
    {
      type: "list",
      name: "itemTypes",
      message: "Item Types"
    },
    {
      type: "list",
      name: "itemTags",
      message: "Tags"
    },
    {
      type: "number",
      name: "number",
      message: "How Many?"
    }
  ];

  // prompts returns a `Promise` that resolves with the users input
  return prompts(searchPrompts).then(
    //use ES2015 destructuring so we don't make any extra variables
    ({ searchText, itemTypes, itemTags, number }) => {
      const query = new SearchQueryBuilder()
        .match(session.username)
        .in("owner");

      // format the search query for item types
      const types = itemTypes.filter(type => type.length);

      // format the search query for item types
      if (types.length) {
        query.and().startGroup();
        types.forEach((type, index, types) => {
          query.match(type).in("type");
          if (index !== types.length - 1) {
            query.or();
          }
        });
        query.endGroup();
      }

      // format the search query for item tags
      const tags = itemTags.filter(tag => tag.length);

      if (tags.length) {
        query.and().startGroup();
        tags.forEach((tag, index, tags) => {
          query.match(tag).in("tags");
          if (index !== tags.length - 1) {
            query.or();
          }
        });
        query.endGroup();
      }

      // format the search query for the search text
      if (searchText.length) {
        query.and().match(searchText);
      }

      console.log(chalk.blue(`Searching ArcGIS Online: ${query.toParam()}`));

      return searchItems({
        authentication: session,
        q: query,
        num: number
      })
      .then(response => {
        return { response, session };
      })
      .catch(err => {
        console.warn(err);
      })
    }
  );
}