1
1
const { inspect } = require ( 'util' )
2
2
const { URL } = require ( 'url' )
3
3
const { log, output } = require ( 'proc-log' )
4
- const npmProfile = require ( 'npm-profile' )
4
+ const { get , set , createToken } = require ( 'npm-profile' )
5
5
const qrcodeTerminal = require ( 'qrcode-terminal' )
6
- const otplease = require ( '../utils/otplease .js' )
6
+ const { otplease } = require ( '../utils/auth .js' )
7
7
const readUserInfo = require ( '../utils/read-user-info.js' )
8
8
const BaseCommand = require ( '../base-cmd.js' )
9
9
@@ -101,7 +101,7 @@ class Profile extends BaseCommand {
101
101
102
102
async get ( args ) {
103
103
const tfa = 'two-factor auth'
104
- const info = await npmProfile . get ( { ...this . npm . flatOptions } )
104
+ const info = await get ( { ...this . npm . flatOptions } )
105
105
106
106
if ( ! info . cidr_whitelist ) {
107
107
delete info . cidr_whitelist
@@ -199,7 +199,7 @@ class Profile extends BaseCommand {
199
199
}
200
200
201
201
// 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 )
203
203
const newUser = { }
204
204
205
205
for ( const key of writableProfileKeys ) {
@@ -208,7 +208,7 @@ class Profile extends BaseCommand {
208
208
209
209
newUser [ prop ] = value
210
210
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 ) )
212
212
213
213
if ( this . npm . config . get ( 'json' ) ) {
214
214
output . standard ( JSON . stringify ( { [ prop ] : result [ prop ] } , null , 2 ) )
@@ -273,7 +273,7 @@ class Profile extends BaseCommand {
273
273
274
274
if ( auth . basic ) {
275
275
log . info ( 'profile' , 'Updating authentication to bearer token' )
276
- const result = await npmProfile . createToken (
276
+ const result = await createToken (
277
277
auth . basic . password , false , [ ] , { ...this . npm . flatOptions }
278
278
)
279
279
@@ -297,12 +297,12 @@ class Profile extends BaseCommand {
297
297
info . tfa . password = password
298
298
299
299
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 } )
301
301
302
302
const conf = { ...this . npm . flatOptions }
303
303
if ( userInfo && userInfo . tfa && userInfo . tfa . pending ) {
304
304
log . info ( 'profile' , 'Resetting two-factor authentication' )
305
- await npmProfile . set ( { tfa : { password, mode : 'disable' } } , conf )
305
+ await set ( { tfa : { password, mode : 'disable' } } , conf )
306
306
} else if ( userInfo && userInfo . tfa ) {
307
307
if ( ! conf . otp ) {
308
308
conf . otp = await readUserInfo . otp (
@@ -312,7 +312,7 @@ class Profile extends BaseCommand {
312
312
}
313
313
314
314
log . info ( 'profile' , 'Setting two-factor authentication to ' + mode )
315
- const challenge = await npmProfile . set ( info , conf )
315
+ const challenge = await set ( info , conf )
316
316
317
317
if ( challenge . tfa === null ) {
318
318
output . standard ( 'Two factor authentication mode changed to: ' + mode )
@@ -341,7 +341,7 @@ class Profile extends BaseCommand {
341
341
342
342
log . info ( 'profile' , 'Finalizing two-factor authentication' )
343
343
344
- const result = await npmProfile . set ( { tfa : [ interactiveOTP ] } , conf )
344
+ const result = await set ( { tfa : [ interactiveOTP ] } , conf )
345
345
346
346
output . standard (
347
347
'2FA successfully enabled. Below are your recovery codes, ' +
@@ -359,7 +359,7 @@ class Profile extends BaseCommand {
359
359
360
360
async disable2fa ( ) {
361
361
const conf = { ...this . npm . flatOptions }
362
- const info = await npmProfile . get ( conf )
362
+ const info = await get ( conf )
363
363
364
364
if ( ! info . tfa || info . tfa . pending ) {
365
365
output . standard ( 'Two factor authentication not enabled.' )
@@ -375,7 +375,7 @@ class Profile extends BaseCommand {
375
375
376
376
log . info ( 'profile' , 'disabling tfa' )
377
377
378
- await npmProfile . set ( { tfa : { password : password , mode : 'disable' } } , conf )
378
+ await set ( { tfa : { password : password , mode : 'disable' } } , conf )
379
379
380
380
if ( this . npm . config . get ( 'json' ) ) {
381
381
output . standard ( JSON . stringify ( { tfa : false } , null , 2 ) )
0 commit comments