Skip to content

feat: implement read gist APIs with comprehensive error handling #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 7, 2025

Conversation

nullcoder
Copy link
Owner

Summary

Implements Issue #106: Read Gist APIs with two new endpoints for retrieving encrypted gists and their metadata.

New Features

GET /api/gists/[id] - Gist Metadata Endpoint

  • Returns public gist metadata excluding sensitive fields (PIN hash/salt)
  • Implements proper cache headers (5min for regular, no-cache for one-time)
  • Type-safe response using Omit utility type

GET /api/blobs/[id] - Encrypted Blob Endpoint

  • Returns encrypted blob data as binary with security headers
  • Implements proper cache headers (1hr for regular, no-cache for one-time)
  • Sets Content-Disposition for secure file downloads

Key Implementation Details

  • Error Handling: Uses ErrorCode enums instead of string matching for reliability
  • One-Time View: Automatically deletes gists after successful retrieval
  • Expiry Check: Returns 410 Gone for expired gists based on expires_at
  • Security: Excludes edit_pin_hash, edit_pin_salt, encrypted_metadata from responses
  • Edge Runtime: Compatible with Cloudflare Workers global performance
  • Logger Integration: Proper error tracking with context-specific loggers

Testing

  • 23 comprehensive tests with 100% coverage for both endpoints
  • Tests error scenarios: 400, 404, 410, 500 status codes
  • Tests one-time view deletion and cache headers
  • Tests large blob handling and empty blob edge cases

API Error Improvements

  • Added ApiErrors.gone() method for 410 status responses
  • Enhanced error response consistency across endpoints
  • Added GetGistMetadataResponse type for type-safe responses

Test plan

  • All existing tests pass
  • New endpoints return correct data formats
  • Error handling works for all scenarios (404, 410, 500)
  • One-time view deletion works correctly
  • Cache headers are set appropriately
  • Security headers prevent content sniffing and framing
  • TypeScript compilation succeeds
  • ESLint passes with proper error code handling

Closes #106

🤖 Generated with Claude Code

Implements Issue #106: Read Gist APIs with two new endpoints for retrieving
encrypted gists and their metadata.

## New Features

### GET /api/gists/[id] - Gist Metadata Endpoint
- Returns public gist metadata excluding sensitive fields (PIN hash/salt)
- Implements proper cache headers (5min for regular, no-cache for one-time)
- Type-safe response using Omit utility type

### GET /api/blobs/[id] - Encrypted Blob Endpoint
- Returns encrypted blob data as binary with security headers
- Implements proper cache headers (1hr for regular, no-cache for one-time)
- Sets Content-Disposition for secure file downloads

## Key Implementation Details

- **Error Handling**: Uses ErrorCode enums instead of string matching for reliability
- **One-Time View**: Automatically deletes gists after successful retrieval
- **Expiry Check**: Returns 410 Gone for expired gists based on expires_at
- **Security**: Excludes edit_pin_hash, edit_pin_salt, encrypted_metadata from responses
- **Edge Runtime**: Compatible with Cloudflare Workers global performance
- **Logger Integration**: Proper error tracking with context-specific loggers

## Testing

- 23 comprehensive tests with 100% coverage for both endpoints
- Tests error scenarios: 400, 404, 410, 500 status codes
- Tests one-time view deletion and cache headers
- Tests large blob handling and empty blob edge cases

## API Error Improvements

- Added ApiErrors.gone() method for 410 status responses
- Enhanced error response consistency across endpoints
- Added GetGistMetadataResponse type for type-safe responses

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <claude@ghostpaste.dev>
Copy link

cloudflare-workers-and-pages bot commented Jun 7, 2025

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ghostpaste 0e5a58b Visit preview Jun 07 2025, 11:43 PM

Replaces all console.error calls with proper logger usage for consistency
and better error tracking across the API layer.

## Changes

- **api-errors.ts**: Replace console.error with createLogger("api-errors")
- **gists/route.ts**: Replace console.error with createLogger("api:gists:post")
- **api-errors.test.ts**: Update test mocks to use logger instead of console.error

## Benefits

- Consistent logging format with timestamps and context
- Better error tracking and debugging capability
- Follows established logging patterns throughout codebase
- Proper error object handling instead of raw console output

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <claude@ghostpaste.dev>
@nullcoder nullcoder merged commit 9b00b87 into main Jun 7, 2025
1 check was pending
@nullcoder nullcoder deleted the feat/read-gist-apis branch June 7, 2025 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: implement GET endpoints for gists
1 participant