File tree Expand file tree Collapse file tree 4 files changed +21
-9
lines changed Expand file tree Collapse file tree 4 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import meow from 'meow'
3
3
import ora from 'ora'
4
4
import prompts from 'prompts'
5
5
6
+ import { ChalkOrMarkdown } from '../../utils/chalk-markdown.js'
6
7
import { AuthError , InputError } from '../../utils/errors.js'
7
8
import { setupSdk } from '../../utils/sdk.js'
8
9
import { getSetting , updateSetting } from '../../utils/settings.js'
@@ -33,10 +34,14 @@ export const login = {
33
34
if ( ! isInteractive ( ) ) {
34
35
throw new InputError ( 'cannot prompt for credentials in a non-interactive shell' )
35
36
}
37
+ const format = new ChalkOrMarkdown ( false )
36
38
const { apiKey } = await prompts ( {
37
39
type : 'password' ,
38
40
name : 'apiKey' ,
39
- message : 'Enter your Socket.dev API key' ,
41
+ message : `Enter your ${ format . hyperlink (
42
+ 'Socket.dev API key' ,
43
+ 'https://docs.socket.dev/docs/api-keys'
44
+ ) } `,
40
45
} )
41
46
42
47
if ( ! apiKey ) {
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ const oraPromise = import('ora')
12
12
const isInteractivePromise = import ( 'is-interactive' )
13
13
const chalkPromise = import ( 'chalk' )
14
14
const chalkMarkdownPromise = import ( '../utils/chalk-markdown.js' )
15
+ const settingsPromise = import ( '../utils/settings.js' )
15
16
const ipc_version = require ( '../../package.json' ) . version
16
17
17
18
try {
32
33
* @typedef {import('stream').Writable } Writable
33
34
*/
34
35
35
- const pubToken = 'sktsec_t_--RAN5U4ivauy4w37-6aoKyYPDt5ZbaT5JBVMqiwKo_api'
36
+ const pubTokenPromise = settingsPromise . then ( ( { getSetting } ) =>
37
+ getSetting ( 'apiKey' ) || 'sktsec_t_--RAN5U4ivauy4w37-6aoKyYPDt5ZbaT5JBVMqiwKo_api'
38
+ ) ;
36
39
37
40
// shadow `npm` and `npx` to mitigate subshells
38
41
require ( './link.cjs' ) ( fs . realpathSync ( path . join ( __dirname , 'bin' ) ) , 'npm' )
@@ -64,6 +67,7 @@ const pkgidParts = (pkgid) => {
64
67
async function * batchScan (
65
68
pkgids
66
69
) {
70
+ const pubToken = await pubTokenPromise
67
71
const query = {
68
72
packages : pkgids . map ( pkgid => {
69
73
const { name, version } = pkgidParts ( pkgid )
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ export async function setupSdk () {
24
24
const input = await prompts ( {
25
25
type : 'password' ,
26
26
name : 'apiKey' ,
27
- message : 'Enter your Socket.dev API key' ,
27
+ message : 'Enter your Socket.dev API key (not saved) ' ,
28
28
} )
29
29
30
30
apiKey = sessionAPIKey = input . apiKey
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import * as path from 'path'
4
4
5
5
// @ts -ignore no types for ascii85
6
6
import ascii85 from 'ascii85'
7
+ import ora from 'ora'
7
8
8
9
let dataHome = process . platform === 'win32'
9
10
? process . env [ 'LOCALAPPDATA' ]
@@ -20,31 +21,33 @@ if (!dataHome) {
20
21
21
22
const settingsPath = path . join ( dataHome , 'socket' , 'settings' )
22
23
23
- /** @type {any } */
24
+ /** @type {{apiKey?: string | null} } */
24
25
let settings = { }
25
26
26
27
if ( fs . existsSync ( settingsPath ) ) {
27
28
const raw = fs . readFileSync ( settingsPath )
28
29
try {
29
30
settings = JSON . parse ( ascii85 . decode ( raw ) . toString ( ) )
30
31
} catch ( e ) {
31
- // failed decode - don't load
32
+ ora ( `Failed to parse settings at ${ settingsPath } ` ) . warn ( )
32
33
}
33
34
} else {
34
35
fs . mkdirSync ( path . dirname ( settingsPath ) , { recursive : true } )
35
36
}
36
37
37
38
/**
38
- * @param {string } key
39
- * @returns {any }
39
+ * @template {keyof typeof settings} Key
40
+ * @param {Key } key
41
+ * @returns {typeof settings[Key] }
40
42
*/
41
43
export function getSetting ( key ) {
42
44
return settings [ key ]
43
45
}
44
46
45
47
/**
46
- * @param {string } key
47
- * @param {any } value
48
+ * @template {keyof typeof settings} Key
49
+ * @param {Key } key
50
+ * @param {typeof settings[Key] } value
48
51
* @returns {void }
49
52
*/
50
53
export function updateSetting ( key , value ) {
You can’t perform that action at this time.
0 commit comments