File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import meow from 'meow'
33import ora from 'ora'
44import prompts from 'prompts'
55
6+ import { ChalkOrMarkdown } from '../../utils/chalk-markdown.js'
67import { AuthError , InputError } from '../../utils/errors.js'
78import { setupSdk } from '../../utils/sdk.js'
89import { getSetting , updateSetting } from '../../utils/settings.js'
@@ -33,10 +34,14 @@ export const login = {
3334 if ( ! isInteractive ( ) ) {
3435 throw new InputError ( 'cannot prompt for credentials in a non-interactive shell' )
3536 }
37+ const format = new ChalkOrMarkdown ( false )
3638 const { apiKey } = await prompts ( {
3739 type : 'password' ,
3840 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+ ) } `,
4045 } )
4146
4247 if ( ! apiKey ) {
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ const oraPromise = import('ora')
1212const isInteractivePromise = import ( 'is-interactive' )
1313const chalkPromise = import ( 'chalk' )
1414const chalkMarkdownPromise = import ( '../utils/chalk-markdown.js' )
15+ const settingsPromise = import ( '../utils/settings.js' )
1516const ipc_version = require ( '../../package.json' ) . version
1617
1718try {
3233 * @typedef {import('stream').Writable } Writable
3334 */
3435
35- const pubToken = 'sktsec_t_--RAN5U4ivauy4w37-6aoKyYPDt5ZbaT5JBVMqiwKo_api'
36+ const pubTokenPromise = settingsPromise . then ( ( { getSetting } ) =>
37+ getSetting ( 'apiKey' ) || 'sktsec_t_--RAN5U4ivauy4w37-6aoKyYPDt5ZbaT5JBVMqiwKo_api'
38+ ) ;
3639
3740// shadow `npm` and `npx` to mitigate subshells
3841require ( './link.cjs' ) ( fs . realpathSync ( path . join ( __dirname , 'bin' ) ) , 'npm' )
@@ -64,6 +67,7 @@ const pkgidParts = (pkgid) => {
6467async function * batchScan (
6568 pkgids
6669) {
70+ const pubToken = await pubTokenPromise
6771 const query = {
6872 packages : pkgids . map ( pkgid => {
6973 const { name, version } = pkgidParts ( pkgid )
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ export async function setupSdk () {
2424 const input = await prompts ( {
2525 type : 'password' ,
2626 name : 'apiKey' ,
27- message : 'Enter your Socket.dev API key' ,
27+ message : 'Enter your Socket.dev API key (not saved) ' ,
2828 } )
2929
3030 apiKey = sessionAPIKey = input . apiKey
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import * as path from 'path'
44
55// @ts -ignore no types for ascii85
66import ascii85 from 'ascii85'
7+ import ora from 'ora'
78
89let dataHome = process . platform === 'win32'
910 ? process . env [ 'LOCALAPPDATA' ]
@@ -20,31 +21,33 @@ if (!dataHome) {
2021
2122const settingsPath = path . join ( dataHome , 'socket' , 'settings' )
2223
23- /** @type {any } */
24+ /** @type {{apiKey?: string | null} } */
2425let settings = { }
2526
2627if ( fs . existsSync ( settingsPath ) ) {
2728 const raw = fs . readFileSync ( settingsPath )
2829 try {
2930 settings = JSON . parse ( ascii85 . decode ( raw ) . toString ( ) )
3031 } catch ( e ) {
31- // failed decode - don't load
32+ ora ( `Failed to parse settings at ${ settingsPath } ` ) . warn ( )
3233 }
3334} else {
3435 fs . mkdirSync ( path . dirname ( settingsPath ) , { recursive : true } )
3536}
3637
3738/**
38- * @param {string } key
39- * @returns {any }
39+ * @template {keyof typeof settings} Key
40+ * @param {Key } key
41+ * @returns {typeof settings[Key] }
4042 */
4143export function getSetting ( key ) {
4244 return settings [ key ]
4345}
4446
4547/**
46- * @param {string } key
47- * @param {any } value
48+ * @template {keyof typeof settings} Key
49+ * @param {Key } key
50+ * @param {typeof settings[Key] } value
4851 * @returns {void }
4952 */
5053export function updateSetting ( key , value ) {
You can’t perform that action at this time.
0 commit comments