-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket-cli.ts
More file actions
268 lines (254 loc) · 7.1 KB
/
socket-cli.ts
File metadata and controls
268 lines (254 loc) · 7.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/**
* @file Socket CLI environment variables. Provides typed getters for
* SOCKET_CLI_* environment variables (excluding shadow).
*/
import { envAsBoolean } from './boolean'
import { envAsNumber } from './number'
import { getEnvValue } from './rewire'
/**
* Whether to accept all Socket CLI risks (alternative name).
*
* @example
* ;```typescript
* import { getSocketCliAcceptRisks } from '@socketsecurity/lib/env/socket-cli'
*
* if (getSocketCliAcceptRisks()) {
* console.log('All risks accepted')
* }
* ```
*
* @returns Whether to accept all risks
*/
/*@__NO_SIDE_EFFECTS__*/
export function getSocketCliAcceptRisks(): boolean {
return envAsBoolean(getEnvValue('SOCKET_CLI_ACCEPT_RISKS'))
}
/**
* Socket CLI API base URL (alternative name). Checks SOCKET_CLI_API_BASE_URL
* first, then falls back to legacy SOCKET_SECURITY_API_BASE_URL.
*
* @example
* ;```typescript
* import { getSocketCliApiBaseUrl } from '@socketsecurity/lib/env/socket-cli'
*
* const baseUrl = getSocketCliApiBaseUrl()
* // e.g. 'https://api.socket.dev' or undefined
* ```
*
* @returns API base URL or undefined
*/
/*@__NO_SIDE_EFFECTS__*/
export function getSocketCliApiBaseUrl(): string | undefined {
return (
getEnvValue('SOCKET_CLI_API_BASE_URL') ||
getEnvValue('SOCKET_SECURITY_API_BASE_URL')
)
}
/**
* Proxy URL for Socket CLI API requests (alternative name). Checks
* SOCKET_CLI_API_PROXY, SOCKET_SECURITY_API_PROXY, then standard proxy env
* vars. Follows the same precedence as v1.x: HTTPS_PROXY → https_proxy →
* HTTP_PROXY → http_proxy.
*
* @example
* ;```typescript
* import { getSocketCliApiProxy } from '@socketsecurity/lib/env/socket-cli'
*
* const proxy = getSocketCliApiProxy()
* // e.g. 'http://proxy.example.com:8080' or undefined
* ```
*
* @returns API proxy URL or undefined
*/
/*@__NO_SIDE_EFFECTS__*/
export function getSocketCliApiProxy(): string | undefined {
return (
getEnvValue('SOCKET_CLI_API_PROXY') ||
getEnvValue('SOCKET_SECURITY_API_PROXY') ||
getEnvValue('HTTPS_PROXY') ||
getEnvValue('https_proxy') ||
getEnvValue('HTTP_PROXY') ||
getEnvValue('http_proxy')
)
}
/**
* Timeout in milliseconds for Socket CLI API requests (alternative name).
*
* @example
* ;```typescript
* import { getSocketCliApiTimeout } from '@socketsecurity/lib/env/socket-cli'
*
* const timeout = getSocketCliApiTimeout()
* // e.g. 30000 or 0 if not set
* ```
*
* @returns API timeout in milliseconds
*/
/*@__NO_SIDE_EFFECTS__*/
export function getSocketCliApiTimeout(): number {
return envAsNumber(getEnvValue('SOCKET_CLI_API_TIMEOUT'))
}
/**
* Bootstrap cache directory path. Set by bootstrap wrappers to pass dlx cache
* location to CLI.
*
* @example
* ;```typescript
* import { getSocketCliBootstrapCacheDir } from '@socketsecurity/lib/env/socket-cli'
*
* const cacheDir = getSocketCliBootstrapCacheDir()
* // e.g. '/tmp/.socket-cli-cache' or undefined
* ```
*
* @returns Bootstrap cache directory or undefined
*/
/*@__NO_SIDE_EFFECTS__*/
export function getSocketCliBootstrapCacheDir(): string | undefined {
return getEnvValue('SOCKET_CLI_BOOTSTRAP_CACHE_DIR')
}
/**
* Bootstrap package spec (e.g., @socketsecurity/cli@^2.0.11). Set by bootstrap
* wrappers (SEA/smol/npm) to pass package spec to CLI.
*
* @example
* ;```typescript
* import { getSocketCliBootstrapSpec } from '@socketsecurity/lib/env/socket-cli'
*
* const spec = getSocketCliBootstrapSpec()
* // e.g. '@socketsecurity/cli@^2.0.11' or undefined
* ```
*
* @returns Bootstrap package spec or undefined
*/
/*@__NO_SIDE_EFFECTS__*/
export function getSocketCliBootstrapSpec(): string | undefined {
return getEnvValue('SOCKET_CLI_BOOTSTRAP_SPEC')
}
/**
* Socket CLI configuration file path (alternative name).
*
* @example
* ;```typescript
* import { getSocketCliConfig } from '@socketsecurity/lib/env/socket-cli'
*
* const config = getSocketCliConfig()
* // e.g. '/tmp/project/socket.yml' or undefined
* ```
*
* @returns Config file path or undefined
*/
/*@__NO_SIDE_EFFECTS__*/
export function getSocketCliConfig(): string | undefined {
return getEnvValue('SOCKET_CLI_CONFIG')
}
/**
* Controls Socket CLI fix mode.
*
* @example
* ;```typescript
* import { getSocketCliFix } from '@socketsecurity/lib/env/socket-cli'
*
* const fix = getSocketCliFix()
* // e.g. 'true' or undefined
* ```
*
* @returns Fix mode value or undefined
*/
/*@__NO_SIDE_EFFECTS__*/
export function getSocketCliFix(): string | undefined {
return getEnvValue('SOCKET_CLI_FIX')
}
/**
* Socket CLI GitHub authentication token. Checks SOCKET_CLI_GITHUB_TOKEN,
* SOCKET_SECURITY_GITHUB_PAT, then falls back to GITHUB_TOKEN.
*
* @example
* ;```typescript
* import { getSocketCliGithubToken } from '@socketsecurity/lib/env/socket-cli'
*
* const token = getSocketCliGithubToken()
* // e.g. 'ghp_abc123...' or undefined
* ```
*
* @returns GitHub token or undefined
*/
/*@__NO_SIDE_EFFECTS__*/
export function getSocketCliGithubToken(): string | undefined {
return (
getEnvValue('SOCKET_CLI_GITHUB_TOKEN') ||
getEnvValue('SOCKET_SECURITY_GITHUB_PAT') ||
getEnvValue('GITHUB_TOKEN')
)
}
/**
* Whether to skip Socket CLI API token requirement (alternative name).
*
* @example
* ;```typescript
* import { getSocketCliNoApiToken } from '@socketsecurity/lib/env/socket-cli'
*
* if (getSocketCliNoApiToken()) {
* console.log('API token requirement skipped')
* }
* ```
*
* @returns Whether to skip API token requirement
*/
/*@__NO_SIDE_EFFECTS__*/
export function getSocketCliNoApiToken(): boolean {
return envAsBoolean(getEnvValue('SOCKET_CLI_NO_API_TOKEN'))
}
/**
* Controls Socket CLI optimization mode.
*
* @example
* ;```typescript
* import { getSocketCliOptimize } from '@socketsecurity/lib/env/socket-cli'
*
* if (getSocketCliOptimize()) {
* console.log('Optimization mode enabled')
* }
* ```
*
* @returns Whether optimization mode is enabled
*/
/*@__NO_SIDE_EFFECTS__*/
export function getSocketCliOptimize(): boolean {
return envAsBoolean(getEnvValue('SOCKET_CLI_OPTIMIZE'))
}
/**
* Socket CLI organization slug identifier (alternative name). Checks
* SOCKET_CLI_ORG_SLUG first, then falls back to SOCKET_ORG_SLUG.
*
* @example
* ;```typescript
* import { getSocketCliOrgSlug } from '@socketsecurity/lib/env/socket-cli'
*
* const slug = getSocketCliOrgSlug()
* // e.g. 'my-org' or undefined
* ```
*
* @returns Organization slug or undefined
*/
/*@__NO_SIDE_EFFECTS__*/
export function getSocketCliOrgSlug(): string | undefined {
return getEnvValue('SOCKET_CLI_ORG_SLUG') || getEnvValue('SOCKET_ORG_SLUG')
}
/**
* Whether to view all Socket CLI risks (alternative name).
*
* @example
* ;```typescript
* import { getSocketCliViewAllRisks } from '@socketsecurity/lib/env/socket-cli'
*
* if (getSocketCliViewAllRisks()) {
* console.log('Viewing all risks')
* }
* ```
*
* @returns Whether to view all risks
*/
/*@__NO_SIDE_EFFECTS__*/
export function getSocketCliViewAllRisks(): boolean {
return envAsBoolean(getEnvValue('SOCKET_CLI_VIEW_ALL_RISKS'))
}