@socketsecurity/cli-with-sentry 0.14.68 → 0.14.69

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.
@@ -9,7 +9,16 @@ interface LocalConfig {
9
9
  }
10
10
  declare const supportedConfigKeys: Map<keyof LocalConfig, string>
11
11
  declare const sensitiveConfigKeys: Set<keyof LocalConfig>
12
- declare function overrideCachedConfig(config: object): void
12
+ declare function overrideCachedConfig(jsonConfig: unknown):
13
+ | {
14
+ ok: true
15
+ message: undefined
16
+ }
17
+ | {
18
+ ok: false
19
+ message: string
20
+ }
21
+ declare function overrideConfigApiToken(apiToken: unknown): void
13
22
  declare function findSocketYmlSync(dir?: string): {
14
23
  path: string
15
24
  parsed: config.SocketYml
@@ -17,6 +26,7 @@ declare function findSocketYmlSync(dir?: string): {
17
26
  declare function getConfigValue<Key extends keyof LocalConfig>(
18
27
  key: Key
19
28
  ): LocalConfig[Key]
29
+ declare function isReadOnlyConfig(): boolean
20
30
  declare function updateConfigValue<Key extends keyof LocalConfig>(
21
31
  key: keyof LocalConfig,
22
32
  value: LocalConfig[Key]
@@ -26,7 +36,9 @@ export {
26
36
  supportedConfigKeys,
27
37
  sensitiveConfigKeys,
28
38
  overrideCachedConfig,
39
+ overrideConfigApiToken,
29
40
  findSocketYmlSync,
30
41
  getConfigValue,
42
+ isReadOnlyConfig,
31
43
  updateConfigValue
32
44
  }
@@ -112,7 +112,7 @@ const supportedConfigKeys = new Map([
112
112
  ['apiToken', 'The API token required to access most API endpoints'],
113
113
  [
114
114
  'defaultOrg',
115
- 'The default org slug to use when appropriate; usually the org your API token has access to. When set, all orgSlug arguments are implied to be this value.'
115
+ 'The default org slug to use; usually the org your API token has access to. When set, all orgSlug arguments are implied to be this value.'
116
116
  ],
117
117
  [
118
118
  'enforcedOrgs',
@@ -121,18 +121,55 @@ const supportedConfigKeys = new Map([
121
121
  ])
122
122
  const sensitiveConfigKeys = new Set(['apiToken'])
123
123
  let _cachedConfig
124
- // When using --config or SOCKET_CLI_CONFIG_OVERRIDE, do not persist the config.
124
+ // When using --config or SOCKET_CLI_CONFIG, do not persist the config.
125
125
  let _readOnlyConfig = false
126
- function overrideCachedConfig(config) {
127
- _cachedConfig = {
128
- ...config
126
+ function overrideCachedConfig(jsonConfig) {
127
+ let config
128
+ try {
129
+ config = JSON.parse(String(jsonConfig))
130
+ if (!config || typeof config !== 'object') {
131
+ // Just throw to reuse the error message. `null` is valid json,
132
+ // so are primitive values. They're not valid config objects :)
133
+ throw new Error()
134
+ }
135
+ } catch {
136
+ return {
137
+ ok: false,
138
+ message:
139
+ "Could not JSON parse the config override. Make sure it's a proper JSON object (double-quoted keys and strings, no unquoted `undefined`) and try again."
140
+ }
129
141
  }
142
+
143
+ // @ts-ignore if you want to override an illegal object, so be it?
144
+ _cachedConfig = config
130
145
  _readOnlyConfig = true
146
+
131
147
  // Normalize apiKey to apiToken.
132
148
  if (_cachedConfig['apiKey']) {
149
+ if (_cachedConfig['apiToken']) {
150
+ logger.logger.warn(
151
+ 'Note: The config override had both apiToken and apiKey. Using the apiToken value. Remove the apiKey to get rid of this message.'
152
+ )
153
+ }
133
154
  _cachedConfig['apiToken'] = _cachedConfig['apiKey']
134
155
  delete _cachedConfig['apiKey']
135
156
  }
157
+ return {
158
+ ok: true,
159
+ message: undefined
160
+ }
161
+ }
162
+ function overrideConfigApiToken(apiToken) {
163
+ // Set token to the local cached config and mark it read-only so it doesn't persist
164
+ _cachedConfig = {
165
+ ...config,
166
+ ...(apiToken === undefined
167
+ ? {}
168
+ : {
169
+ apiToken: String(apiToken)
170
+ })
171
+ }
172
+ _readOnlyConfig = true
136
173
  }
137
174
  function getConfigValues() {
138
175
  if (_cachedConfig === undefined) {
@@ -245,6 +282,9 @@ function getConfigValue(key) {
245
282
  const localConfig = getConfigValues()
246
283
  return localConfig[normalizeConfigKey(key)]
247
284
  }
285
+ function isReadOnlyConfig() {
286
+ return _readOnlyConfig
287
+ }
248
288
  let _pendingSave = false
249
289
  function updateConfigValue(key, value) {
250
290
  const localConfig = getConfigValues()
@@ -290,7 +330,7 @@ function captureExceptionSync(exception, hint) {
290
330
  if (!Sentry) {
291
331
  return ''
292
332
  }
293
- debug.debugLog('captureException: Sending exception to Sentry.')
333
+ debug.debugLog('captureException: Sending exception to Sentry')
294
334
  return Sentry.captureException(exception, hint)
295
335
  }
296
336
 
@@ -366,7 +406,7 @@ async function setupSdk(
366
406
  // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_NAME']".
367
407
  name: '@socketsecurity/cli',
368
408
  // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
369
- version: '0.14.68',
409
+ version: '0.14.69',
370
410
  // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_HOMEPAGE']".
371
411
  homepage: 'https://github.com/SocketDev/socket-cli'
372
412
  })
@@ -1732,7 +1772,7 @@ function getDetailsFromDiff(diff_, options) {
1732
1772
  existing = oldNode
1733
1773
  }
1734
1774
  } else {
1735
- debug.debugLog('SKIPPING META CHANGE ON', diff)
1775
+ debug.debugLog('SKIPPING META CHANGE ON\n', diff)
1736
1776
  }
1737
1777
  } else {
1738
1778
  keep = action !== DiffAction.remove
@@ -1829,10 +1869,12 @@ function findPackageNodes(tree, packageName) {
1829
1869
  }
1830
1870
  return matches
1831
1871
  }
1832
- async function getAlertsMapFromArborist(arb, options) {
1833
- const { include: _include, spinner } = {
1872
+ async function getAlertsMapFromArborist(arb, options_) {
1873
+ const options = {
1834
1874
  __proto__: null,
1835
- ...options
1875
+ consolidate: false,
1876
+ nothrow: false,
1877
+ ...options_
1836
1878
  }
1837
1879
  const include = {
1838
1880
  __proto__: null,
@@ -1842,8 +1884,9 @@ async function getAlertsMapFromArborist(arb, options) {
1842
1884
  existing: false,
1843
1885
  unfixable: true,
1844
1886
  upgradable: false,
1845
- ..._include
1887
+ ...options.include
1846
1888
  }
1889
+ const { spinner } = options
1847
1890
  const needInfoOn = getDetailsFromDiff(arb.diff, {
1848
1891
  include: {
1849
1892
  unchanged: include.existing
@@ -1872,11 +1915,12 @@ async function getAlertsMapFromArborist(arb, options) {
1872
1915
  }
1873
1916
  const sockSdk = await setupSdk(getPublicToken())
1874
1917
  const toAlertsMapOptions = {
1875
- ...options,
1918
+ overrides,
1919
+ consolidate: options.consolidate,
1876
1920
  include,
1877
- overrides
1921
+ spinner
1878
1922
  }
1879
- for await (const batchPackageFetchResult of sockSdk.batchPackageStream(
1923
+ for await (const batchResult of sockSdk.batchPackageStream(
1880
1924
  {
1881
1925
  alerts: 'true',
1882
1926
  compact: 'true',
@@ -1888,12 +1932,18 @@ async function getAlertsMapFromArborist(arb, options) {
1888
1932
  }))
1889
1933
  }
1890
1934
  )) {
1891
- if (batchPackageFetchResult.success) {
1935
+ if (batchResult.success) {
1892
1936
  await addArtifactToAlertsMap(
1893
- batchPackageFetchResult.data,
1937
+ batchResult.data,
1894
1938
  alertsByPkgId,
1895
1939
  toAlertsMapOptions
1896
1940
  )
1941
+ } else if (!options.nothrow) {
1942
+ const statusCode = batchResult.status ?? 'unknown'
1943
+ const statusMessage = batchResult.error ?? 'No status message'
1944
+ throw new Error(
1945
+ `Socket API server error (${statusCode}): ${statusMessage}`
1946
+ )
1897
1947
  }
1898
1948
  remaining -= 1
1899
1949
  if (spinner && remaining > 0) {
@@ -2143,7 +2193,9 @@ exports.getPublicToken = getPublicToken
2143
2193
  exports.getSeverityCount = getSeverityCount
2144
2194
  exports.getSocketDevAlertUrl = getSocketDevAlertUrl
2145
2195
  exports.getSocketDevPackageOverviewUrl = getSocketDevPackageOverviewUrl
2196
+ exports.isReadOnlyConfig = isReadOnlyConfig
2146
2197
  exports.overrideCachedConfig = overrideCachedConfig
2198
+ exports.overrideConfigApiToken = overrideConfigApiToken
2147
2199
  exports.readFileBinary = readFileBinary
2148
2200
  exports.readFileUtf8 = readFileUtf8
2149
2201
  exports.safeReadFile = safeReadFile
@@ -2152,5 +2204,5 @@ exports.setupSdk = setupSdk
2152
2204
  exports.supportedConfigKeys = supportedConfigKeys
2153
2205
  exports.updateConfigValue = updateConfigValue
2154
2206
  exports.updateNode = updateNode
2155
- //# debugId=c4cc0383-a1f3-4096-bddd-173589820ed1
2207
+ //# debugId=cdcd5c63-68c6-42dc-b74c-fbaa59735aeb
2156
2208
  //# sourceMappingURL=shadow-npm-inject.js.map