@socketsecurity/cli-with-sentry 0.14.155 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.config/tsconfig.dts.tsbuildinfo +1 -1
- package/dist/cli.js +279 -325
- package/dist/cli.js.map +1 -1
- package/dist/constants.js +11 -9
- package/dist/constants.js.map +1 -1
- package/dist/types/commands/analytics/fetch-org-analytics.d.mts.map +1 -1
- package/dist/types/commands/analytics/fetch-repo-analytics.d.mts.map +1 -1
- package/dist/types/commands/audit-log/fetch-audit-log.d.mts.map +1 -1
- package/dist/types/commands/ci/fetch-default-org-slug.d.mts.map +1 -1
- package/dist/types/commands/dependencies/fetch-dependencies.d.mts.map +1 -1
- package/dist/types/commands/diff-scan/fetch-diff-scan.d.mts.map +1 -1
- package/dist/types/commands/info/fetch-package-info.d.mts.map +1 -1
- package/dist/types/commands/login/attempt-login.d.mts.map +1 -1
- package/dist/types/commands/oops/cmd-oops.d.mts.map +1 -1
- package/dist/types/commands/organization/fetch-license-policy.d.mts.map +1 -1
- package/dist/types/commands/organization/fetch-organization-list.d.mts.map +1 -1
- package/dist/types/commands/organization/fetch-quota.d.mts.map +1 -1
- package/dist/types/commands/organization/fetch-security-policy.d.mts.map +1 -1
- package/dist/types/commands/organization/output-organization-list.d.mts.map +1 -1
- package/dist/types/commands/package/cmd-package-score.d.mts.map +1 -1
- package/dist/types/commands/package/fetch-purl-deep-score.d.mts.map +1 -1
- package/dist/types/commands/package/fetch-purls-shallow-score.d.mts.map +1 -1
- package/dist/types/commands/repos/fetch-create-repo.d.mts.map +1 -1
- package/dist/types/commands/repos/fetch-delete-repo.d.mts.map +1 -1
- package/dist/types/commands/repos/fetch-list-repos.d.mts.map +1 -1
- package/dist/types/commands/repos/fetch-update-repo.d.mts.map +1 -1
- package/dist/types/commands/repos/fetch-view-repo.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-create-org-full-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-delete-org-full-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-diff-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-list-scans.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-report-data.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-scan-metadata.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-supported-scan-file-names.d.mts.map +1 -1
- package/dist/types/commands/scan/generate-report.d.mts.map +1 -1
- package/dist/types/commands/scan/stream-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/suggest-org-slug.d.mts.map +1 -1
- package/dist/types/commands/scan/suggest-repo-slug.d.mts.map +1 -1
- package/dist/types/commands/threat-feed/fetch-threat-feed.d.mts.map +1 -1
- package/dist/types/constants.d.mts.map +1 -1
- package/dist/types/utils/alerts-map.d.mts.map +1 -1
- package/dist/types/utils/api.d.mts +11 -11
- package/dist/types/utils/api.d.mts.map +1 -1
- package/dist/types/utils/meow-with-subcommands.d.mts.map +1 -1
- package/dist/types/utils/sdk.d.mts +4 -1
- package/dist/types/utils/sdk.d.mts.map +1 -1
- package/dist/types/utils/socket-url.d.mts +10 -2
- package/dist/types/utils/socket-url.d.mts.map +1 -1
- package/dist/utils.js +331 -177
- package/dist/utils.js.map +1 -1
- package/external/@socketsecurity/registry/lib/constants/maintained-node-versions.js +5 -10
- package/external/@socketsecurity/registry/package.json +3 -3
- package/package.json +6 -6
package/dist/utils.js
CHANGED
|
@@ -10,11 +10,11 @@ const regexps = require('../external/@socketsecurity/registry/lib/regexps')
|
|
|
10
10
|
const constants = require('./constants.js')
|
|
11
11
|
const prompts = require('../external/@socketsecurity/registry/lib/prompts')
|
|
12
12
|
const strings = require('../external/@socketsecurity/registry/lib/strings')
|
|
13
|
+
const promises = require('node:timers/promises')
|
|
13
14
|
const arrays = require('../external/@socketsecurity/registry/lib/arrays')
|
|
14
15
|
const packages = require('../external/@socketsecurity/registry/lib/packages')
|
|
15
16
|
const fs = require('node:fs')
|
|
16
17
|
const os = require('node:os')
|
|
17
|
-
const promises = require('node:timers/promises')
|
|
18
18
|
const registry = require('../external/@socketsecurity/registry')
|
|
19
19
|
const sorts = require('../external/@socketsecurity/registry/lib/sorts')
|
|
20
20
|
const Module = require('node:module')
|
|
@@ -608,6 +608,99 @@ function failMsgWithBadge(badge, msg) {
|
|
|
608
608
|
return `${vendor.yoctocolorsCjsExports.bgRed(vendor.yoctocolorsCjsExports.bold(vendor.yoctocolorsCjsExports.white(` ${badge}${msg ? ': ' : ''}`)))}${msg ? ' ' + vendor.yoctocolorsCjsExports.bold(msg) : ''}`
|
|
609
609
|
}
|
|
610
610
|
|
|
611
|
+
const { SOCKET_PUBLIC_API_TOKEN } = constants
|
|
612
|
+
|
|
613
|
+
// The API server that should be used for operations.
|
|
614
|
+
function getDefaultApiBaseUrl$1() {
|
|
615
|
+
const baseUrl =
|
|
616
|
+
// Lazily access constants.ENV.SOCKET_SECURITY_API_BASE_URL.
|
|
617
|
+
constants.ENV.SOCKET_SECURITY_API_BASE_URL ||
|
|
618
|
+
getConfigValueOrUndef('apiBaseUrl')
|
|
619
|
+
return strings.isNonEmptyString(baseUrl) ? baseUrl : undefined
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// The API server that should be used for operations.
|
|
623
|
+
function getDefaultHttpProxy() {
|
|
624
|
+
const apiProxy =
|
|
625
|
+
// Lazily access constants.ENV.SOCKET_SECURITY_API_PROXY.
|
|
626
|
+
constants.ENV.SOCKET_SECURITY_API_PROXY || getConfigValueOrUndef('apiProxy')
|
|
627
|
+
return strings.isNonEmptyString(apiProxy) ? apiProxy : undefined
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// This API key should be stored globally for the duration of the CLI execution.
|
|
631
|
+
let _defaultToken
|
|
632
|
+
function getDefaultToken() {
|
|
633
|
+
// Lazily access constants.ENV.SOCKET_CLI_NO_API_TOKEN.
|
|
634
|
+
if (constants.ENV.SOCKET_CLI_NO_API_TOKEN) {
|
|
635
|
+
_defaultToken = undefined
|
|
636
|
+
} else {
|
|
637
|
+
const key =
|
|
638
|
+
// Lazily access constants.ENV.SOCKET_SECURITY_API_TOKEN.
|
|
639
|
+
constants.ENV.SOCKET_SECURITY_API_TOKEN ||
|
|
640
|
+
getConfigValueOrUndef('apiToken') ||
|
|
641
|
+
_defaultToken
|
|
642
|
+
_defaultToken = strings.isNonEmptyString(key) ? key : undefined
|
|
643
|
+
}
|
|
644
|
+
return _defaultToken
|
|
645
|
+
}
|
|
646
|
+
function getVisibleTokenPrefix() {
|
|
647
|
+
const apiToken = getDefaultToken()
|
|
648
|
+
if (!apiToken) {
|
|
649
|
+
return ''
|
|
650
|
+
}
|
|
651
|
+
const PREFIX = 'sktsec_'
|
|
652
|
+
return apiToken.slice(PREFIX.length, PREFIX.length + 5)
|
|
653
|
+
}
|
|
654
|
+
function hasDefaultToken() {
|
|
655
|
+
return !!getDefaultToken()
|
|
656
|
+
}
|
|
657
|
+
function getPublicToken() {
|
|
658
|
+
return (
|
|
659
|
+
// Lazily access constants.ENV.SOCKET_SECURITY_API_TOKEN.
|
|
660
|
+
(constants.ENV.SOCKET_SECURITY_API_TOKEN || getDefaultToken()) ??
|
|
661
|
+
SOCKET_PUBLIC_API_TOKEN
|
|
662
|
+
)
|
|
663
|
+
}
|
|
664
|
+
async function setupSdk(
|
|
665
|
+
apiToken = getDefaultToken(),
|
|
666
|
+
apiBaseUrl = getDefaultApiBaseUrl$1(),
|
|
667
|
+
proxy = getDefaultHttpProxy()
|
|
668
|
+
) {
|
|
669
|
+
if (typeof apiToken !== 'string' && vendor.isInteractiveExports()) {
|
|
670
|
+
apiToken = await prompts.password({
|
|
671
|
+
message:
|
|
672
|
+
'Enter your Socket.dev API key (not saved, use socket login to persist)'
|
|
673
|
+
})
|
|
674
|
+
_defaultToken = apiToken
|
|
675
|
+
}
|
|
676
|
+
if (!apiToken) {
|
|
677
|
+
return {
|
|
678
|
+
ok: false,
|
|
679
|
+
message: 'Auth Error',
|
|
680
|
+
cause: 'You need to provide an API Token. Run `socket login` first.'
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
return {
|
|
684
|
+
ok: true,
|
|
685
|
+
data: new vendor.distExports$2.SocketSdk(apiToken, {
|
|
686
|
+
agent: proxy
|
|
687
|
+
? new vendor.HttpsProxyAgent({
|
|
688
|
+
proxy
|
|
689
|
+
})
|
|
690
|
+
: undefined,
|
|
691
|
+
baseUrl: apiBaseUrl,
|
|
692
|
+
userAgent: vendor.distExports$2.createUserAgentFromPkgJson({
|
|
693
|
+
// Lazily access constants.ENV.INLINED_SOCKET_CLI_NAME.
|
|
694
|
+
name: constants.ENV.INLINED_SOCKET_CLI_NAME,
|
|
695
|
+
// Lazily access constants.ENV.INLINED_SOCKET_CLI_VERSION.
|
|
696
|
+
version: constants.ENV.INLINED_SOCKET_CLI_VERSION,
|
|
697
|
+
// Lazily access constants.ENV.INLINED_SOCKET_CLI_HOMEPAGE.
|
|
698
|
+
homepage: constants.ENV.INLINED_SOCKET_CLI_HOMEPAGE
|
|
699
|
+
})
|
|
700
|
+
})
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
611
704
|
// TODO: this function is removed after v1.0.0
|
|
612
705
|
function handleUnsuccessfulApiResponse(_name, error, cause, status) {
|
|
613
706
|
const message = `${error || 'No error message returned'}${cause ? ` (reason: ${cause})` : ''}`
|
|
@@ -621,15 +714,6 @@ function handleUnsuccessfulApiResponse(_name, error, cause, status) {
|
|
|
621
714
|
// eslint-disable-next-line n/no-process-exit
|
|
622
715
|
process.exit(1)
|
|
623
716
|
}
|
|
624
|
-
function handleFailedApiResponse(_name, { cause, error }) {
|
|
625
|
-
const message = `${error || 'No error message returned'}`
|
|
626
|
-
// logger.error(failMsgWithBadge('Socket API returned an error', message))
|
|
627
|
-
return {
|
|
628
|
-
ok: false,
|
|
629
|
-
message: 'Socket API returned an error',
|
|
630
|
-
cause: `${message}${cause ? ` ( Reason: ${cause} )` : ''}`
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
717
|
async function handleApiCall(value, fetchingDesc) {
|
|
634
718
|
// Lazily access constants.spinner.
|
|
635
719
|
const { spinner } = constants
|
|
@@ -677,17 +761,6 @@ async function handleApiCall(value, fetchingDesc) {
|
|
|
677
761
|
}
|
|
678
762
|
}
|
|
679
763
|
}
|
|
680
|
-
async function tmpHandleApiCall(value, description) {
|
|
681
|
-
try {
|
|
682
|
-
return await value
|
|
683
|
-
} catch (e) {
|
|
684
|
-
debug.debugLog(`handleApiCall[${description}] error:\n`, e)
|
|
685
|
-
// TODO: eliminate this throw in favor of CResult (or anything else)
|
|
686
|
-
throw new Error(`Failed ${description}`, {
|
|
687
|
-
cause: e
|
|
688
|
-
})
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
764
|
async function handleApiCallNoSpinner(value, description) {
|
|
692
765
|
let result
|
|
693
766
|
try {
|
|
@@ -724,25 +797,24 @@ async function handleApiCallNoSpinner(value, description) {
|
|
|
724
797
|
}
|
|
725
798
|
}
|
|
726
799
|
}
|
|
727
|
-
async function
|
|
800
|
+
async function getErrorMessageForHttpStatusCode(code) {
|
|
728
801
|
if (code === 400) {
|
|
729
802
|
return 'One of the options passed might be incorrect'
|
|
730
803
|
}
|
|
731
|
-
if (code === 403) {
|
|
804
|
+
if (code === 403 || code === 401) {
|
|
732
805
|
return 'Your API token may not have the required permissions for this command or you might be trying to access (data from) an organization that is not linked to the API key you are logged in with'
|
|
733
806
|
}
|
|
734
807
|
if (code === 404) {
|
|
735
|
-
return 'The requested Socket API endpoint was not found (404) or there was no result for the requested parameters.
|
|
808
|
+
return 'The requested Socket API endpoint was not found (404) or there was no result for the requested parameters. If unexpected, this could be a temporary problem caused by an incident or a bug in the CLI. If the problem persists please let us know.'
|
|
809
|
+
}
|
|
810
|
+
if (code === 500) {
|
|
811
|
+
return 'There was an unknown server side problem with your request. This ought to be temporary. Please let us know if this problem persists.'
|
|
736
812
|
}
|
|
737
813
|
return `Server responded with status code ${code}`
|
|
738
814
|
}
|
|
739
|
-
function getLastFiveOfApiToken(token) {
|
|
740
|
-
// Get the last 5 characters of the API token before the trailing "_api".
|
|
741
|
-
return token.slice(-9, -4)
|
|
742
|
-
}
|
|
743
815
|
|
|
744
816
|
// The API server that should be used for operations.
|
|
745
|
-
function getDefaultApiBaseUrl
|
|
817
|
+
function getDefaultApiBaseUrl() {
|
|
746
818
|
// Lazily access constants.ENV.SOCKET_SECURITY_API_BASE_URL.
|
|
747
819
|
const SOCKET_SECURITY_API_BASE_URL =
|
|
748
820
|
constants.ENV.SOCKET_SECURITY_API_BASE_URL
|
|
@@ -756,7 +828,7 @@ function getDefaultApiBaseUrl$1() {
|
|
|
756
828
|
return API_V0_URL
|
|
757
829
|
}
|
|
758
830
|
async function queryApi(path, apiToken) {
|
|
759
|
-
const baseUrl = getDefaultApiBaseUrl
|
|
831
|
+
const baseUrl = getDefaultApiBaseUrl() || ''
|
|
760
832
|
if (!baseUrl) {
|
|
761
833
|
logger.logger.warn(
|
|
762
834
|
'API endpoint is not set and default was empty. Request is likely to fail.'
|
|
@@ -769,81 +841,93 @@ async function queryApi(path, apiToken) {
|
|
|
769
841
|
}
|
|
770
842
|
})
|
|
771
843
|
}
|
|
772
|
-
|
|
773
|
-
const
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
844
|
+
async function queryApiSafeText(path, fetchSpinnerDesc) {
|
|
845
|
+
const apiToken = getDefaultToken()
|
|
846
|
+
if (!apiToken) {
|
|
847
|
+
return {
|
|
848
|
+
ok: false,
|
|
849
|
+
message: 'Authentication Error',
|
|
850
|
+
cause:
|
|
851
|
+
'User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.'
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
if (fetchSpinnerDesc) {
|
|
855
|
+
// Lazily access constants.spinner.
|
|
856
|
+
const { spinner } = constants
|
|
857
|
+
spinner.start(`Requesting ${fetchSpinnerDesc} from API...`)
|
|
858
|
+
}
|
|
859
|
+
let result
|
|
860
|
+
try {
|
|
861
|
+
result = await queryApi(path, apiToken)
|
|
862
|
+
if (fetchSpinnerDesc) {
|
|
863
|
+
// Lazily access constants.spinner.
|
|
864
|
+
const { spinner } = constants
|
|
865
|
+
spinner.successAndStop(
|
|
866
|
+
`Received API response (after requesting ${fetchSpinnerDesc}).`
|
|
867
|
+
)
|
|
868
|
+
}
|
|
869
|
+
} catch (e) {
|
|
870
|
+
if (fetchSpinnerDesc) {
|
|
871
|
+
// Lazily access constants.spinner.
|
|
872
|
+
const { spinner } = constants
|
|
873
|
+
spinner.failAndStop(
|
|
874
|
+
`An error was thrown while requesting ${fetchSpinnerDesc}`
|
|
875
|
+
)
|
|
876
|
+
}
|
|
877
|
+
debug.debugLog('Error thrown trying to await queryApi():')
|
|
878
|
+
debug.debugLog(e)
|
|
879
|
+
const msg = e?.message
|
|
880
|
+
return {
|
|
881
|
+
ok: false,
|
|
882
|
+
message: 'API Request failed to complete',
|
|
883
|
+
...(msg
|
|
884
|
+
? {
|
|
885
|
+
cause: msg
|
|
886
|
+
}
|
|
887
|
+
: {})
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
if (!result.ok) {
|
|
891
|
+
const cause = await getErrorMessageForHttpStatusCode(result.status)
|
|
892
|
+
return {
|
|
893
|
+
ok: false,
|
|
894
|
+
message: 'Socket API returned an error',
|
|
895
|
+
cause: `${result.statusText}${cause ? ` (cause: ${cause})` : ''}`
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
try {
|
|
899
|
+
const data = await result.text()
|
|
900
|
+
return {
|
|
901
|
+
ok: true,
|
|
902
|
+
data
|
|
903
|
+
}
|
|
904
|
+
} catch (e) {
|
|
905
|
+
debug.debugLog('Error thrown trying to await result.text():')
|
|
906
|
+
debug.debugLog(e)
|
|
907
|
+
return {
|
|
908
|
+
ok: false,
|
|
909
|
+
message: 'API Request failed to complete',
|
|
910
|
+
cause: 'There was an unexpected error trying to read the response text'
|
|
911
|
+
}
|
|
805
912
|
}
|
|
806
|
-
return _defaultToken
|
|
807
|
-
}
|
|
808
|
-
function getPublicToken() {
|
|
809
|
-
return (
|
|
810
|
-
// Lazily access constants.ENV.SOCKET_SECURITY_API_TOKEN.
|
|
811
|
-
(constants.ENV.SOCKET_SECURITY_API_TOKEN || getDefaultToken()) ??
|
|
812
|
-
SOCKET_PUBLIC_API_TOKEN
|
|
813
|
-
)
|
|
814
913
|
}
|
|
815
|
-
async function
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
) {
|
|
820
|
-
if (typeof apiToken !== 'string' && vendor.isInteractiveExports()) {
|
|
821
|
-
apiToken = await prompts.password({
|
|
822
|
-
message:
|
|
823
|
-
'Enter your Socket.dev API key (not saved, use socket login to persist)'
|
|
824
|
-
})
|
|
825
|
-
_defaultToken = apiToken
|
|
914
|
+
async function queryApiSafeJson(path, fetchSpinnerDesc = '') {
|
|
915
|
+
const result = await queryApiSafeText(path, fetchSpinnerDesc)
|
|
916
|
+
if (!result.ok) {
|
|
917
|
+
return result
|
|
826
918
|
}
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
919
|
+
try {
|
|
920
|
+
return {
|
|
921
|
+
ok: true,
|
|
922
|
+
data: JSON.parse(result.data)
|
|
923
|
+
}
|
|
924
|
+
} catch (e) {
|
|
925
|
+
return {
|
|
926
|
+
ok: false,
|
|
927
|
+
message: 'Server returned invalid JSON',
|
|
928
|
+
cause: `Please report this. JSON.parse threw an error over the following response: \`${(result.data?.slice?.(0, 100) || '<empty>').trim() + (result.data?.length > 100 ? '...' : '')}\``
|
|
929
|
+
}
|
|
830
930
|
}
|
|
831
|
-
return new vendor.distExports$2.SocketSdk(apiToken, {
|
|
832
|
-
agent: proxy
|
|
833
|
-
? new vendor.HttpsProxyAgent({
|
|
834
|
-
proxy
|
|
835
|
-
})
|
|
836
|
-
: undefined,
|
|
837
|
-
baseUrl: apiBaseUrl,
|
|
838
|
-
userAgent: vendor.distExports$2.createUserAgentFromPkgJson({
|
|
839
|
-
// Lazily access constants.ENV.INLINED_SOCKET_CLI_NAME.
|
|
840
|
-
name: constants.ENV.INLINED_SOCKET_CLI_NAME,
|
|
841
|
-
// Lazily access constants.ENV.INLINED_SOCKET_CLI_VERSION.
|
|
842
|
-
version: constants.ENV.INLINED_SOCKET_CLI_VERSION,
|
|
843
|
-
// Lazily access constants.ENV.INLINED_SOCKET_CLI_HOMEPAGE.
|
|
844
|
-
homepage: constants.ENV.INLINED_SOCKET_CLI_HOMEPAGE
|
|
845
|
-
})
|
|
846
|
-
})
|
|
847
931
|
}
|
|
848
932
|
|
|
849
933
|
function mdTableStringNumber(title1, title2, obj) {
|
|
@@ -1161,53 +1245,20 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1161
1245
|
'Do input validation for a command and exit 0 when input is ok. Every command should support this flag (not shown on help screens)'
|
|
1162
1246
|
}
|
|
1163
1247
|
}
|
|
1164
|
-
const cli = vendor.meow(
|
|
1165
|
-
`
|
|
1166
|
-
Usage
|
|
1167
|
-
$ ${name} <command>
|
|
1168
1248
|
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
const { hidden } = alias
|
|
1183
|
-
const cmdName = hidden ? '' : alias.argv[0]
|
|
1184
|
-
const subcommand = cmdName ? subcommands[cmdName] : undefined
|
|
1185
|
-
return subcommand && !subcommand.hidden
|
|
1186
|
-
})
|
|
1187
|
-
)
|
|
1188
|
-
)
|
|
1189
|
-
},
|
|
1190
|
-
6
|
|
1191
|
-
)}
|
|
1192
|
-
|
|
1193
|
-
Options
|
|
1194
|
-
${getFlagListOutput(flags, 6)}
|
|
1195
|
-
|
|
1196
|
-
Examples
|
|
1197
|
-
$ ${name} --help
|
|
1198
|
-
`,
|
|
1199
|
-
{
|
|
1200
|
-
argv,
|
|
1201
|
-
importMeta,
|
|
1202
|
-
...additionalOptions,
|
|
1203
|
-
flags,
|
|
1204
|
-
// Do not strictly check for flags here.
|
|
1205
|
-
allowUnknownFlags: true,
|
|
1206
|
-
// We will emit help when we're ready
|
|
1207
|
-
// Plus, if we allow this then meow() can just exit here.
|
|
1208
|
-
autoHelp: false
|
|
1209
|
-
}
|
|
1210
|
-
)
|
|
1249
|
+
// This is basically a dry-run parse of cli args and flags. We use this to
|
|
1250
|
+
// determine config overrides and expected output mode.
|
|
1251
|
+
const cli1 = vendor.meow(`(this should never be printed)`, {
|
|
1252
|
+
argv,
|
|
1253
|
+
importMeta,
|
|
1254
|
+
...additionalOptions,
|
|
1255
|
+
flags,
|
|
1256
|
+
// Do not strictly check for flags here.
|
|
1257
|
+
allowUnknownFlags: true,
|
|
1258
|
+
// We will emit help when we're ready
|
|
1259
|
+
// Plus, if we allow this then meow() can just exit here.
|
|
1260
|
+
autoHelp: false
|
|
1261
|
+
})
|
|
1211
1262
|
|
|
1212
1263
|
// Hard override the config if instructed to do so.
|
|
1213
1264
|
// The env var overrides the --flag, which overrides the persisted config
|
|
@@ -1219,9 +1270,9 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1219
1270
|
// Lazily access constants.ENV.SOCKET_CLI_CONFIG.
|
|
1220
1271
|
constants.ENV.SOCKET_CLI_CONFIG
|
|
1221
1272
|
)
|
|
1222
|
-
} else if (
|
|
1273
|
+
} else if (cli1.flags['config']) {
|
|
1223
1274
|
configOverrideResult = overrideCachedConfig(
|
|
1224
|
-
String(
|
|
1275
|
+
String(cli1.flags['config'] || '')
|
|
1225
1276
|
)
|
|
1226
1277
|
}
|
|
1227
1278
|
|
|
@@ -1262,19 +1313,75 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1262
1313
|
})
|
|
1263
1314
|
}
|
|
1264
1315
|
}
|
|
1316
|
+
if (isTestingV1()) {
|
|
1317
|
+
delete subcommands['diff-scan']
|
|
1318
|
+
delete subcommands['info']
|
|
1319
|
+
delete subcommands['report']
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
// Parse it again. Config overrides should now be applied (may affect help).
|
|
1323
|
+
const cli2 = vendor.meow(
|
|
1324
|
+
`
|
|
1325
|
+
Usage
|
|
1326
|
+
$ ${name} <command>
|
|
1327
|
+
|
|
1328
|
+
Commands
|
|
1329
|
+
${getHelpListOutput(
|
|
1330
|
+
{
|
|
1331
|
+
...objects.toSortedObject(
|
|
1332
|
+
Object.fromEntries(
|
|
1333
|
+
Object.entries(subcommands).filter(
|
|
1334
|
+
({ 1: subcommand }) => !subcommand.hidden
|
|
1335
|
+
)
|
|
1336
|
+
)
|
|
1337
|
+
),
|
|
1338
|
+
...objects.toSortedObject(
|
|
1339
|
+
Object.fromEntries(
|
|
1340
|
+
Object.entries(aliases).filter(({ 1: alias }) => {
|
|
1341
|
+
const { hidden } = alias
|
|
1342
|
+
const cmdName = hidden ? '' : alias.argv[0]
|
|
1343
|
+
const subcommand = cmdName ? subcommands[cmdName] : undefined
|
|
1344
|
+
return subcommand && !subcommand.hidden
|
|
1345
|
+
})
|
|
1346
|
+
)
|
|
1347
|
+
)
|
|
1348
|
+
},
|
|
1349
|
+
6
|
|
1350
|
+
)}
|
|
1351
|
+
|
|
1352
|
+
Options
|
|
1353
|
+
${getFlagListOutput(flags, 6)}
|
|
1354
|
+
|
|
1355
|
+
Examples
|
|
1356
|
+
$ ${name} --help
|
|
1357
|
+
`,
|
|
1358
|
+
{
|
|
1359
|
+
argv,
|
|
1360
|
+
importMeta,
|
|
1361
|
+
...additionalOptions,
|
|
1362
|
+
flags,
|
|
1363
|
+
// Do not strictly check for flags here.
|
|
1364
|
+
allowUnknownFlags: true,
|
|
1365
|
+
// We will emit help when we're ready
|
|
1366
|
+
// Plus, if we allow this then meow() can just exit here.
|
|
1367
|
+
autoHelp: false
|
|
1368
|
+
}
|
|
1369
|
+
)
|
|
1265
1370
|
|
|
1266
1371
|
// ...else we provide basic instructions and help.
|
|
1267
|
-
if (!
|
|
1372
|
+
if (!cli2.flags['silent']) {
|
|
1268
1373
|
emitBanner(name)
|
|
1269
1374
|
}
|
|
1270
|
-
if (!
|
|
1375
|
+
if (!cli2.flags['help'] && cli2.flags['dryRun']) {
|
|
1271
1376
|
process.exitCode = 0
|
|
1272
1377
|
// Lazily access constants.DRY_RUN_LABEL.
|
|
1273
1378
|
logger.logger.log(
|
|
1274
1379
|
`${constants.DRY_RUN_LABEL}: No-op, call a sub-command; ok`
|
|
1275
1380
|
)
|
|
1276
1381
|
} else {
|
|
1277
|
-
|
|
1382
|
+
// When you explicitly request --help, the command should be successful
|
|
1383
|
+
// so we exit(0). If we do it because we need more input, we exit(2).
|
|
1384
|
+
cli2.showHelp(cli2.flags['help'] ? 0 : 2)
|
|
1278
1385
|
}
|
|
1279
1386
|
}
|
|
1280
1387
|
|
|
@@ -1298,15 +1405,44 @@ function meowOrExit({
|
|
|
1298
1405
|
help: config.help(command, config),
|
|
1299
1406
|
importMeta,
|
|
1300
1407
|
flags: config.flags,
|
|
1301
|
-
allowUnknownFlags:
|
|
1302
|
-
|
|
1408
|
+
allowUnknownFlags: true,
|
|
1409
|
+
// meow will exit(1) before printing the banner
|
|
1410
|
+
autoHelp: false // meow will exit(0) before printing the banner
|
|
1303
1411
|
})
|
|
1304
1412
|
if (!cli.flags['silent']) {
|
|
1305
1413
|
emitBanner(command)
|
|
1306
1414
|
}
|
|
1415
|
+
if (!allowUnknownFlags) {
|
|
1416
|
+
// Run meow specifically with the flag setting. It will exit(2) if an
|
|
1417
|
+
// invalid flag is set and print a message.
|
|
1418
|
+
vendor.meow({
|
|
1419
|
+
argv,
|
|
1420
|
+
description: config.description,
|
|
1421
|
+
help: config.help(command, config),
|
|
1422
|
+
importMeta,
|
|
1423
|
+
flags: config.flags,
|
|
1424
|
+
allowUnknownFlags: false,
|
|
1425
|
+
autoHelp: false
|
|
1426
|
+
})
|
|
1427
|
+
}
|
|
1307
1428
|
if (cli.flags['help']) {
|
|
1308
|
-
cli.showHelp()
|
|
1429
|
+
cli.showHelp(0)
|
|
1309
1430
|
}
|
|
1431
|
+
// Now test for help state. Run meow again. If it exits now, it must be due
|
|
1432
|
+
// to wanting to print the help screen. But it would exit(0) and we want a
|
|
1433
|
+
// consistent exit(2) for that case (missing input). TODO: move away from meow
|
|
1434
|
+
process.exitCode = 2
|
|
1435
|
+
vendor.meow({
|
|
1436
|
+
argv,
|
|
1437
|
+
description: config.description,
|
|
1438
|
+
help: config.help(command, config),
|
|
1439
|
+
importMeta,
|
|
1440
|
+
flags: config.flags,
|
|
1441
|
+
allowUnknownFlags: Boolean(allowUnknownFlags),
|
|
1442
|
+
autoHelp: false
|
|
1443
|
+
})
|
|
1444
|
+
// Ok, no help, reset to default.
|
|
1445
|
+
process.exitCode = 0
|
|
1310
1446
|
return cli
|
|
1311
1447
|
}
|
|
1312
1448
|
function emitBanner(name) {
|
|
@@ -1330,7 +1466,6 @@ function getAsciiHeader(command) {
|
|
|
1330
1466
|
: // Lazily access constants.ENV.INLINED_SOCKET_CLI_VERSION_HASH.
|
|
1331
1467
|
constants.ENV.INLINED_SOCKET_CLI_VERSION_HASH
|
|
1332
1468
|
const nodeVersion = redacting ? REDACTED : process.version
|
|
1333
|
-
const apiToken = getDefaultToken()
|
|
1334
1469
|
const defaultOrg = getConfigValueOrUndef('defaultOrg')
|
|
1335
1470
|
const readOnlyConfig = isReadOnlyConfig() ? '*' : '.'
|
|
1336
1471
|
const v1test = isTestingV1() ? ' (is testing v1)' : ''
|
|
@@ -1339,11 +1474,7 @@ function getAsciiHeader(command) {
|
|
|
1339
1474
|
' (Thank you for testing the v1 bump! Please send us any feedback you might have!)\n'
|
|
1340
1475
|
)
|
|
1341
1476
|
: ''
|
|
1342
|
-
const shownToken = redacting
|
|
1343
|
-
? REDACTED
|
|
1344
|
-
: apiToken
|
|
1345
|
-
? getLastFiveOfApiToken(apiToken)
|
|
1346
|
-
: 'no'
|
|
1477
|
+
const shownToken = redacting ? REDACTED : getVisibleTokenPrefix() || 'no'
|
|
1347
1478
|
const relCwd = redacting
|
|
1348
1479
|
? REDACTED
|
|
1349
1480
|
: path$1.normalizePath(
|
|
@@ -1376,7 +1507,11 @@ function getAsciiHeader(command) {
|
|
|
1376
1507
|
}
|
|
1377
1508
|
|
|
1378
1509
|
async function suggestOrgSlug() {
|
|
1379
|
-
const
|
|
1510
|
+
const sockSdkResult = await setupSdk()
|
|
1511
|
+
if (!sockSdkResult.ok) {
|
|
1512
|
+
return
|
|
1513
|
+
}
|
|
1514
|
+
const sockSdk = sockSdkResult.data
|
|
1380
1515
|
const result = await handleApiCall(
|
|
1381
1516
|
sockSdk.getOrganizations(),
|
|
1382
1517
|
'list of organizations'
|
|
@@ -1669,6 +1804,27 @@ function isHelpFlag(cmdArg) {
|
|
|
1669
1804
|
return helpFlags.has(cmdArg)
|
|
1670
1805
|
}
|
|
1671
1806
|
|
|
1807
|
+
function getPkgFullNameFromPurlObj(purlObj) {
|
|
1808
|
+
const { name, namespace } = purlObj
|
|
1809
|
+
return namespace
|
|
1810
|
+
? `${namespace}${purlObj.type === 'maven' ? ':' : '/'}${name}`
|
|
1811
|
+
: name
|
|
1812
|
+
}
|
|
1813
|
+
function getSocketDevAlertUrl(alertType) {
|
|
1814
|
+
return `https://socket.dev/alerts/${alertType}`
|
|
1815
|
+
}
|
|
1816
|
+
function getSocketDevPackageOverviewUrlFromPurl(purlObj) {
|
|
1817
|
+
const fullName = getPkgFullNameFromPurlObj(purlObj)
|
|
1818
|
+
return getSocketDevPackageOverviewUrl(purlObj.type, fullName, purlObj.version)
|
|
1819
|
+
}
|
|
1820
|
+
function getSocketDevPackageOverviewUrl(ecosystem, fullName, version) {
|
|
1821
|
+
if (ecosystem === 'go') {
|
|
1822
|
+
return `https://socket.dev/go/package/${fullName}${version ? `?section=overview&version=${version}` : ''}`
|
|
1823
|
+
} else {
|
|
1824
|
+
return `https://socket.dev/${ecosystem}/package/${fullName}${version ? `/overview/${version}` : ''}`
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1672
1828
|
/**
|
|
1673
1829
|
* Convert a Map<string, Map|string> to a nested object of similar shape.
|
|
1674
1830
|
* The goal is to serialize it with JSON.stringify, which Map can't do.
|
|
@@ -1846,13 +2002,6 @@ class ColorOrMarkdown {
|
|
|
1846
2002
|
}
|
|
1847
2003
|
}
|
|
1848
2004
|
|
|
1849
|
-
function getSocketDevAlertUrl(alertType) {
|
|
1850
|
-
return `https://socket.dev/alerts/${alertType}`
|
|
1851
|
-
}
|
|
1852
|
-
function getSocketDevPackageOverviewUrl(eco, name, version) {
|
|
1853
|
-
return `https://socket.dev/${eco}/package/${name}${version ? `/overview/${version}` : ''}`
|
|
1854
|
-
}
|
|
1855
|
-
|
|
1856
2005
|
const require$1 = Module.createRequire(
|
|
1857
2006
|
require('u' + 'rl').pathToFileURL(__filename).href
|
|
1858
2007
|
)
|
|
@@ -2504,7 +2653,11 @@ async function getAlertsMapFromPurls(purls, options_) {
|
|
|
2504
2653
|
}
|
|
2505
2654
|
const getText = () => `Looking up data for ${remaining} packages`
|
|
2506
2655
|
spinner?.start(getText())
|
|
2507
|
-
const
|
|
2656
|
+
const sockSdkResult = await setupSdk(getPublicToken())
|
|
2657
|
+
if (!sockSdkResult.ok) {
|
|
2658
|
+
throw new Error('Auth error: Try to run `socket login` first')
|
|
2659
|
+
}
|
|
2660
|
+
const sockSdk = sockSdkResult.data
|
|
2508
2661
|
const toAlertsMapOptions = {
|
|
2509
2662
|
overrides: options.overrides,
|
|
2510
2663
|
consolidate: options.consolidate,
|
|
@@ -3118,25 +3271,26 @@ exports.getAlertsMapFromPurls = getAlertsMapFromPurls
|
|
|
3118
3271
|
exports.getConfigValue = getConfigValue
|
|
3119
3272
|
exports.getConfigValueOrUndef = getConfigValueOrUndef
|
|
3120
3273
|
exports.getCveInfoByAlertsMap = getCveInfoByAlertsMap
|
|
3121
|
-
exports.getDefaultToken = getDefaultToken
|
|
3122
3274
|
exports.getFlagListOutput = getFlagListOutput
|
|
3123
|
-
exports.getLastFiveOfApiToken = getLastFiveOfApiToken
|
|
3124
3275
|
exports.getMajor = getMajor
|
|
3125
3276
|
exports.getNpmBinPath = getNpmBinPath
|
|
3126
3277
|
exports.getNpmRequire = getNpmRequire
|
|
3127
3278
|
exports.getNpxBinPath = getNpxBinPath
|
|
3128
3279
|
exports.getOutputKind = getOutputKind
|
|
3129
3280
|
exports.getPackageFilesForScan = getPackageFilesForScan
|
|
3281
|
+
exports.getPkgFullNameFromPurlObj = getPkgFullNameFromPurlObj
|
|
3130
3282
|
exports.getPublicToken = getPublicToken
|
|
3131
3283
|
exports.getSeverityCount = getSeverityCount
|
|
3132
3284
|
exports.getSocketDevAlertUrl = getSocketDevAlertUrl
|
|
3133
3285
|
exports.getSocketDevPackageOverviewUrl = getSocketDevPackageOverviewUrl
|
|
3286
|
+
exports.getSocketDevPackageOverviewUrlFromPurl =
|
|
3287
|
+
getSocketDevPackageOverviewUrlFromPurl
|
|
3288
|
+
exports.getVisibleTokenPrefix = getVisibleTokenPrefix
|
|
3134
3289
|
exports.globWorkspace = globWorkspace
|
|
3135
3290
|
exports.handleApiCall = handleApiCall
|
|
3136
3291
|
exports.handleApiCallNoSpinner = handleApiCallNoSpinner
|
|
3137
|
-
exports.handleApiError = handleApiError
|
|
3138
|
-
exports.handleFailedApiResponse = handleFailedApiResponse
|
|
3139
3292
|
exports.handleUnsuccessfulApiResponse = handleUnsuccessfulApiResponse
|
|
3293
|
+
exports.hasDefaultToken = hasDefaultToken
|
|
3140
3294
|
exports.idToPurl = idToPurl
|
|
3141
3295
|
exports.isHelpFlag = isHelpFlag
|
|
3142
3296
|
exports.isNpmBinPathShadowed = isNpmBinPathShadowed
|
|
@@ -3152,7 +3306,8 @@ exports.meowOrExit = meowOrExit
|
|
|
3152
3306
|
exports.meowWithSubcommands = meowWithSubcommands
|
|
3153
3307
|
exports.outputFlags = outputFlags
|
|
3154
3308
|
exports.parsePnpmLockfileVersion = parsePnpmLockfileVersion
|
|
3155
|
-
exports.
|
|
3309
|
+
exports.queryApiSafeJson = queryApiSafeJson
|
|
3310
|
+
exports.queryApiSafeText = queryApiSafeText
|
|
3156
3311
|
exports.removeNodeModules = removeNodeModules
|
|
3157
3312
|
exports.runAgentInstall = runAgentInstall
|
|
3158
3313
|
exports.safeReadFile = safeReadFile
|
|
@@ -3161,9 +3316,8 @@ exports.serializeResultJson = serializeResultJson
|
|
|
3161
3316
|
exports.setupSdk = setupSdk
|
|
3162
3317
|
exports.suggestOrgSlug = suggestOrgSlug
|
|
3163
3318
|
exports.supportedConfigKeys = supportedConfigKeys
|
|
3164
|
-
exports.tmpHandleApiCall = tmpHandleApiCall
|
|
3165
3319
|
exports.updateConfigValue = updateConfigValue
|
|
3166
3320
|
exports.validationFlags = validationFlags
|
|
3167
3321
|
exports.walkNestedMap = walkNestedMap
|
|
3168
|
-
//# debugId=
|
|
3322
|
+
//# debugId=ce901e44-4e3e-43e6-8016-50895b08fc53
|
|
3169
3323
|
//# sourceMappingURL=utils.js.map
|