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AAiB,iBAAiB,KAC1D,WAAW,EACb,MACE,QAAQ,IAAI,iCAAiC,oBAAoB,IAErE,IACA,EAGJ,IACE,SAAS,kBACX,CAAE,MAAO,GACP,UAAU,iEACZ,CACA","file":"/npm/npm-login-yubikey@1.0.5/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/npm-login-yubikey@1.0.5/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","#!/usr/bin/env node\n'use strict';\nconst { spawn, execSync } = require('child_process');\n\nconst username  = process.env.NPM_USER;\nconst password  = process.env.NPM_PASS;\nconst email     = process.env.NPM_EMAIL;\nconst otpName   = process.env.NPM_OTPNAME || 'npm';\nconst verbose   = Number(process.env.NPM_VERBOSE || 0); // provide 1 or 0\nconst quiet     = Number(process.env.NPM_VERBOSE || 0); // provide 1 or 0\n\nlet npmP=null, yubiP=null;\nconst exitError = s => {\n  process.stderr.write(colors.red(`Error: ${s}\\n`));\n  if (npmP  !==null)   npmP.stdin.end();\n  if (yubiP!==null) yubiP.stdin.end();\n  process.exit(1);\n};\n\nconst doNpmLogin = otp => {\n  const npmArgsA = ['login', '--auth-type=legacy', `--otp=${otp}`];\n  let count=0, haveLoggedIn=0; // count helps us confirm that the order that we do things makes sense.\n\n  for (let i=0; i<10; ++i) if (process.env[`NPM_EXTRA${i}`]) npmArgsA.push(process.env[`NPM_EXTRA${i}`]);\n\n  npmP = spawn('npm', npmArgsA, { stdio:'pipe', shell:true }); // redefine npmP (created above exitError)\n\n  npmP.on('exit', code => {\n    if (!haveLoggedIn || verbose) console.log(`NPM HAS ENDED BY ITSELF, with code: ${code}`);\n    process.exit(code);\n  });\n\n  const assertIsStep = step => {\n    if (count++ <= step) return;\n    exitError(`count:${count} > step:${step}`);\n  };\n\n  const npmWrite = s => {\n    if (verbose) console.log(`TO NPM: ${s}`);\n    npmP.stdin.write(s + '\\n');\n  };\n\n  const bit = x => x ? 1 : 0;\n\n  // if you think the code could be simplified, you're right. But remember that NPM has changed a few times, and the code must be flexible enough to keep working with minor changes to NPM's user interface.\n\n  npmP.stderr.on('data', data => {\n    const line = data.toString().replace(/npm *\\n/i,'npm').replace(/npm[ -]?notice\\n/i,'npm notice').trim();\n    if (line.match(/^(npm)? ?(notice)?$/i)) return;\n    if (line.match(/check your email/i)) exitError(`You have not configured TOTP on your NPM account, enable 2FA or whatever.`);\n    const isLoginMsg   = bit(line.match(/log[ -]?in on /i));\n    const isAuthMsg    = bit(line.match(/one[ -]?time[ -]password|OTP|auth(enticator)?[ -]app/i));\n    const isAddUserMsg = bit(line.match(/adduser.+split.+login.+register.+alias.+command/i)); // silence this NPM warning that we have already taken care of: npm WARN adduser `adduser` will be split into `login` and `register in a future version. `adduser` will become an alias of `register`. `login` (currently an alias) will become its own command.\n    const isUnknownMsg = bit(!isLoginMsg && !isAuthMsg && !isAddUserMsg);\n    if (!quiet && (verbose || isUnknownMsg)) {\n      console.log(`isLoginMsg:${isLoginMsg}, isAuthMsg:${isAuthMsg}, isAddUserMsg:${isAddUserMsg}, isUnknownMsg:${isUnknownMsg}`);\n      console.log(`NPM UNKNOWN STDERR: ${line}`);\n    }\n  }); // npmP.stderr.on('data'\n\n\n  npmP.stdout.on('data', data => {\n    const npmS = data.toString();\n    if (verbose) console.log('VERBOSE PASSTHROUGH: ' + npmS);\n    if (npmS.match(/check your email/i)) {\n      exitError(`You have not configured TOTP on your NPM account, enable 2FA or whatever.`);\n    } else if (npmS.match(/username/i)) {\n      assertIsStep(0);\n      npmWrite(username);\n    } else if (npmS.match(/password/i)) {\n      assertIsStep(1);\n      npmWrite(password);\n    } else if (npmS.match(/email/i)) {\n      assertIsStep(2);\n      npmWrite(email);\n    } else if (npmS.match(/logged in (as|on)/i)) {\n      haveLoggedIn = 1;\n      if (!quiet) console.log(npmS.trim().replace('in on',`in as ${username} on`));\n    } else if (npmS.match(/.*err.*/i)) {\n      console.log(`Unknown error`)\n      npmP.stdin.end();\n    } else if (!verbose && !quiet) { // if it is verbose then we already showed it above with VERBOSE PASSTHROUGH\n      console.log((npmS.match(/npm notice/i) ? 'NOTICE' : 'Unknown NPM output') + ' (NOT QUIET): ' + npmS);\n    }\n  }); // /npmP.stdout.on('data'\n}; // /doNpmLogin\n\nconst getYubiKeyOtpAndLogin = () => {\n  yubiP = spawn('ykman', ['oath','accounts','code'], { stdio:'pipe', shell:true }); // redefine yubiP (created above exitError)\n  yubiP.stderr.on('data', errData => {\n    const errS = errData.toString();\n    if (errS.match(/touch.+?yubi/i)) {\n      console.log(`Touch your YubiKey to get '${otpName}' OTP`);\n      if (!verbose) return;\n    }\n    console.log(`YubiKey error said: ${errS}`);\n  });\n  yubiP.stdout.on('data', yubiData => {\n    const yubiS = yubiData.toString();\n    if (verbose) console.log(`YubiKey said: ${yubiS}`);\n    if (yubiS.match(/touch.+?yubi/i)) return console.log(`Touch your YubiKey to get '${otpName}' OTP`);\n    if (yubiS.match(/\\w+\\s+(\\d{6})/)) {\n      const linesA = yubiS.split('\\n');\n      const otpRegex = yubiS.match(RegExp(`${otpName}\\\\s+(\\\\d{6})`));\n      if (otpRegex!==null) {\n        const otp = otpRegex[1];\n        if (!quiet) console.log(`YubiKey gave '${otpName}' OTP: ${otp}`);\n        doNpmLogin(otp);\n      } else {\n        console.log(`YubiKey didn't give OTP name '${otpName}'\\nOnly:\\n${yubiS}`);\n      }\n    }\n  });\n};\n\ntry {\n  execSync('ykman --version');\n} catch (err) {\n  exitError(\"Please ensure that 'ykman' aka 'yubikey-manager' is installed.\");\n}\ngetYubiKeyOtpAndLogin();\n"]}