Commit 56e74a7
This PR completes Issue #107 by implementing PUT and DELETE endpoints for the /api/gists/[id] route with comprehensive security features and API test refactoring.
## Key Features
### DELETE Endpoint
- Dual authentication methods:
- One-time view gists: metadata proof validation (SHA-256 hash)
- PIN-protected gists: PIN validation via X-Edit-Password header
- CSRF protection on all state-changing endpoints
- Fixed race condition by moving auto-deletion to explicit DELETE endpoint
### PUT Endpoint
- Multipart form data support for gist updates
- PIN validation for protected gists
- Optimistic locking to prevent concurrent update conflicts
- Support for updating encrypted user metadata and editor preferences
### Security Enhancements
- Created reusable CSRF validation in lib/security.ts
- Converted all crypto operations to WebCrypto API for edge runtime
- Added comprehensive schema validation using Zod
- Proper error handling with typed AppError system
### API Test Refactoring
- Established consistent test pattern: route.{method}.test.ts
- Split all combined test files by HTTP method
- Created API_TEST_PATTERN.md documentation
- All 69 tests passing with 100% coverage
### Additional Improvements
- Implemented user metadata encryption support
- Created shared schemas in lib/api-schemas.ts
- Added editor preferences to create/update operations
- Updated tracking documents and TODO.md
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-authored-by: Claude <[email protected]>
1 parent 9b00b87 commit 56e74a7
File tree
22 files changed
+1886
-270
lines changed- app/api
- blobs/[id]
- gists
- [id]
- docs
- lib
- types
22 files changed
+1886
-270
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
247 | | - | |
| 247 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
34 | 39 | | |
35 | 40 | | |
36 | 41 | | |
37 | | - | |
38 | | - | |
39 | 42 | | |
40 | 43 | | |
41 | 44 | | |
| |||
183 | 186 | | |
184 | 187 | | |
185 | 188 | | |
186 | | - | |
| 189 | + | |
187 | 190 | | |
188 | | - | |
189 | 191 | | |
| 192 | + | |
190 | 193 | | |
191 | 194 | | |
192 | 195 | | |
| |||
Lines changed: 3 additions & 39 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
| |||
106 | 105 | | |
107 | 106 | | |
108 | 107 | | |
109 | | - | |
110 | 108 | | |
111 | 109 | | |
112 | 110 | | |
| |||
116 | 114 | | |
117 | 115 | | |
118 | 116 | | |
119 | | - | |
120 | | - | |
121 | | - | |
| 117 | + | |
122 | 118 | | |
123 | 119 | | |
124 | 120 | | |
| |||
194 | 190 | | |
195 | 191 | | |
196 | 192 | | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
| 193 | + | |
212 | 194 | | |
213 | 195 | | |
214 | 196 | | |
| |||
239 | 221 | | |
240 | 222 | | |
241 | 223 | | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
| 65 | + | |
| 66 | + | |
77 | 67 | | |
78 | 68 | | |
79 | 69 | | |
| |||
0 commit comments