11const { inspect } = require ( 'util' )
22const { URL } = require ( 'url' )
33const { log, output } = require ( 'proc-log' )
4- const npmProfile = require ( 'npm-profile' )
4+ const { get , set , createToken } = require ( 'npm-profile' )
55const qrcodeTerminal = require ( 'qrcode-terminal' )
6- const otplease = require ( '../utils/otplease .js' )
6+ const { otplease } = require ( '../utils/auth .js' )
77const readUserInfo = require ( '../utils/read-user-info.js' )
88const BaseCommand = require ( '../base-cmd.js' )
99
@@ -101,7 +101,7 @@ class Profile extends BaseCommand {
101101
102102 async get ( args ) {
103103 const tfa = 'two-factor auth'
104- const info = await npmProfile . get ( { ...this . npm . flatOptions } )
104+ const info = await get ( { ...this . npm . flatOptions } )
105105
106106 if ( ! info . cidr_whitelist ) {
107107 delete info . cidr_whitelist
@@ -199,7 +199,7 @@ class Profile extends BaseCommand {
199199 }
200200
201201 // FIXME: Work around to not clear everything other than what we're setting
202- const user = await npmProfile . get ( conf )
202+ const user = await get ( conf )
203203 const newUser = { }
204204
205205 for ( const key of writableProfileKeys ) {
@@ -208,7 +208,7 @@ class Profile extends BaseCommand {
208208
209209 newUser [ prop ] = value
210210
211- const result = await otplease ( this . npm , conf , c => npmProfile . set ( newUser , c ) )
211+ const result = await otplease ( this . npm , conf , c => set ( newUser , c ) )
212212
213213 if ( this . npm . config . get ( 'json' ) ) {
214214 output . standard ( JSON . stringify ( { [ prop ] : result [ prop ] } , null , 2 ) )
@@ -273,7 +273,7 @@ class Profile extends BaseCommand {
273273
274274 if ( auth . basic ) {
275275 log . info ( 'profile' , 'Updating authentication to bearer token' )
276- const result = await npmProfile . createToken (
276+ const result = await createToken (
277277 auth . basic . password , false , [ ] , { ...this . npm . flatOptions }
278278 )
279279
@@ -297,12 +297,12 @@ class Profile extends BaseCommand {
297297 info . tfa . password = password
298298
299299 log . info ( 'profile' , 'Determine if tfa is pending' )
300- const userInfo = await npmProfile . get ( { ...this . npm . flatOptions } )
300+ const userInfo = await get ( { ...this . npm . flatOptions } )
301301
302302 const conf = { ...this . npm . flatOptions }
303303 if ( userInfo && userInfo . tfa && userInfo . tfa . pending ) {
304304 log . info ( 'profile' , 'Resetting two-factor authentication' )
305- await npmProfile . set ( { tfa : { password, mode : 'disable' } } , conf )
305+ await set ( { tfa : { password, mode : 'disable' } } , conf )
306306 } else if ( userInfo && userInfo . tfa ) {
307307 if ( ! conf . otp ) {
308308 conf . otp = await readUserInfo . otp (
@@ -312,7 +312,7 @@ class Profile extends BaseCommand {
312312 }
313313
314314 log . info ( 'profile' , 'Setting two-factor authentication to ' + mode )
315- const challenge = await npmProfile . set ( info , conf )
315+ const challenge = await set ( info , conf )
316316
317317 if ( challenge . tfa === null ) {
318318 output . standard ( 'Two factor authentication mode changed to: ' + mode )
@@ -341,7 +341,7 @@ class Profile extends BaseCommand {
341341
342342 log . info ( 'profile' , 'Finalizing two-factor authentication' )
343343
344- const result = await npmProfile . set ( { tfa : [ interactiveOTP ] } , conf )
344+ const result = await set ( { tfa : [ interactiveOTP ] } , conf )
345345
346346 output . standard (
347347 '2FA successfully enabled. Below are your recovery codes, ' +
@@ -359,7 +359,7 @@ class Profile extends BaseCommand {
359359
360360 async disable2fa ( ) {
361361 const conf = { ...this . npm . flatOptions }
362- const info = await npmProfile . get ( conf )
362+ const info = await get ( conf )
363363
364364 if ( ! info . tfa || info . tfa . pending ) {
365365 output . standard ( 'Two factor authentication not enabled.' )
@@ -375,7 +375,7 @@ class Profile extends BaseCommand {
375375
376376 log . info ( 'profile' , 'disabling tfa' )
377377
378- await npmProfile . set ( { tfa : { password : password , mode : 'disable' } } , conf )
378+ await set ( { tfa : { password : password , mode : 'disable' } } , conf )
379379
380380 if ( this . npm . config . get ( 'json' ) ) {
381381 output . standard ( JSON . stringify ( { tfa : false } , null , 2 ) )
0 commit comments