Skip to content

Commit 01380b1

Browse files
Merge pull request #3 from SocketDev/docs/update-cli-documentation
Update CLI documentation and package name
2 parents 8ffa6ef + 31baf4f commit 01380b1

File tree

2 files changed

+110
-84
lines changed

2 files changed

+110
-84
lines changed

README.md

Lines changed: 109 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,142 @@
11
# Socket Patch CLI
22

3-
CLI tool for applying security patches to dependencies.
3+
Apply security patches to npm dependencies without waiting for upstream fixes.
44

5-
## Setup
5+
## Installation
66

77
```bash
8-
# Install dependencies
9-
npm install
8+
npx @socketsecurity/socket-patch
9+
```
10+
11+
Or install globally:
1012

11-
# Build the project
12-
npm run build
13+
```bash
14+
npm install -g @socketsecurity/socket-patch
1315
```
1416

15-
## Usage
17+
## Commands
18+
19+
### `apply`
20+
21+
Apply security patches from manifest.
1622

23+
**Usage:**
1724
```bash
18-
# Apply patches from manifest (default: .socket/manifest.json)
19-
socket-patch apply
25+
npx @socketsecurity/socket-patch apply [options]
26+
```
2027

21-
# Apply patches with custom manifest path
22-
socket-patch apply --manifest-path /path/to/manifest.json
28+
**Options:**
29+
- `--cwd` - Working directory (default: current directory)
30+
- `-d, --dry-run` - Verify patches without modifying files
31+
- `-s, --silent` - Only output errors
32+
- `-m, --manifest-path` - Path to manifest (default: `.socket/manifest.json`)
2333

24-
# Dry run (verify patches can be applied without modifying files)
25-
socket-patch apply --dry-run
34+
**Examples:**
35+
```bash
36+
# Apply patches
37+
npx @socketsecurity/socket-patch apply
2638

27-
# Silent mode (only output errors)
28-
socket-patch apply --silent
39+
# Dry run
40+
npx @socketsecurity/socket-patch apply --dry-run
2941

30-
# Custom working directory
31-
socket-patch apply --cwd /path/to/project
42+
# Custom manifest
43+
npx @socketsecurity/socket-patch apply -m /path/to/manifest.json
3244
```
3345

34-
## Development
46+
### `download`
3547

48+
Download patch from Socket API.
49+
50+
**Usage:**
3651
```bash
37-
# Watch mode for development
38-
npm run dev
52+
npx @socketsecurity/socket-patch download --uuid <uuid> --org <org> [options]
3953
```
4054

41-
## Project Structure
55+
**Options:**
56+
- `--uuid` - Patch UUID (required)
57+
- `--org` - Organization slug (required)
58+
- `--api-token` - API token (or use `SOCKET_API_TOKEN` env var)
59+
- `--api-url` - API URL (default: `https://api.socket.dev`)
60+
- `--cwd` - Working directory
61+
- `-m, --manifest-path` - Path to manifest
62+
63+
**Examples:**
64+
```bash
65+
# Download patch
66+
export SOCKET_API_TOKEN="your-token"
67+
npx @socketsecurity/socket-patch download --uuid "550e8400-e29b-41d4-a716-446655440000" --org "my-org"
4268

69+
# With explicit token
70+
npx @socketsecurity/socket-patch download --uuid "..." --org "my-org" --api-token "token"
4371
```
44-
src/
45-
├── cli.ts # Main CLI entry point
46-
├── commands/
47-
│ └── apply.ts # Apply patch command
48-
├── schema/
49-
│ └── manifest-schema.ts # Patch manifest schema (Zod)
50-
├── hash/
51-
│ └── git-sha256.ts # Git-compatible SHA256 hashing
52-
├── patch/
53-
│ ├── file-hash.ts # File hashing utilities
54-
│ └── apply.ts # Core patch application logic
55-
├── types.ts # TypeScript type definitions
56-
├── utils.ts # Utility functions
57-
└── index.ts # Library exports
72+
73+
### `list`
74+
75+
List patches in manifest.
76+
77+
**Usage:**
78+
```bash
79+
npx @socketsecurity/socket-patch list [options]
5880
```
5981

