• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2
3const BB = require('bluebird')
4
5const optCheck = require('figgy-pudding')({
6  prompt: {default: 'This operation requires a one-time password.\nEnter OTP:'},
7  otp: {}
8})
9const readUserInfo = require('./read-user-info.js')
10
11module.exports = otplease
12function otplease (opts, fn) {
13  opts = opts.concat ? opts : optCheck(opts)
14  return BB.try(() => {
15    return fn(opts)
16  }).catch(err => {
17    if (err.code !== 'EOTP' && !(err.code === 'E401' && /one-time pass/.test(err.body))) {
18      throw err
19    } else if (!process.stdin.isTTY || !process.stdout.isTTY) {
20      throw err
21    } else {
22      return readUserInfo.otp(
23        optCheck(opts).prompt
24      ).then(otp => fn(opts.concat({otp})))
25    }
26  })
27}
28