@socketsecurity/lib 5.18.2 → 5.19.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/CHANGELOG.md +43 -0
- package/README.md +6 -5
- package/dist/abort.d.ts +3 -0
- package/dist/abort.js +1 -0
- package/dist/agent.d.ts +66 -49
- package/dist/agent.js +51 -50
- package/dist/ansi.d.ts +2 -5
- package/dist/ansi.js +3 -2
- package/dist/archives.d.ts +25 -21
- package/dist/archives.js +35 -34
- package/dist/argv/flags.d.ts +100 -91
- package/dist/argv/flags.js +88 -87
- package/dist/argv/parse.d.ts +30 -40
- package/dist/argv/parse.js +33 -32
- package/dist/arrays.d.ts +4 -8
- package/dist/arrays.js +1 -0
- package/dist/bin.d.ts +7 -5
- package/dist/bin.js +52 -29
- package/dist/cacache.d.ts +13 -12
- package/dist/cacache.js +9 -8
- package/dist/cache-with-ttl.d.ts +53 -35
- package/dist/cache-with-ttl.js +1 -0
- package/dist/colors.d.ts +5 -5
- package/dist/colors.js +1 -0
- package/dist/constants/agents.d.ts +5 -9
- package/dist/constants/agents.js +3 -2
- package/dist/constants/core.d.ts +5 -10
- package/dist/constants/core.js +2 -1
- package/dist/constants/encoding.d.ts +3 -3
- package/dist/constants/encoding.js +1 -0
- package/dist/constants/github.d.ts +3 -3
- package/dist/constants/github.js +1 -0
- package/dist/constants/licenses.d.ts +9 -2
- package/dist/constants/licenses.js +1 -0
- package/dist/constants/lifecycle-script-names.js +1 -0
- package/dist/constants/maintained-node-versions.d.ts +3 -0
- package/dist/constants/maintained-node-versions.js +1 -0
- package/dist/constants/node.d.ts +125 -16
- package/dist/constants/node.js +74 -73
- package/dist/constants/package-default-node-range.d.ts +3 -1
- package/dist/constants/package-default-node-range.js +2 -1
- package/dist/constants/package-default-socket-categories.d.ts +0 -1
- package/dist/constants/package-default-socket-categories.js +1 -0
- package/dist/constants/packages.d.ts +12 -17
- package/dist/constants/packages.js +31 -16
- package/dist/constants/platform.d.ts +1 -2
- package/dist/constants/platform.js +2 -1
- package/dist/constants/process.d.ts +18 -0
- package/dist/constants/process.js +1 -0
- package/dist/constants/socket.d.ts +4 -10
- package/dist/constants/socket.js +2 -1
- package/dist/constants/testing.d.ts +3 -3
- package/dist/constants/testing.js +1 -0
- package/dist/constants/time.d.ts +3 -4
- package/dist/constants/time.js +1 -0
- package/dist/constants/typescript.d.ts +10 -3
- package/dist/constants/typescript.js +5 -4
- package/dist/cover/code.d.ts +3 -0
- package/dist/cover/code.js +12 -12
- package/dist/cover/formatters.d.ts +12 -9
- package/dist/cover/formatters.js +19 -18
- package/dist/cover/type.d.ts +3 -0
- package/dist/cover/type.js +1 -0
- package/dist/cover/types.js +1 -0
- package/dist/debug.d.ts +32 -47
- package/dist/debug.js +97 -96
- package/dist/dlx/arborist.d.ts +134 -0
- package/dist/dlx/arborist.js +177 -0
- package/dist/dlx/binary.d.ts +25 -9
- package/dist/dlx/binary.js +34 -12
- package/dist/dlx/cache.d.ts +1 -0
- package/dist/dlx/cache.js +2 -1
- package/dist/dlx/detect.d.ts +15 -0
- package/dist/dlx/detect.js +28 -20
- package/dist/dlx/dir.d.ts +1 -11
- package/dist/dlx/dir.js +2 -12
- package/dist/dlx/integrity.d.ts +86 -0
- package/dist/dlx/integrity.js +112 -0
- package/dist/dlx/lockfile.d.ts +115 -0
- package/dist/dlx/lockfile.js +139 -0
- package/dist/dlx/manifest.d.ts +26 -1
- package/dist/dlx/manifest.js +9 -6
- package/dist/dlx/package.d.ts +58 -3
- package/dist/dlx/package.js +101 -74
- package/dist/dlx/packages.d.ts +1 -11
- package/dist/dlx/packages.js +3 -14
- package/dist/dlx/paths.d.ts +1 -0
- package/dist/dlx/paths.js +2 -1
- package/dist/effects/pulse-frames.js +1 -0
- package/dist/effects/text-shimmer.d.ts +13 -2
- package/dist/effects/text-shimmer.js +50 -46
- package/dist/effects/types.js +1 -0
- package/dist/effects/ultra.js +1 -0
- package/dist/env/ci.d.ts +6 -1
- package/dist/env/ci.js +1 -0
- package/dist/env/debug.d.ts +5 -1
- package/dist/env/debug.js +1 -0
- package/dist/env/github.d.ts +19 -23
- package/dist/env/github.js +5 -4
- package/dist/env/helpers.d.ts +21 -9
- package/dist/env/helpers.js +5 -11
- package/dist/env/home.d.ts +17 -4
- package/dist/env/home.js +2 -1
- package/dist/env/locale.d.ts +4 -3
- package/dist/env/locale.js +1 -0
- package/dist/env/node-auth-token.d.ts +5 -1
- package/dist/env/node-auth-token.js +1 -0
- package/dist/env/node-env.d.ts +5 -1
- package/dist/env/node-env.js +1 -0
- package/dist/env/npm.d.ts +4 -5
- package/dist/env/npm.js +1 -0
- package/dist/env/package-manager.d.ts +4 -3
- package/dist/env/package-manager.js +2 -1
- package/dist/env/path.d.ts +5 -1
- package/dist/env/path.js +1 -0
- package/dist/env/pre-commit.d.ts +5 -1
- package/dist/env/pre-commit.js +1 -0
- package/dist/env/rewire.d.ts +10 -0
- package/dist/env/rewire.js +7 -5
- package/dist/env/shell.d.ts +5 -1
- package/dist/env/shell.js +1 -0
- package/dist/env/socket-cli-shadow.d.ts +4 -5
- package/dist/env/socket-cli-shadow.js +1 -0
- package/dist/env/socket-cli.d.ts +4 -14
- package/dist/env/socket-cli.js +1 -0
- package/dist/env/socket.d.ts +6 -18
- package/dist/env/socket.js +4 -3
- package/dist/env/temp-dir.d.ts +4 -3
- package/dist/env/temp-dir.js +1 -0
- package/dist/env/term.d.ts +5 -1
- package/dist/env/term.js +1 -0
- package/dist/env/test.d.ts +4 -3
- package/dist/env/test.js +1 -0
- package/dist/env/windows.d.ts +4 -4
- package/dist/env/windows.js +1 -0
- package/dist/env/xdg.d.ts +4 -3
- package/dist/env/xdg.js +1 -0
- package/dist/env.d.ts +83 -23
- package/dist/env.js +112 -80
- package/dist/errors.js +1 -0
- package/dist/external/@npmcli/package-json.js +9 -3968
- package/dist/external/@socketregistry/packageurl-js.js +2 -2
- package/dist/external/debug.js +162 -328
- package/dist/external/external-pack.js +3 -2835
- package/dist/external/npm-pack.js +13939 -33342
- package/dist/external/zod.js +160 -7558
- package/dist/fs.d.ts +92 -113
- package/dist/fs.js +35 -35
- package/dist/git.d.ts +170 -164
- package/dist/git.js +113 -87
- package/dist/github.d.ts +249 -227
- package/dist/github.js +82 -81
- package/dist/globs.d.ts +31 -17
- package/dist/globs.js +51 -58
- package/dist/http-request.d.ts +99 -99
- package/dist/http-request.js +182 -156
- package/dist/ipc-cli.d.ts +28 -0
- package/dist/{utils/get-ipc.js → ipc-cli.js} +4 -3
- package/dist/ipc.d.ts +9 -299
- package/dist/ipc.js +18 -204
- package/dist/json/edit.d.ts +3 -1
- package/dist/json/edit.js +30 -30
- package/dist/json/format.d.ts +36 -36
- package/dist/json/format.js +22 -21
- package/dist/json/parse.d.ts +4 -2
- package/dist/json/parse.js +1 -0
- package/dist/json/types.js +1 -0
- package/dist/{links/index.d.ts → links.d.ts} +6 -2
- package/dist/{links/index.js → links.js} +5 -4
- package/dist/logger.d.ts +4 -6
- package/dist/logger.js +61 -53
- package/dist/memoization.d.ts +52 -49
- package/dist/memoization.js +55 -33
- package/dist/objects.d.ts +25 -44
- package/dist/objects.js +2 -1
- package/dist/package-extensions.d.ts +6 -0
- package/dist/package-extensions.js +2 -1
- package/dist/packages/edit.d.ts +3 -5
- package/dist/packages/edit.js +4 -3
- package/dist/packages/exports.d.ts +11 -14
- package/dist/packages/exports.js +11 -10
- package/dist/packages/isolation.d.ts +4 -0
- package/dist/packages/isolation.js +20 -19
- package/dist/packages/licenses.d.ts +3 -10
- package/dist/packages/licenses.js +2 -1
- package/dist/packages/manifest.d.ts +3 -3
- package/dist/packages/manifest.js +1 -0
- package/dist/packages/normalize.d.ts +3 -4
- package/dist/packages/normalize.js +1 -0
- package/dist/packages/operations.d.ts +3 -10
- package/dist/packages/operations.js +1 -0
- package/dist/packages/provenance.d.ts +10 -8
- package/dist/packages/provenance.js +55 -54
- package/dist/packages/specs.d.ts +3 -5
- package/dist/packages/specs.js +1 -0
- package/dist/packages/validation.d.ts +3 -3
- package/dist/packages/validation.js +1 -0
- package/dist/packages.d.ts +2 -17
- package/dist/packages.js +2 -1
- package/dist/paths/dirnames.d.ts +0 -2
- package/dist/paths/dirnames.js +1 -0
- package/dist/paths/exts.d.ts +0 -1
- package/dist/paths/exts.js +1 -0
- package/dist/paths/filenames.d.ts +0 -1
- package/dist/paths/filenames.js +1 -0
- package/dist/paths/globs.d.ts +0 -1
- package/dist/paths/globs.js +1 -0
- package/dist/paths/normalize.d.ts +115 -123
- package/dist/paths/normalize.js +128 -127
- package/dist/paths/packages.d.ts +3 -2
- package/dist/paths/packages.js +2 -1
- package/dist/paths/rewire.d.ts +9 -0
- package/dist/paths/rewire.js +5 -3
- package/dist/paths/socket.d.ts +37 -23
- package/dist/paths/socket.js +26 -25
- package/dist/performance.d.ts +87 -84
- package/dist/performance.js +97 -96
- package/dist/process-lock.d.ts +41 -1
- package/dist/process-lock.js +24 -17
- package/dist/promise-queue.d.ts +6 -0
- package/dist/promise-queue.js +1 -0
- package/dist/promises.d.ts +40 -55
- package/dist/promises.js +12 -11
- package/dist/regexps.d.ts +0 -5
- package/dist/regexps.js +1 -0
- package/dist/releases/github.d.ts +59 -63
- package/dist/releases/github.js +95 -100
- package/dist/releases/socket-btm.d.ts +9 -2
- package/dist/releases/socket-btm.js +32 -25
- package/dist/sea.d.ts +5 -0
- package/dist/sea.js +1 -0
- package/dist/shadow.d.ts +4 -0
- package/dist/shadow.js +1 -0
- package/dist/signal-exit.d.ts +7 -7
- package/dist/signal-exit.js +46 -45
- package/dist/sorts.d.ts +5 -7
- package/dist/sorts.js +11 -10
- package/dist/spawn.d.ts +96 -77
- package/dist/spawn.js +39 -38
- package/dist/spinner.d.ts +21 -22
- package/dist/spinner.js +15 -11
- package/dist/ssri.d.ts +31 -36
- package/dist/ssri.js +15 -14
- package/dist/stdio/_stream.d.ts +31 -0
- package/dist/stdio/_stream.js +57 -0
- package/dist/stdio/divider.d.ts +40 -36
- package/dist/stdio/divider.js +10 -9
- package/dist/stdio/footer.d.ts +20 -0
- package/dist/stdio/footer.js +12 -2
- package/dist/stdio/header.d.ts +4 -16
- package/dist/stdio/header.js +1 -9
- package/dist/stdio/stderr.d.ts +51 -39
- package/dist/stdio/stderr.js +19 -22
- package/dist/stdio/stdout.d.ts +54 -52
- package/dist/stdio/stdout.js +35 -33
- package/dist/streams.d.ts +4 -3
- package/dist/streams.js +1 -0
- package/dist/strings.d.ts +31 -85
- package/dist/strings.js +5 -49
- package/dist/suppress-warnings.d.ts +32 -15
- package/dist/suppress-warnings.js +14 -13
- package/dist/tables.d.ts +30 -26
- package/dist/tables.js +24 -23
- package/dist/temporary-executor.d.ts +4 -0
- package/dist/temporary-executor.js +1 -0
- package/dist/themes/context.d.ts +30 -26
- package/dist/themes/context.js +19 -18
- package/dist/themes/index.d.ts +0 -4
- package/dist/themes/index.js +1 -0
- package/dist/themes/themes.d.ts +1 -1
- package/dist/themes/themes.js +1 -0
- package/dist/themes/types.js +1 -0
- package/dist/themes/utils.d.ts +46 -43
- package/dist/themes/utils.js +45 -44
- package/dist/types.d.ts +48 -52
- package/dist/types.js +35 -35
- package/dist/url.d.ts +48 -53
- package/dist/url.js +38 -37
- package/dist/validation/json-parser.d.ts +19 -190
- package/dist/validation/json-parser.js +5 -69
- package/dist/validation/types.d.ts +9 -33
- package/dist/validation/types.js +1 -0
- package/dist/versions.d.ts +1 -0
- package/dist/versions.js +2 -1
- package/dist/words.d.ts +3 -6
- package/dist/words.js +1 -0
- package/dist/zod.js +1 -0
- package/package.json +34 -66
- package/dist/external/@inquirer/checkbox.js +0 -5
- package/dist/external/@inquirer/confirm.js +0 -5
- package/dist/external/@inquirer/input.js +0 -5
- package/dist/external/@inquirer/password.js +0 -5
- package/dist/external/@inquirer/search.js +0 -5
- package/dist/external/@inquirer/select.js +0 -5
- package/dist/functions.d.ts +0 -57
- package/dist/functions.js +0 -70
- package/dist/stdio/clear.d.ts +0 -140
- package/dist/stdio/clear.js +0 -95
- package/dist/stdio/mask.d.ts +0 -151
- package/dist/stdio/mask.js +0 -224
- package/dist/stdio/progress.d.ts +0 -148
- package/dist/stdio/progress.js +0 -212
- package/dist/stdio/prompts.d.ts +0 -195
- package/dist/stdio/prompts.js +0 -176
- package/dist/utils/get-ipc.d.ts +0 -15
package/dist/github.d.ts
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview GitHub utilities for Socket projects.
|
|
3
|
+
* Provides GitHub API integration for repository operations.
|
|
4
|
+
*
|
|
5
|
+
* Authentication:
|
|
6
|
+
* - getGitHubToken: Retrieve GitHub token from environment variables
|
|
7
|
+
* - fetchGitHub: Authenticated GitHub API requests with rate limit handling
|
|
8
|
+
*
|
|
9
|
+
* Ref Resolution:
|
|
10
|
+
* - resolveRefToSha: Convert tags/branches to commit SHAs (with memoization and persistent cache)
|
|
11
|
+
* - clearRefCache: Clear the in-memory memoization cache
|
|
12
|
+
*
|
|
13
|
+
* Caching:
|
|
14
|
+
* - Uses cacache for persistent storage with in-memory memoization
|
|
15
|
+
* - Two-tier caching: in-memory (Map) for hot data, persistent (cacache) for durability
|
|
16
|
+
* - Default TTL: 5 minutes
|
|
17
|
+
* - Disable with DISABLE_GITHUB_CACHE env var
|
|
18
|
+
*
|
|
19
|
+
* Rate Limiting:
|
|
20
|
+
* - Automatic rate limit detection and error messages
|
|
21
|
+
* - Cache to minimize API calls
|
|
22
|
+
*/
|
|
1
23
|
import type { SpawnOptions } from './spawn';
|
|
2
24
|
/**
|
|
3
25
|
* Options for GitHub API fetch requests.
|
|
@@ -27,83 +49,6 @@ export interface GitHubRateLimitError extends Error {
|
|
|
27
49
|
*/
|
|
28
50
|
resetTime?: Date | undefined;
|
|
29
51
|
}
|
|
30
|
-
/**
|
|
31
|
-
* Get GitHub authentication token from environment variables.
|
|
32
|
-
* Checks multiple environment variable names in priority order.
|
|
33
|
-
*
|
|
34
|
-
* Environment variables checked (in order):
|
|
35
|
-
* 1. `GITHUB_TOKEN` - Standard GitHub token variable
|
|
36
|
-
* 2. `GH_TOKEN` - Alternative GitHub CLI token variable
|
|
37
|
-
* 3. `SOCKET_CLI_GITHUB_TOKEN` - Socket-specific token variable
|
|
38
|
-
*
|
|
39
|
-
* @returns The first available GitHub token, or `undefined` if none found
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```ts
|
|
43
|
-
* const token = getGitHubToken()
|
|
44
|
-
* if (!token) {
|
|
45
|
-
* console.warn('No GitHub token found')
|
|
46
|
-
* }
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
export declare function getGitHubToken(): string | undefined;
|
|
50
|
-
/**
|
|
51
|
-
* Fetch data from GitHub API with automatic authentication and rate limit handling.
|
|
52
|
-
* Makes authenticated requests to the GitHub REST API with proper error handling.
|
|
53
|
-
*
|
|
54
|
-
* Features:
|
|
55
|
-
* - Automatic token injection from environment if not provided
|
|
56
|
-
* - Rate limit detection with helpful error messages
|
|
57
|
-
* - Standard GitHub API headers (Accept, User-Agent)
|
|
58
|
-
* - JSON response parsing
|
|
59
|
-
*
|
|
60
|
-
* @template T - Expected response type (defaults to `unknown`)
|
|
61
|
-
* @param url - Full GitHub API URL (e.g., 'https://api.github.com/repos/owner/repo')
|
|
62
|
-
* @param options - Fetch options including token and custom headers
|
|
63
|
-
* @returns Parsed JSON response of type `T`
|
|
64
|
-
*
|
|
65
|
-
* @throws {GitHubRateLimitError} When API rate limit is exceeded (status 403)
|
|
66
|
-
* @throws {Error} For other API errors with status code and message
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* ```ts
|
|
70
|
-
* // Fetch repository information
|
|
71
|
-
* interface Repo {
|
|
72
|
-
* name: string
|
|
73
|
-
* full_name: string
|
|
74
|
-
* default_branch: string
|
|
75
|
-
* }
|
|
76
|
-
* const repo = await fetchGitHub<Repo>(
|
|
77
|
-
* 'https://api.github.com/repos/owner/repo'
|
|
78
|
-
* )
|
|
79
|
-
* console.log(`Default branch: ${repo.default_branch}`)
|
|
80
|
-
* ```
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```ts
|
|
84
|
-
* // With custom token and headers
|
|
85
|
-
* const data = await fetchGitHub(
|
|
86
|
-
* 'https://api.github.com/user',
|
|
87
|
-
* {
|
|
88
|
-
* token: 'ghp_customtoken',
|
|
89
|
-
* headers: { 'X-Custom-Header': 'value' }
|
|
90
|
-
* }
|
|
91
|
-
* )
|
|
92
|
-
* ```
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```ts
|
|
96
|
-
* // Handle rate limit errors
|
|
97
|
-
* try {
|
|
98
|
-
* await fetchGitHub('https://api.github.com/repos/owner/repo')
|
|
99
|
-
* } catch (error) {
|
|
100
|
-
* if (error.status === 403 && error.resetTime) {
|
|
101
|
-
* console.error(`Rate limited until ${error.resetTime}`)
|
|
102
|
-
* }
|
|
103
|
-
* }
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
export declare function fetchGitHub<T = unknown>(url: string, options?: GitHubFetchOptions | undefined): Promise<T>;
|
|
107
52
|
/**
|
|
108
53
|
* GitHub ref object returned by the API.
|
|
109
54
|
* Represents a git reference (tag or branch).
|
|
@@ -192,129 +137,6 @@ export interface ResolveRefOptions {
|
|
|
192
137
|
*/
|
|
193
138
|
token?: string | undefined;
|
|
194
139
|
}
|
|
195
|
-
/**
|
|
196
|
-
* Resolve a git ref (tag, branch, or commit SHA) to its full commit SHA.
|
|
197
|
-
* Handles tags (annotated and lightweight), branches, and commit SHAs.
|
|
198
|
-
* Results are cached in-memory and on disk (with TTL) to minimize API calls.
|
|
199
|
-
*
|
|
200
|
-
* Resolution strategy:
|
|
201
|
-
* 1. Try as a tag (refs/tags/{ref})
|
|
202
|
-
* 2. If tag is annotated, dereference to get the commit SHA
|
|
203
|
-
* 3. If not a tag, try as a branch (refs/heads/{ref})
|
|
204
|
-
* 4. If not a branch, try as a commit SHA directly
|
|
205
|
-
*
|
|
206
|
-
* Caching behavior:
|
|
207
|
-
* - In-memory cache (Map) for immediate lookups
|
|
208
|
-
* - Persistent disk cache (cacache) for durability across runs
|
|
209
|
-
* - Default TTL: 5 minutes
|
|
210
|
-
* - Disable caching with `DISABLE_GITHUB_CACHE` env var
|
|
211
|
-
*
|
|
212
|
-
* @param owner - Repository owner (user or organization name)
|
|
213
|
-
* @param repo - Repository name
|
|
214
|
-
* @param ref - Git reference to resolve (tag name, branch name, or commit SHA)
|
|
215
|
-
* @param options - Resolution options including authentication token
|
|
216
|
-
* @returns The full commit SHA (40-character hex string)
|
|
217
|
-
*
|
|
218
|
-
* @throws {Error} When ref cannot be resolved after trying all strategies
|
|
219
|
-
* @throws {GitHubRateLimitError} When API rate limit is exceeded
|
|
220
|
-
*
|
|
221
|
-
* @example
|
|
222
|
-
* ```ts
|
|
223
|
-
* // Resolve a tag to commit SHA
|
|
224
|
-
* const sha = await resolveRefToSha('owner', 'repo', 'v1.0.0')
|
|
225
|
-
* console.log(sha) // 'a1b2c3d4e5f6...'
|
|
226
|
-
* ```
|
|
227
|
-
*
|
|
228
|
-
* @example
|
|
229
|
-
* ```ts
|
|
230
|
-
* // Resolve a branch to latest commit SHA
|
|
231
|
-
* const sha = await resolveRefToSha('owner', 'repo', 'main')
|
|
232
|
-
* console.log(sha) // Latest commit on main branch
|
|
233
|
-
* ```
|
|
234
|
-
*
|
|
235
|
-
* @example
|
|
236
|
-
* ```ts
|
|
237
|
-
* // Resolve with custom token
|
|
238
|
-
* const sha = await resolveRefToSha(
|
|
239
|
-
* 'owner',
|
|
240
|
-
* 'repo',
|
|
241
|
-
* 'develop',
|
|
242
|
-
* { token: 'ghp_customtoken' }
|
|
243
|
-
* )
|
|
244
|
-
* ```
|
|
245
|
-
*
|
|
246
|
-
* @example
|
|
247
|
-
* ```ts
|
|
248
|
-
* // Commit SHA passes through unchanged (but validates it exists)
|
|
249
|
-
* const sha = await resolveRefToSha('owner', 'repo', 'a1b2c3d4')
|
|
250
|
-
* console.log(sha) // Full 40-char SHA
|
|
251
|
-
* ```
|
|
252
|
-
*/
|
|
253
|
-
export declare function resolveRefToSha(owner: string, repo: string, ref: string, options?: ResolveRefOptions | undefined): Promise<string>;
|
|
254
|
-
/**
|
|
255
|
-
* Clear the ref resolution cache (in-memory only).
|
|
256
|
-
* Clears the in-memory memoization cache without affecting the persistent disk cache.
|
|
257
|
-
* Useful for testing or when you need fresh data from the API.
|
|
258
|
-
*
|
|
259
|
-
* Note: This only clears the in-memory cache. The persistent cacache storage
|
|
260
|
-
* remains intact and will be used to rebuild the in-memory cache on next access.
|
|
261
|
-
*
|
|
262
|
-
* @returns Promise that resolves when cache is cleared
|
|
263
|
-
*
|
|
264
|
-
* @example
|
|
265
|
-
* ```ts
|
|
266
|
-
* // Clear cache to force fresh API calls
|
|
267
|
-
* await clearRefCache()
|
|
268
|
-
* const sha = await resolveRefToSha('owner', 'repo', 'main')
|
|
269
|
-
* // This will hit the persistent cache or API, not in-memory cache
|
|
270
|
-
* ```
|
|
271
|
-
*/
|
|
272
|
-
export declare function clearRefCache(): Promise<void>;
|
|
273
|
-
/**
|
|
274
|
-
* Get GitHub authentication token from git config.
|
|
275
|
-
* Reads the `github.token` configuration value from git config.
|
|
276
|
-
* This is a fallback method when environment variables don't contain a token.
|
|
277
|
-
*
|
|
278
|
-
* @param options - Spawn options for git command execution
|
|
279
|
-
* @returns GitHub token from git config, or `undefined` if not configured
|
|
280
|
-
*
|
|
281
|
-
* @example
|
|
282
|
-
* ```ts
|
|
283
|
-
* const token = await getGitHubTokenFromGitConfig()
|
|
284
|
-
* if (token) {
|
|
285
|
-
* console.log('Found token in git config')
|
|
286
|
-
* }
|
|
287
|
-
* ```
|
|
288
|
-
*
|
|
289
|
-
* @example
|
|
290
|
-
* ```ts
|
|
291
|
-
* // With custom working directory
|
|
292
|
-
* const token = await getGitHubTokenFromGitConfig({
|
|
293
|
-
* cwd: '/path/to/repo'
|
|
294
|
-
* })
|
|
295
|
-
* ```
|
|
296
|
-
*/
|
|
297
|
-
export declare function getGitHubTokenFromGitConfig(options?: SpawnOptions | undefined): Promise<string | undefined>;
|
|
298
|
-
/**
|
|
299
|
-
* Get GitHub authentication token from all available sources.
|
|
300
|
-
* Checks environment variables first, then falls back to git config.
|
|
301
|
-
* This is the recommended way to get a GitHub token with maximum compatibility.
|
|
302
|
-
*
|
|
303
|
-
* Priority order:
|
|
304
|
-
* 1. Environment variables (GITHUB_TOKEN, GH_TOKEN, SOCKET_CLI_GITHUB_TOKEN)
|
|
305
|
-
* 2. Git config (github.token)
|
|
306
|
-
*
|
|
307
|
-
* @returns GitHub token from first available source, or `undefined` if none found
|
|
308
|
-
*
|
|
309
|
-
* @example
|
|
310
|
-
* ```ts
|
|
311
|
-
* const token = await getGitHubTokenWithFallback()
|
|
312
|
-
* if (!token) {
|
|
313
|
-
* throw new Error('GitHub token required')
|
|
314
|
-
* }
|
|
315
|
-
* ```
|
|
316
|
-
*/
|
|
317
|
-
export declare function getGitHubTokenWithFallback(): Promise<string | undefined>;
|
|
318
140
|
/**
|
|
319
141
|
* GitHub Security Advisory (GHSA) details.
|
|
320
142
|
* Represents a complete security advisory from GitHub's database.
|
|
@@ -383,19 +205,60 @@ export interface GhsaDetails {
|
|
|
383
205
|
}>;
|
|
384
206
|
}
|
|
385
207
|
/**
|
|
386
|
-
*
|
|
387
|
-
*
|
|
208
|
+
* Fetch GitHub Security Advisory details with caching.
|
|
209
|
+
* Retrieves advisory information with two-tier caching (in-memory + persistent).
|
|
210
|
+
* Cached results are stored with the default TTL (5 minutes).
|
|
388
211
|
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
212
|
+
* Caching behavior:
|
|
213
|
+
* - Checks in-memory cache first for immediate response
|
|
214
|
+
* - Falls back to persistent disk cache if not in memory
|
|
215
|
+
* - Fetches from API only if not cached
|
|
216
|
+
* - Stores result in both cache tiers
|
|
217
|
+
* - Respects `DISABLE_GITHUB_CACHE` env var
|
|
218
|
+
*
|
|
219
|
+
* @param ghsaId - GHSA identifier to fetch
|
|
220
|
+
* @param options - Fetch options including authentication token
|
|
221
|
+
* @returns Complete advisory details
|
|
222
|
+
*
|
|
223
|
+
* @throws {Error} If advisory cannot be found or API request fails
|
|
224
|
+
* @throws {GitHubRateLimitError} When API rate limit is exceeded
|
|
391
225
|
*
|
|
392
226
|
* @example
|
|
393
227
|
* ```ts
|
|
394
|
-
*
|
|
395
|
-
*
|
|
228
|
+
* // First call hits API
|
|
229
|
+
* const advisory = await cacheFetchGhsa('GHSA-1234-5678-90ab')
|
|
230
|
+
*
|
|
231
|
+
* // Second call within 5 minutes returns cached data
|
|
232
|
+
* const cached = await cacheFetchGhsa('GHSA-1234-5678-90ab')
|
|
233
|
+
* ```
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```ts
|
|
237
|
+
* // Disable caching for fresh data
|
|
238
|
+
* process.env.DISABLE_GITHUB_CACHE = '1'
|
|
239
|
+
* const advisory = await cacheFetchGhsa('GHSA-xxxx-yyyy-zzzz')
|
|
396
240
|
* ```
|
|
397
241
|
*/
|
|
398
|
-
export declare function
|
|
242
|
+
export declare function cacheFetchGhsa(ghsaId: string, options?: GitHubFetchOptions | undefined): Promise<GhsaDetails>;
|
|
243
|
+
/**
|
|
244
|
+
* Clear the ref resolution cache (in-memory only).
|
|
245
|
+
* Clears the in-memory memoization cache without affecting the persistent disk cache.
|
|
246
|
+
* Useful for testing or when you need fresh data from the API.
|
|
247
|
+
*
|
|
248
|
+
* Note: This only clears the in-memory cache. The persistent cacache storage
|
|
249
|
+
* remains intact and will be used to rebuild the in-memory cache on next access.
|
|
250
|
+
*
|
|
251
|
+
* @returns Promise that resolves when cache is cleared
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```ts
|
|
255
|
+
* // Clear cache to force fresh API calls
|
|
256
|
+
* await clearRefCache()
|
|
257
|
+
* const sha = await resolveRefToSha('owner', 'repo', 'main')
|
|
258
|
+
* // This will hit the persistent cache or API, not in-memory cache
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
export declare function clearRefCache(): Promise<void>;
|
|
399
262
|
/**
|
|
400
263
|
* Fetch GitHub Security Advisory details from the API.
|
|
401
264
|
* Retrieves complete advisory information including severity, affected packages,
|
|
@@ -433,38 +296,197 @@ export declare function getGhsaUrl(ghsaId: string): string;
|
|
|
433
296
|
*/
|
|
434
297
|
export declare function fetchGhsaDetails(ghsaId: string, options?: GitHubFetchOptions | undefined): Promise<GhsaDetails>;
|
|
435
298
|
/**
|
|
436
|
-
* Fetch
|
|
437
|
-
*
|
|
438
|
-
*
|
|
299
|
+
* Fetch data from GitHub API with automatic authentication and rate limit handling.
|
|
300
|
+
* Makes authenticated requests to the GitHub REST API with proper error handling.
|
|
301
|
+
*
|
|
302
|
+
* Features:
|
|
303
|
+
* - Automatic token injection from environment if not provided
|
|
304
|
+
* - Rate limit detection with helpful error messages
|
|
305
|
+
* - Standard GitHub API headers (Accept, User-Agent)
|
|
306
|
+
* - JSON response parsing
|
|
307
|
+
*
|
|
308
|
+
* @template T - Expected response type (defaults to `unknown`)
|
|
309
|
+
* @param url - Full GitHub API URL (e.g., 'https://api.github.com/repos/owner/repo')
|
|
310
|
+
* @param options - Fetch options including token and custom headers
|
|
311
|
+
* @returns Parsed JSON response of type `T`
|
|
312
|
+
*
|
|
313
|
+
* @throws {GitHubRateLimitError} When API rate limit is exceeded (status 403)
|
|
314
|
+
* @throws {Error} For other API errors with status code and message
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```ts
|
|
318
|
+
* // Fetch repository information
|
|
319
|
+
* interface Repo {
|
|
320
|
+
* name: string
|
|
321
|
+
* full_name: string
|
|
322
|
+
* default_branch: string
|
|
323
|
+
* }
|
|
324
|
+
* const repo = await fetchGitHub<Repo>(
|
|
325
|
+
* 'https://api.github.com/repos/owner/repo'
|
|
326
|
+
* )
|
|
327
|
+
* console.log(`Default branch: ${repo.default_branch}`)
|
|
328
|
+
* ```
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```ts
|
|
332
|
+
* // With custom token and headers
|
|
333
|
+
* const data = await fetchGitHub(
|
|
334
|
+
* 'https://api.github.com/user',
|
|
335
|
+
* {
|
|
336
|
+
* token: 'ghp_customtoken',
|
|
337
|
+
* headers: { 'X-Custom-Header': 'value' }
|
|
338
|
+
* }
|
|
339
|
+
* )
|
|
340
|
+
* ```
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```ts
|
|
344
|
+
* // Handle rate limit errors
|
|
345
|
+
* try {
|
|
346
|
+
* await fetchGitHub('https://api.github.com/repos/owner/repo')
|
|
347
|
+
* } catch (error) {
|
|
348
|
+
* if (error.status === 403 && error.resetTime) {
|
|
349
|
+
* console.error(`Rate limited until ${error.resetTime}`)
|
|
350
|
+
* }
|
|
351
|
+
* }
|
|
352
|
+
* ```
|
|
353
|
+
*/
|
|
354
|
+
export declare function fetchGitHub<T = unknown>(url: string, options?: GitHubFetchOptions | undefined): Promise<T>;
|
|
355
|
+
/**
|
|
356
|
+
* Generate GitHub Security Advisory URL from GHSA ID.
|
|
357
|
+
* Constructs the public advisory URL for a given GHSA identifier.
|
|
358
|
+
*
|
|
359
|
+
* @param ghsaId - GHSA identifier (e.g., 'GHSA-xxxx-yyyy-zzzz')
|
|
360
|
+
* @returns Full URL to the advisory page
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```ts
|
|
364
|
+
* const url = getGhsaUrl('GHSA-1234-5678-90ab')
|
|
365
|
+
* console.log(url) // 'https://github.com/advisories/GHSA-1234-5678-90ab'
|
|
366
|
+
* ```
|
|
367
|
+
*/
|
|
368
|
+
export declare function getGhsaUrl(ghsaId: string): string;
|
|
369
|
+
/**
|
|
370
|
+
* Get GitHub authentication token from environment variables.
|
|
371
|
+
* Checks multiple environment variable names in priority order.
|
|
372
|
+
*
|
|
373
|
+
* Environment variables checked (in order):
|
|
374
|
+
* 1. `GITHUB_TOKEN` - Standard GitHub token variable
|
|
375
|
+
* 2. `GH_TOKEN` - Alternative GitHub CLI token variable
|
|
376
|
+
* 3. `SOCKET_CLI_GITHUB_TOKEN` - Socket-specific token variable
|
|
377
|
+
*
|
|
378
|
+
* @returns The first available GitHub token, or `undefined` if none found
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* ```ts
|
|
382
|
+
* const token = getGitHubToken()
|
|
383
|
+
* if (!token) {
|
|
384
|
+
* console.warn('No GitHub token found')
|
|
385
|
+
* }
|
|
386
|
+
* ```
|
|
387
|
+
*/
|
|
388
|
+
export declare function getGitHubToken(): string | undefined;
|
|
389
|
+
/**
|
|
390
|
+
* Get GitHub authentication token from git config.
|
|
391
|
+
* Reads the `github.token` configuration value from git config.
|
|
392
|
+
* This is a fallback method when environment variables don't contain a token.
|
|
393
|
+
*
|
|
394
|
+
* @param options - Spawn options for git command execution
|
|
395
|
+
* @returns GitHub token from git config, or `undefined` if not configured
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
* ```ts
|
|
399
|
+
* const token = await getGitHubTokenFromGitConfig()
|
|
400
|
+
* if (token) {
|
|
401
|
+
* console.log('Found token in git config')
|
|
402
|
+
* }
|
|
403
|
+
* ```
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* ```ts
|
|
407
|
+
* // With custom working directory
|
|
408
|
+
* const token = await getGitHubTokenFromGitConfig({
|
|
409
|
+
* cwd: '/path/to/repo'
|
|
410
|
+
* })
|
|
411
|
+
* ```
|
|
412
|
+
*/
|
|
413
|
+
export declare function getGitHubTokenFromGitConfig(options?: SpawnOptions | undefined): Promise<string | undefined>;
|
|
414
|
+
/**
|
|
415
|
+
* Get GitHub authentication token from all available sources.
|
|
416
|
+
* Checks environment variables first, then falls back to git config.
|
|
417
|
+
* This is the recommended way to get a GitHub token with maximum compatibility.
|
|
418
|
+
*
|
|
419
|
+
* Priority order:
|
|
420
|
+
* 1. Environment variables (GITHUB_TOKEN, GH_TOKEN, SOCKET_CLI_GITHUB_TOKEN)
|
|
421
|
+
* 2. Git config (github.token)
|
|
422
|
+
*
|
|
423
|
+
* @returns GitHub token from first available source, or `undefined` if none found
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```ts
|
|
427
|
+
* const token = await getGitHubTokenWithFallback()
|
|
428
|
+
* if (!token) {
|
|
429
|
+
* throw new Error('GitHub token required')
|
|
430
|
+
* }
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
export declare function getGitHubTokenWithFallback(): Promise<string | undefined>;
|
|
434
|
+
/**
|
|
435
|
+
* Resolve a git ref (tag, branch, or commit SHA) to its full commit SHA.
|
|
436
|
+
* Handles tags (annotated and lightweight), branches, and commit SHAs.
|
|
437
|
+
* Results are cached in-memory and on disk (with TTL) to minimize API calls.
|
|
438
|
+
*
|
|
439
|
+
* Resolution strategy:
|
|
440
|
+
* 1. Try as a tag (refs/tags/{ref})
|
|
441
|
+
* 2. If tag is annotated, dereference to get the commit SHA
|
|
442
|
+
* 3. If not a tag, try as a branch (refs/heads/{ref})
|
|
443
|
+
* 4. If not a branch, try as a commit SHA directly
|
|
439
444
|
*
|
|
440
445
|
* Caching behavior:
|
|
441
|
-
* -
|
|
442
|
-
* -
|
|
443
|
-
* -
|
|
444
|
-
* -
|
|
445
|
-
* - Respects `DISABLE_GITHUB_CACHE` env var
|
|
446
|
+
* - In-memory cache (Map) for immediate lookups
|
|
447
|
+
* - Persistent disk cache (cacache) for durability across runs
|
|
448
|
+
* - Default TTL: 5 minutes
|
|
449
|
+
* - Disable caching with `DISABLE_GITHUB_CACHE` env var
|
|
446
450
|
*
|
|
447
|
-
* @param
|
|
448
|
-
* @param
|
|
449
|
-
* @
|
|
451
|
+
* @param owner - Repository owner (user or organization name)
|
|
452
|
+
* @param repo - Repository name
|
|
453
|
+
* @param ref - Git reference to resolve (tag name, branch name, or commit SHA)
|
|
454
|
+
* @param options - Resolution options including authentication token
|
|
455
|
+
* @returns The full commit SHA (40-character hex string)
|
|
450
456
|
*
|
|
451
|
-
* @throws {Error}
|
|
457
|
+
* @throws {Error} When ref cannot be resolved after trying all strategies
|
|
452
458
|
* @throws {GitHubRateLimitError} When API rate limit is exceeded
|
|
453
459
|
*
|
|
454
460
|
* @example
|
|
455
461
|
* ```ts
|
|
456
|
-
* //
|
|
457
|
-
* const
|
|
462
|
+
* // Resolve a tag to commit SHA
|
|
463
|
+
* const sha = await resolveRefToSha('owner', 'repo', 'v1.0.0')
|
|
464
|
+
* console.log(sha) // 'a1b2c3d4e5f6...'
|
|
465
|
+
* ```
|
|
458
466
|
*
|
|
459
|
-
*
|
|
460
|
-
*
|
|
467
|
+
* @example
|
|
468
|
+
* ```ts
|
|
469
|
+
* // Resolve a branch to latest commit SHA
|
|
470
|
+
* const sha = await resolveRefToSha('owner', 'repo', 'main')
|
|
471
|
+
* console.log(sha) // Latest commit on main branch
|
|
461
472
|
* ```
|
|
462
473
|
*
|
|
463
474
|
* @example
|
|
464
475
|
* ```ts
|
|
465
|
-
* //
|
|
466
|
-
*
|
|
467
|
-
*
|
|
476
|
+
* // Resolve with custom token
|
|
477
|
+
* const sha = await resolveRefToSha(
|
|
478
|
+
* 'owner',
|
|
479
|
+
* 'repo',
|
|
480
|
+
* 'develop',
|
|
481
|
+
* { token: 'ghp_customtoken' }
|
|
482
|
+
* )
|
|
483
|
+
* ```
|
|
484
|
+
*
|
|
485
|
+
* @example
|
|
486
|
+
* ```ts
|
|
487
|
+
* // Commit SHA passes through unchanged (but validates it exists)
|
|
488
|
+
* const sha = await resolveRefToSha('owner', 'repo', 'a1b2c3d4')
|
|
489
|
+
* console.log(sha) // Full 40-char SHA
|
|
468
490
|
* ```
|
|
469
491
|
*/
|
|
470
|
-
export declare function
|
|
492
|
+
export declare function resolveRefToSha(owner: string, repo: string, ref: string, options?: ResolveRefOptions | undefined): Promise<string>;
|