60-
## Commands
82+
**Options:**
83+
- `--cwd` - Working directory
84+
- `-m, --manifest-path` - Path to manifest
85+
- `--json` - Output as JSON
86+
87+
**Examples:**
88+
```bash
89+
# List patches
90+
npx @socketsecurity/socket-patch list
6191

62-
### apply
92+
# JSON output
93+
npx @socketsecurity/socket-patch list --json
94+
```
95+
96+
**Sample Output:**
97+
```
98+
Found 2 patch(es):
99+
100+
Package: pkg:npm/[email protected]
101+
UUID: 550e8400-e29b-41d4-a716-446655440000
102+
Tier: free
103+
License: MIT
104+
Vulnerabilities (1):
105+
- GHSA-xxxx-yyyy-zzzz (CVE-2024-12345)
106+
Severity: high
107+
Summary: Prototype pollution in lodash
108+
Files patched (1):
109+
- lodash.js
110+
```
111+
112+
### `remove`
63113

64-
Apply security patches to dependencies from a manifest file.
114+
Remove patch from manifest.
115+
116+
**Usage:**
117+
```bash
118+
npx @socketsecurity/socket-patch remove <identifier> [options]
119+
```
120+
121+
**Arguments:**
122+
- `identifier` - Package PURL (e.g., `pkg:npm/package@version`) or patch UUID
65123

66124
**Options:**
67-
- `--cwd` - Working directory (default: current directory)
68-
- `-d, --dry-run` - Verify patches can be applied without modifying files
69-
- `-s, --silent` - Only output errors
70-
- `-m, --manifest-path` - Path to patch manifest file (default: `.socket/manifest.json`)
71-
- `-h, --help` - Show help
72-
- `-v, --version` - Show version
125+
- `--cwd` - Working directory
126+
- `-m, --manifest-path` - Path to manifest
73127

74-
**Exit Codes:**
75-
- `0` - Success (patches applied or already applied)
76-
- `1` - Error (manifest not found, verification failed, or patch application failed)
128+
**Examples:**
129+
```bash
130+
# Remove by PURL
131+
npx @socketsecurity/socket-patch remove "pkg:npm/[email protected]"
132+
133+
# Remove by UUID
134+
npx @socketsecurity/socket-patch remove "550e8400-e29b-41d4-a716-446655440000"
135+
```
77136

78137
## Manifest Format
79138

80-
The manifest file (`.socket/manifest.json`) contains patch definitions:
139+
Downloaded patches are stored in `.socket/manifest.json`:
81140

82141
```json
83142
{
@@ -98,43 +157,10 @@ The manifest file (`.socket/manifest.json`) contains patch definitions:
98157
"severity": "high",
99158
"description": "Detailed description"
100159
}
101-
},
102-
"description": "Patch description",
103-
"license": "MIT",
104-
"tier": "free"
160+
}
105161
}
106162
}
107163
}
108164
```
109165

110-
Patched file contents are stored in `.socket/blobs/` directory, named by their Git-compatible SHA256 hash.
111-
112-
## Library Usage
113-
114-
The socket-patch CLI can also be used as a library:
115-
116-
```typescript
117-
import {
118-
PatchManifest,
119-
PatchManifestSchema,
120-
computeGitSHA256FromBuffer,
121-
computeGitSHA256FromChunks,
122-
applyPackagePatch,
123-
findNodeModules,
124-
} from '@socketsecurity/socket-patch-cli'
125-
126-
// Validate manifest
127-
const manifest = PatchManifestSchema.parse(manifestData)
128-
129-
// Compute file hashes
130-
const hash = computeGitSHA256FromBuffer(fileBuffer)
131-
132-
// Apply patches programmatically
133-
const result = await applyPackagePatch(
134-
packageKey,
135-
packagePath,
136-
files,
137-
blobsPath,
138-
dryRun,
139-
)
140-
```
166+
Patched file contents are in `.socket/blobs/` (named by git SHA256 hash).

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@socketsecurity/socket-patch-cli",
2+
"name": "@socketsecurity/socket-patch",
33
"version": "0.1.0",
44
"description": "CLI tool for applying security patches to dependencies",
55
"main": "dist/index.js",

0 commit comments

Comments
 (0)